Search code examples
sessiontomcat8session-management

Force tomcat not to invalidate session on shutdown


My project uses custom session invalidation mechanism. It requires to send notification with invalidation cause, for example - if invalidation happends by user request - invalidation cause is USER_REQUEST, if shutdown of the server - then the cause is SHUTDOWN. All working well besides shutdown case - tomcat itself invalidates all the session(at least StandardManager does).

As far as I know - I can create my own Manager, which does'nt invalidate sessions at all:

public class HttpSessionManager extends StandardManager {

    @Override
    protected synchronized void stopInternal() throws LifecycleException {
        setState(LifecycleState.STOPPING);
        if (sessionIdGenerator instanceof Lifecycle) {
            ((Lifecycle) sessionIdGenerator).stop();
        }
    }
}

This class should be placed in some jar file and placed in tomcat/lib folder. In fact, that solution requires to distribute additional library for tomcat together with the main solution, which is not good(delivery process getting complicated)

There should be another way to do that or my solution could be improved somehow.


Solution

  • After a long and deep googling this issue - I can say there is no other way to do such thing.