Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket session Expiration

Tags:

java

wicket

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?


2 Answers

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>
like image 180
Michal Bernhard Avatar answered Dec 12 '25 05:12

Michal Bernhard


Session.java has a callback method that is executed when the user session is invalidated or due to HttpSession expiration.

public void onInvalidate(){
}
like image 26
Eugene Avatar answered Dec 12 '25 05:12

Eugene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!