Solved

Invalidated session does not call HttpSessionListener sessionDestroyed method

Posted on 2004-03-31
9
2,237 Views
Last Modified: 2012-06-27
Hi All,

I've got the following problem:
In my web application a user has to login with username + password. After a successful login I insert a record in a database.
When the user logs out of the application the user Session is invalidated. In my implementation of HttpSessionListener I update the created database record by filling in a logout timestamp.

This mechanism works perfect in Tomcat 4.0.3 running on Win NT.

When I deploy my code to a Linux machine running Tomcat 4.0.3 and 4.0.6 the following happens:
The first time after a tomcat restart that  a user logs in and out the record is created and updated.
The second time however a record is created at login time, but not updated at logout time! Only after 30 minutes (when the session expires) the record is updated with the logout timestamp of that moment.????

Can someone tell me what is happening and may be how I can solve this?

Since the code on both machine is exactly the same I assume it must have something to do with TOmcat configuration or proxies or something.
0
Comment
Question by:paskal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 10724253
Hi paskal
can you post the code?
Javier
0
 
LVL 3

Author Comment

by:paskal
ID: 10729815
Yes, I can post the code, but to get the whole thing working I need to post too much code.
And as I said before: it is working in one environment so I assume the code is correct.
But anyway, here is the code of my listener:

public class SessionLogger implements HttpSessionListener
{

   /** Logging object used to log the messages */
  protected static Log logger = LogFactory.getLog(SessionLogger.class);
 
      /**
       * When a new HttpSession is created this method is performed.
       */
      public void sessionCreated(HttpSessionEvent se)
      {
        logger.info("Created: id = "+ se.getSession().getId() );
      }

      /**
       * When a HttpSession is destroyed this method is performed. It will fill the enddate
       * of the session-row in the sessions table if not filled yet.
       */

      public void sessionDestroyed(HttpSessionEvent se)
      {
        endSession( se.getSession().getId());
        logger.info("Destroyed: " + se.getSession().getId());
      }
     
      private void endSession(String id)
      {
         try
         {
           E4AllSession session = new E4AllSession();
                     
           session.setId(id);
       
           DAOSessions dao = new DAOSessions();
           logger.info(" listener: Going to end the session: " + session.getId() );
           dao.endSession(session);
         } catch (Exception e)
         {
             e.printStackTrace();
         }
      }
}

Remark:
The debuig message "listener: Going to end the session..." is also not put out after the second session is (should) killed.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10729870
I would try this to see if the dbupdate was locked for some reason:
      public void sessionDestroyed(HttpSessionEvent se)
      {
        logger.info("Destroyed: " + se.getSession().getId());
        endSession( se.getSession().getId());
        logger.info("delete from db: " + se.getSession().getId());
      }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:paskal
ID: 10730899

Okay, guys I finally found it.
Of course the error occurred not where I expected it. The problem was this:
When a user clicked the logout-link or when an unload was done of the html-page I did:
opener.document.location='logout.m'; //or something like that

The first time this action is really performed, but the second time I think it is taken from a cache (of the proxy-server??) and the code is not executed.
On my local environment in Win nT I don't use proxies so no problems with the cache there.

I solved it by doing a post of 'logout.m' request and works now in all environments.

I apologies for the time taken from you looking in to this question. May be better luck next time.

0
 
LVL 6

Expert Comment

by:jarasa
ID: 10730912
:c) Glad you get it.

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 11215998
go ahead.
Javier
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11244497
PAQed, with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Learn why we support net neutrality and why the topic is important to all internet users.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question