Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Cleanup in JAXRS  RSS feed

 
Tim Clotworthy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to be able to perform some session-cleanup activities after a user ends a browser session against my JAXRS web service. It is unclear what mechanism I have at my disposal for, 1, recognizing the session-disconnect and, 2, how I can respond to it.

I would be grateful for any insights. Thanks!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server will never know if the client has gone away if there is no explicit "logout" happening. But that's a web app concept anyway, and should not be used for web services, just like sessions are really not RESTful. Can you tell us a bit more about what this session does, and why it's needed?

I'd have assumed that in order to start a session, you'd have to have gotten hold of the HttpServletRequest object (through which you could invalidate the session as well) - not so?
 
Tim Clotworthy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. Probably better stated as follows:

I have web service where web users subscribe to particular events. These subscriptions should not have a life beyond the duration of the session. Although I help create the subscriptions (on behalf of a web client), they are actually created and maintained elsewhere downstream from me by another web service. If I have not heard from a client for some specified period of time, it is incumbent upon me to destroy all the subscriptions (on behalf of that client) and then destroy the session. Yes, I have access to the servlet request to access the sessionId for the purposes of destroying the subscriptions and session.

Thanks again for any reply!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can configure an javax.servlet.http.HttpSessionListener for the web app. It will be called each time a session is about to expire (so you need to configure the session expiration time to suit your requirements), and provides you with a reference to the HttpSession object. That should do the trick if the session object contains all data you need to delete the subscriptions.
 
Tim Clotworthy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works great. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!