Done! This is now in Cactus CVS. Here is the unit test I have added:
public void beginCreateSessionCookie(WebRequest theRequest)
{
HttpSessionCookie sessionCookie = theRequest.getSessionCookie();
theRequest.addCookie(sessionCookie);
}
public void testCreateSessionCookie()
{
assertFalse("A session should have been created prior to "
+ "this request", session.isNew());
}
-Vincent
> -----Original Message-----
> From: Vincent Massol [mailto:[EMAIL PROTECTED]]
> Sent: 26 September 2002 12:05
> To: 'Cactus Users List'
> Subject: Getting session id on the client side (ws RE: How do I unit
test
> a Servlet method which checks if HttpSession.isNew() == true?)
>
> Ah! A good point... I think you have found the first unit test (maybe
> the only one) that may require a round-trip to the server from Cactus
> client.
>
> Thank you for discovering this! The solution I can see is to provide a
> method in WebRequest that allows to retrieve a session id.
>
> Here is how you would use it:
>
> public void beginXXX(WebRequest request)
> {
> String sessionId = request.getSessionId();
> theRequest.addCookie("JSESSIONID", sessionId);
> [...]
> }
>
> public void testXXX()
> {
> assertFalse(session.isNew());
> }
>
> Would that be ok?
>
> The only issue that I need to check has to do with the case of the
> jsessionid cookie. Is the case define in the spec or does it depend on
> the container?
>
> If it does, we could have the following:
>
> public void beginXXX(WebRequest request)
> {
> Session session = request.getSession();
> theRequest.addCookie(session.getCookieName(),
> session.getSessionId());
> [...]
> }
>
> or maybe even better (?):
>
> public void beginXXX(WebRequest request)
> {
> Session session = request.getSession();
> theRequest.addCookie(session.createCookie());
> [...]
> }
>
> We will also need the ability to add the session id to the URL for
> URL-rewriting. But that's easy.
>
> What do you think?
>
> Thanks
> -Vincent
>
> > -----Original Message-----
> > From: Wagle, Shriniwas [mailto:[EMAIL PROTECTED]]
> > Sent: 18 September 2002 22:16
> > To: '[EMAIL PROTECTED]'
> > Subject: How do I unit test a Servlet method which checks if
> > HttpSession.isNew() == true?
> >
> >
> > I want to test a public method of a Servlet.
> > This method along the way checks if the session is new using
> > HttpSession.isNew () which is returning true.
> > The method expects the session to be NOT new.
> >
> > Is there any way I can unit test this method?
> >
> > Thanks
> > Shriniwas Wagle
> >
> >
> > --
> > To unsubscribe, e-mail: <mailto:cactus-user-
> > [EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:cactus-user-
> > [EMAIL PROTECTED]>
>
>
>
> --
> To unsubscribe, e-mail: <mailto:cactus-user-
> [EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:cactus-user-
> [EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>