Wicket
  1. Wicket
  2. WICKET-4370

HttpSession getSession() in MockHttpServletRequest is not compliant with the j2ee servlet spec

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.4
    • Fix Version/s: 1.5.5, 6.0.0-beta1
    • Component/s: wicket
    • Labels:
      None

      Description

      The implementation of
      httpRequest.getSession();
      for MockHttpServletRequest seems not correct since it can return null when
      the servler api specs
      (http://docs.oracle.com/javaee/1.4/api/) says:

      public HttpSession getSession()
      Returns the current session associated with this request, or if the request
      does not have a session, creates one.

      So as far as I understand
      httpRequest.getSession(); and httpRequest.getSession(true); are equivalent

      The MockHttpServletRequest implementation is

      public HttpSession getSession()
      {
      if (session instanceof MockHttpSession &&
      ((MockHttpSession)session).isTemporary())

      { return null; }

      return session;
      }

      I think it should be
      public HttpSession getSession()

      { return getSession(true); }

        Activity

        Hide
        Leonardo D'Alimonte added a comment -

        Hi everybody,
        I'm migrating to Wicket 1.5.9 and I found this code inside MockHttpServletRequest.getSession(boolean):
        HttpSession sess = null;
        if (session instanceof MockHttpSession)
        {
        MockHttpSession mockHttpSession = (MockHttpSession) session;
        if (b)

        { mockHttpSession.setTemporary(false); }

        if (mockHttpSession.isTemporary() == false)

        { sess = session; }

        }
        return sess;

        At the moment, passing "false" will never allow you to get the session, even if it actually exists.
        Is it possible I'm doing something wrong in my code?

        Thanks in advance!

        Show
        Leonardo D'Alimonte added a comment - Hi everybody, I'm migrating to Wicket 1.5.9 and I found this code inside MockHttpServletRequest.getSession(boolean): HttpSession sess = null; if (session instanceof MockHttpSession) { MockHttpSession mockHttpSession = (MockHttpSession) session; if (b) { mockHttpSession.setTemporary(false); } if (mockHttpSession.isTemporary() == false) { sess = session; } } return sess; At the moment, passing "false" will never allow you to get the session, even if it actually exists. Is it possible I'm doing something wrong in my code? Thanks in advance!

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Giovanni Cuccu
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development