tags:

views:

439

answers:

1

Hi,

i am using a class for session which extends org.apache.wicket.protocol.http.WebSession; i need a method to be called when this session expires as a consequence of logging out or time out. but i have found nothing. How can i do it?

Thanks in andvance.

A: 

You can do it on Wicket level like this:

by overriding SessionStore implementation - override Application#newSessionStore()

 @Override
 protected ISessionStore newSessionStore() {
        return new SecondLevelCacheSessionStore(this, new DiskPageStore()) {

            @Override
            protected void onUnbind(String sessionId) {
                // this code is called when wicket call httpSession.invalidate()
            }

        };
    }

but this has drawback: when session expires (which is constroled by servlet container) this code won't be called. In other words - you can handle only session destroy event which is caused by wicket itself.

On global level you can use Servlet API's HttpSessionListener - you can react on session destroy event whatever it was triggered by

HttpSesionListener#sessionDestroyed(HttpSessionEvent se)

and write this to your WEB-INF/web.xml

<listener>
  <listener-class>
     your.listener.class.full.qualified.name
  </listener-class>
</listener>
Michal Bernhard