Reputation:
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?
Upvotes: 3
Views: 7516
Reputation: 91
Session.java has a callback method that is executed when the user session is invalidated or due to HttpSession expiration.
public void onInvalidate(){
}
Upvotes: 2
Reputation: 3883
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>
Upvotes: 7