Defer disable persistence logic to a listener

Update TomcatEmbeddedServletContainerFactory so that logic to disable
persistent sessions happens after Tomcat's standard Manager creation
logic.

Fixes gh-4543
pull/4955/merge
Phillip Webb 9 years ago
parent e520c47c4f
commit fd3e5cf304

@ -405,16 +405,16 @@ public class TomcatEmbeddedServletContainerFactory
private void configureSession(Context context) {
long sessionTimeout = getSessionTimeoutInMinutes();
context.setSessionTimeout((int) sessionTimeout);
Manager manager = context.getManager();
if (manager == null) {
manager = new StandardManager();
context.setManager(manager);
}
if (isPersistSession()) {
Manager manager = context.getManager();
if (manager == null) {
manager = new StandardManager();
context.setManager(manager);
}
configurePersistSession(manager);
}
else {
disablePersistSession(manager);
context.addLifecycleListener(new DisablePersistSessionListener());
}
}
@ -427,12 +427,6 @@ public class TomcatEmbeddedServletContainerFactory
((StandardManager) manager).setPathname(file.getAbsolutePath());
}
private void disablePersistSession(Manager manager) {
if (manager instanceof StandardManager) {
((StandardManager) manager).setPathname(null);
}
}
private long getSessionTimeoutInMinutes() {
long sessionTimeout = getSessionTimeout();
if (sessionTimeout > 0) {
@ -771,4 +765,24 @@ public class TomcatEmbeddedServletContainerFactory
}
/**
* {@link LifecycleListener} to disable persistence in the {@link StandardManager}. A
* {@link LifecycleListener} is used so not to interfere with Tomcat's default manager
* creation logic.
*/
private static class DisablePersistSessionListener implements LifecycleListener {
@Override
public void lifecycleEvent(LifecycleEvent event) {
if (event.getType().equals(Lifecycle.START_EVENT)) {
Context context = (Context) event.getLifecycle();
Manager manager = context.getManager();
if (manager != null && manager instanceof StandardManager) {
((StandardManager) manager).setPathname(null);
}
}
}
}
}

Loading…
Cancel
Save