Solved

Invalidated session does not call HttpSessionListener sessionDestroyed method

Posted on 2004-03-31
9
2,201 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
Comment Utility
Hi paskal
can you post the code?
Javier
0
 
LVL 3

Author Comment

by:paskal
Comment Utility
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
Comment Utility
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
 
LVL 3

Author Comment

by:paskal
Comment Utility

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:jarasa
Comment Utility
:c) Glad you get it.

Javier
0
 

Expert Comment

by:fks2
Comment Utility
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
go ahead.
Javier
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
Comment Utility
PAQed, with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now