You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Bigwood, David" <db...@metatomix.com> on 2002/02/20 16:11:25 UTC

SessionListener sessionDestroyed() - session already invalidated - Tomcat 4.0.2

I am having issues getting useful functionality with code that
implements Servlet 2.3 HttpSessionListener. The code was intended to
provide some enhancements to a logging suite to carry out some tasks
BEFORE a session is actually destroyed.

My intention is to gather some interesting data about a visit for
tracking purposes, e.g.: page count, page history, session duration,
session create time, entry page, exit page, etc. (some of this data is
inserted during the session).

However, the existing sessionDestroyed method:

public void sessionDestroyed(HttpSessionEvent hse) 

while allowing access to the current session ID via:

hse.getSession().getId();

does not appear to allow access to any data that is/was stored in the
session and results in a message along the lines of:

"session already invalidated"

Having checked the code in
org/apache/catalina/session/StandardSession.java, specifically the
method:

public void expire(boolean notify)

the reason would appear to be because the session is marked as invalid:

setValid(false);

BEFORE the call to the session destroyed event of each session listener:

if (notify) {
	fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
}


My question is this:

Is there a specific reason why the session is invalidated BEFORE expire
calls the session listeners, or could we move the setValid(false) call
down?

If there is no reason I will propose a patch to make it so.

Would be interested in your thoughts.
-David 


----
David Bigwood
VP Engineering, Metatomix
mailto: dbigwood@metatomix.com
T: 781 895 4803
F: 781 487 7711
C: 781 983 1699

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SessionListener sessionDestroyed() - session already invalidated - Tomcat 4.0.2

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 20 Feb 2002, Bigwood, David wrote:

>
> My question is this:
>
> Is there a specific reason why the session is invalidated BEFORE expire
> calls the session listeners, or could we move the setValid(false) call
> down?
>

This ordering is based on what the JavaDocs say for the
HttpSessionListener.sessionDestroyed() method says:

    "Notification that a session was invalidated".

In other words, this is an *after-the-fact* notification, not a
before-the-fact notification.

You can track statistical information by registering an
HttpSessionAttributeListener and noticing when particular session
attributes are removed (which happens as part of the invalidation or
timeout process).

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>