You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Giovanni Cuccu <gi...@cup2000.it> on 2012/01/30 09:58:01 UTC

Possibile bug in MockHttpServletRequest

Hello,
     I'm starting to user WicketTester and I've hit the following behaviour.
I have a IRequestCycleListener wich needs to access to the httpSession. 
In my code I was using
     HttpSession httpSession=httpRequest.getSession();
which works fine within the real servlet  container (i.e. tomcat) but 
fails when I use WicketTester
In order to make wicketteset work I had to change the previous line to:
     HttpSession httpSession=httpRequest.getSession(true);
But if I look at the servler api specs 
(http://docs.oracle.com/javaee/1.4/api/) the 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

If my assumption is correct the MockHttpServletRequest implementation is 
incorrect since it returns null in my case.
The code in the mock class is the following one
     public HttpSession getSession()
     {
         if (session instanceof MockHttpSession && 
((MockHttpSession)session).isTemporary())
         {
             return null;
         }
         return session;
     }
Is it a bug or am I missing something?
ciao,
     Giovanni


-- 
Giovanni Cuccu
CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Possibile bug in MockHttpServletRequest

Posted by Martin Grigorov <mg...@apache.org>.
Servlet sessions are like Wicket statefulness:
Initially there is no session. Once you call getSession(true) you create
one.
Wicket pages are stateless by default. Once you add a stateful
component/behavior in the page tree you make it stateful.

This should answer your question - WicketTester should start with no http
session (for some reason this is represented as temporary http session) and
create one (i.e. make it non-temporary) once the application uses its first
stateful page.


On Fri, Dec 14, 2012 at 5:37 PM, Leonardo D'Alimonte <
leonardo.dalimonte@loginet.it> wrote:

> Hi Martin,
> thanks for the explanation.
> Is ti possible the BaseWicketTester instantiate a MockHttpSession without
> setting anymore the temporary flag to "false"?
> I checked the source for Wicket 1.4.20 and I found this
> difference....setting this flag to false inside my WicketTester turned back
> my test to green..
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Possibile-bug-in-MockHttpServletRequest-tp4340419p4654823.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Possibile bug in MockHttpServletRequest

Posted by Leonardo D'Alimonte <le...@loginet.it>.
Hi Martin,
thanks for the explanation.
Is ti possible the BaseWicketTester instantiate a MockHttpSession without
setting anymore the temporary flag to "false"?
I checked the source for Wicket 1.4.20 and I found this
difference....setting this flag to false inside my WicketTester turned back
my test to green..



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Possibile-bug-in-MockHttpServletRequest-tp4340419p4654823.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Possibile bug in MockHttpServletRequest

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

If mockHttpSession is temporary then it is not bound and calling
getSession(false) will not return it.
You have to call getSession()/getSession(true) to bind it and from there on
getSession(false) will return it.


On Fri, Dec 14, 2012 at 12:51 PM, Leonardo D'Alimonte <
leonardo.dalimonte@loginet.it> wrote:

> Hi guys,
> I have a problem with the implementation of
> 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;
>
> With parameter false, i never get the session even if it actually exists.
> Field "session" is an instance of MockHttpSession, the first "if" is never
> executed with boolean "false" and so also the second one..thus session
> remain null.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Possibile-bug-in-MockHttpServletRequest-tp4340419p4654811.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Possibile bug in MockHttpServletRequest

Posted by Leonardo D'Alimonte <le...@loginet.it>.
Hi guys,
I have a problem with the implementation of
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;

With parameter false, i never get the session even if it actually exists.
Field "session" is an instance of MockHttpSession, the first "if" is never
executed with boolean "false" and so also the second one..thus session
remain null.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Possibile-bug-in-MockHttpServletRequest-tp4340419p4654811.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Possibile bug in MockHttpServletRequest

Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi Martin,
     done.
https://issues.apache.org/jira/browse/WICKET-4370
ciao,
     Giovanni

> In
> >  my code I was using
> >      HttpSession httpSession=httpRequest.getSession();
> >  which works fine within the real servlet  container (i.e. tomcat) but fails
> >  when I use WicketTester
> >  In order to make wicketteset work I had to change the previous line to:
> >      HttpSession httpSession=httpRequest.getSession(true);
> >  But if I look at the servler api specs
> >  (http://docs.oracle.com/javaee/1.4/api/) the 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
> >
> >  If my assumption is correct the MockHttpServletRequest implementation is
> >  incorrect since it returns null in my case.
> >  The code in the mock class is the following one
> >      public HttpSession getSession()
> >      {
> >          if (session instanceof MockHttpSession&&
> >  ((MockHttpSession)session).isTemporary())
> >          {
> >              return null;
> >          }
> >          return session;
> >      }


-- 
Giovanni Cuccu
CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Possibile bug in MockHttpServletRequest

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

It looks like a bug.
Please create a ticket.
Thanks!

On Mon, Jan 30, 2012 at 10:58 AM, Giovanni Cuccu
<gi...@cup2000.it> wrote:
> Hello,
>    I'm starting to user WicketTester and I've hit the following behaviour.
> I have a IRequestCycleListener wich needs to access to the httpSession. In
> my code I was using
>    HttpSession httpSession=httpRequest.getSession();
> which works fine within the real servlet  container (i.e. tomcat) but fails
> when I use WicketTester
> In order to make wicketteset work I had to change the previous line to:
>    HttpSession httpSession=httpRequest.getSession(true);
> But if I look at the servler api specs
> (http://docs.oracle.com/javaee/1.4/api/) the 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
>
> If my assumption is correct the MockHttpServletRequest implementation is
> incorrect since it returns null in my case.
> The code in the mock class is the following one
>    public HttpSession getSession()
>    {
>        if (session instanceof MockHttpSession &&
> ((MockHttpSession)session).isTemporary())
>        {
>            return null;
>        }
>        return session;
>    }
> Is it a bug or am I missing something?
> ciao,
>    Giovanni
>
>
> --
> Giovanni Cuccu
> CUP 2000 Spa
> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
> e-mail: giovanni.cuccu _at_ cup2000.it
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org