Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpSessionListener working but not quite...

843841Aug 16 2007 — edited Feb 26 2008
Hi,

To make a long story short, I am currently working on a huge web application that logs every move a user makes in it.

I have a class that i named User that has all the user's infos the application needs like userId companyId and so on.

When a user logs off, a log cleaner is invoked and receives the user so it can go close this user's logs by getting his Id.

The problem was when a user was just closing IE or just letting it sit and his session expired. So i made a HttpSessionListener class that looks like this :

public class SgeSessionListener implements HttpSessionListener{


public void sessionCreated(HttpSessionEvent se) {
System.out.println("Session CREATED");
}

public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("Session CLOSED");
User user = se.getSession().getAttribute("user")
SGELogsCleaner.cleanLogs(user);
}


}

SGELogsCleaner is the llog cleaning class obviously and
cleanLogs(User) is a static method.
In this method i get the userId from the user object i get from the listener and go clean the logs in the database with it.

Once in like 2-3 days of me and 2 coworkers playing with the application we get a wierd error. The cleaner throws a nullPointerException when trying to get the userId from the user object.
So the session gave the cleaner a null User object.

This is where we are puzzled. Cause a user is created and put into the session as soon as the session is created.

So my guess would be that the session is destroyed before the code in the listener is started so the session no longer exists and a user can't be gotten from it.

My question would be why is it not working 100% ? And if my logic is flawed regarding the SessionListener please enlighten me. It's actually the first time I ever worked with such a concept. I can't find a solution to this problem. It's kind of a big problem cause the database will be filled in no time with unclosed logs.

Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2008
Added on Aug 16 2007
3 comments
770 views