Looks like you understand the issue (2nd is the best). I do the second,
its a neat trick.. my user object extends TurbineUser, I over-ride the
valueUnbound and valueBound methods in order to log login and logout (
or session time out ) events. Also, if the objects that you put in the
tempStorage are not serializable, you need to clean them up in the
valueUnbound method if you want your user object to be able to serialize
itself if the container shuts down or something - like if you are using
session replication in weblogic for example. 

 /**
     * This object is an HttpSessionBindingListener, therefore this
method
     * gets called when it is bound to the session
     *
     * @param hsbe The HttpSessionBindingEvent.
     */
    public void valueBound(javax.servlet.http.HttpSessionBindingEvent
hsbe)
    {
        try
        {
            if (hasLoggedIn())
            {
                log.info(ESTABLISHED +
                         LOG_TOKENIZER + 
                         hsbe.getSession().getId() + 
                         LOG_TOKENIZER + 
                         getUserName());
            }
            else
            {
                log.debug(ESTABLISHED + 
                         LOG_TOKENIZER +
                         hsbe.getSession().getId() + 
                         LOG_TOKENIZER + 
                         "anonymous");
            
            }
        }
        catch (Exception e)
        {
            log.error("BizUser.valueBound() :: session=" +
                      hsbe.getSession().getId(), e);
        }
        finally
        {
            super.valueBound(hsbe);
        }
    }

    /**
     * This object is an HttpSessionBindingListener, therefore this
method
     * gets called when it is unbound from the session ( this occurs on
logout
     * or session timeout or servlet shutdown )
     *
     * @param hsbe The HttpSessionBindingEvent.
     */
    public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent
hsbe)
    {
        try
        {
            if (getUserName() != null)
            {
                log.info(TERMINATED + 
                         LOG_TOKENIZER +
                         hsbe.getSession().getId() + 
                         LOG_TOKENIZER + 
                         getUserName());
            }
            else
            {
                log.debug(TERMINATED + 
                         LOG_TOKENIZER +
                         hsbe.getSession().getId() + 
                         LOG_TOKENIZER + 
                         "anonymous");
            
            }
        }
        catch (Exception e)
        {
            log.error("BizUser.valueUnbound() :: session=" + 
                      hsbe.getSession().getId(), e);
        }
        finally
        {
            super.valueUnbound(hsbe);
        }
    }

-----Original Message-----
From: Paul Szego [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, February 19, 2002 11:48 PM
To: Turbine Users List
Subject: Session scope tools



Hi,

I'm just getting going with Turbine/Velocity, and have some questions 
about "session" tools and their lifecycle.

My understanding is that the tool will be initialised with a User object

and placed in the tempStorage of that User. However I can't see how to 
tell when the session is "over".

My solutions so far are to either (1) implement 
HttpSessionBindingListener and bind myself to the servlet session and 
work from HttpSessionBindingEvent's myself, or (2) extend TurbineUser 
and override the valueUnbound() and do some tricks there.

In the second approach I look through each object in the tempStorage, 
and if it implements HttpSessionBindingListener I call the 
valueUnbound() method on it. Then I call super.valueUnbound() to let the

TurbineUser object do its thing.

Is there any other way to do this? Am I missing something completely?

Regards, PaulS.


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to