Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple HttpSession objects

 
Brusk Baran
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'd like to learn whether I can create more than one sesiion object for a single user's single request..and how if yes, the relations between these objects will be arranged..
regards,
c.g.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Due to the way the servlet engine tracks sessions, there can be only one per request. That session can hold an essentially unlimited number of objects (not particularly practical.) If you need to hold lots of data per user consider using a database or writing your own session manager equivalent.
Bill
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can. I cannot think of any reason why you would want to, but here's my half-baked idea of how to do it:
1) Create a subdomain with an alias, say "sub."
2) Use a wrapper class "MultipleDomainSession" so that multiple sessions can be added to this wrapper and that calling setAttribute on any session will cause
3) implement a request filter. In the filter, call MultipleDomainSession.getSession(hreq.getSession(true)).
- If null, set the cookie. Give it a value of the session id. Call setDomain(".yourhost.com") on the cookie and add it to the response.
- otherwise, if the value is not that of the sessionid, add a separator and the session id.
You will then have a cookie that looks like: "MDSCookie=2354eddafcc08342345a88aecb-25a83ecd8aaf08344e235ccd4b"
If you are using lots of subdomains, you'll have a very long cookie value. (You can translate the base of number to use Character.MAX_RADIX (base 36) instead of the session's hex (base 16).
You can look up your wrapper with any sessionid in the MDSCookie.
Calling getAttribute/setAttribute on your MultipleDomainSession instance will cause it to use its own Hashtable.
You can implement HttpSessionBindingEvent for each session added to a MultipleDomainSession wrapper.

Discussion:
When a request is made for "http://www.yourhost.com/path," a new session will be created.
Adding the new session to a wrapper provides an object with access to all data in the object.
[ December 02, 2002: Message edited by: Garrett Smith ]
[ December 02, 2002: Message edited by: Garrett Smith ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ewww! That is really twisted!
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could probably do a much neater job if you were to first study the source code for HttpSession.
Sun has considered session tracking a lot more than I have, and did so with knowledge, teamwork, and experience than I don't have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic