Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use jsessionid while making HTTP calls??

 
Shridhar. Blr.
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

How can i use an existing jsessionid, when i make a http call..
When a first call is made to the application, we get a jsessionid, i want to use the same jsessionid, when we make next calls and how do i use it on the server side to identify it on the server side, with this jsessionid, i want to access all those objects which have been created for that jsessionid..

These calls are not context specific, we are making absolute HTTP calls..

Any help would be highly appreciated..
Thanx in Advace.

Shridhar..
 
Deepak Kaimal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sridhar,
The jsessionid is a unique identifier that is used by the web container as a pointer to your session. As such, the session id is usually persisted on the client and retrieved by the server either through a cookie or through URL rewriting.
The first time you create a session on the server, a session id is returned to the client. You must pass this to the server for subsequent calls. How you pass this depends on how the server expects to receive it.
If it was part of a cookie, you will need to send it back as part of the "Cookie" header. If it was through URL rewriting, you will need to set it as part of the query string.
For the second part of your question there is no way to explicitly retrieve a handle to a session knowing the session id. This was previously possible via the getSession() method on the HttpSessionContext class. As of Servlet API 2.1, this class is deprecated for security reasons.
In my opinion you have two options
1. Try and retrieve the session ID on your client side and send it back to the server. On the server side use sessions normally (request.getSession()). If you use a standard client library like Apache common's HTTPClient, this should happen very cleanly.
2. Use your own session identifier and manage the sessions yourself on the server independant of the container's session management. I think this is a very dirty way to do things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic