Solved

Invalidated session does not call HttpSessionListener sessionDestroyed method

Posted on 2004-03-31
9
2,224 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 

Expert Comment

by:fks2
ID: 10746711
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Java Servlet inside Eclipse Luna 6 165
Getting NoSuchMethodError on accessing a spring mvc project 3 169
ejb on wildfly 5 30
mysql jsp example issue 32 53
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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