You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Vincent Massol <vm...@octo.com> on 2002/09/26 13:04:34 UTC

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:swagle@verisign.com]
> Sent: 18 September 2002 22:16
> To: 'cactus-user@jakarta.apache.org'
> 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-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Getting session id on the client side (ws RE: How do I unit test a Servlet method which checks if HttpSession.isNew() == true?)

Posted by Vincent Massol <vm...@octo.com>.
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:vmassol@octo.com]
> 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:swagle@verisign.com]
> > Sent: 18 September 2002 22:16
> > To: 'cactus-user@jakarta.apache.org'
> > 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-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:cactus-user-
> > help@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>