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

Question about HttpSessionActivationListener implementation

 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to track when a users session is about to timeout. After searching through the topics in "The Ranch" and doing a little reading on my own it appears that my best bet is to implement HttpSessionActivationListener. I can then perform my cleanup in the sessionWillPassivate() method. My understanding is that this will serve a double purpose by being called not only when the session is about to timeout but also on a call to session.invalidate(). I know that when you use an HttpSessionListener you have to register it with the web.xml. Is this true of the ActivationListener as well? If not, how do the servlets recognize where to send the event?
 
vasu venki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well good Question christoper

U know HttpSession migrate from one jvm to another,so the spec designers design an listener to find whether the attributes in the HttpSession were also about to move.So there came a HttpSessionActivationListener.

If all ur attributes r straight forward serializable then u don't need to care about this listener.

So ur question is about ur using HttpSessionActivation listener,and how do we register it.right.My opinion is for any listener we need to register the class in web.xml.I hope this might me true.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things "vasugivenkatesh vasugivenkatesh",

Firstly, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

And secondly...

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

To track session invalidation and time-out, use HttpSessionListener, in which sessionDestroyed() is called when the session is about to be destroyed.

HttpSessionActivationListener's are notified of session migration across JVM's, not time-outs and invalidations.

HttpSessionActivationListener is implemented by attributes that are bound to a Session and not configured in web.xml
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I'm implementing HttpSessionListener. I've declared my class in web.xml and set the session to timeout in 5 minutes for testing purposes. When the session times out I get the following exception thrown to the console. The web page seems unaffected.



The process that I followed was to log in to the application so that my session is loaded with the appropriate objects and then sit on that web page until session timeout is reached. Also, it doesn't appear that the code to finalize session objects I placed in sessionDestroyed() is reached. It enters the method and then...

Any help? Thanks guys (and gals).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what container and version you are using?
Also, if you know what version of the Servlet Spec your container supports, that would be helpful.

I know there was a change in the J2EE API (between 1.3 and 1.4) in the way (when) the sessionDestroyed method is called.
In a nutshell sessionDestroyed used to be called after the session was destroyed and now get's called before.

This thread has links to the two APIs and discusses their differences.

[added: you might actually want the link]
http://www.coderanch.com/t/360982/Servlets/java/Session-timeouts-listeners
[ October 06, 2005: Message edited by: Ben Souther ]
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the version 1.4.2 Java APIs running against a SunOne Web Server (6.1) and a BEA WebLogic Application Server (8.1).

Basically the problem is that some of our users can run reports in the background. What I need to do is check to make sure that the reports stop if the session times out. They run in a seperate thread that's referenced from an object stored in the session. That's the finalization code I spoke of previously which isn't being reached. Any help would be tremendously appreciated. In the meantime I'll look at those links. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic