Set the default session timeout to 30 mins

Update AbstractConfigurableEmbeddedServletContainer to set the default
session timeout to 30 minutes. Also correct Javadoc to specify that
the default is '30 minutes'.

Fixes gh-2084
pull/2707/head
Phillip Webb 10 years ago
parent 22e8478aa3
commit c23a764a1c

@ -37,6 +37,9 @@ import org.springframework.util.Assert;
public abstract class AbstractConfigurableEmbeddedServletContainer implements
ConfigurableEmbeddedServletContainer {
private static final int DEFAULT_SESSION_TIMEOUT = (int) TimeUnit.SECONDS
.toMinutes(30);
private String contextPath = "";
private boolean registerDefaultServlet = true;
@ -57,7 +60,7 @@ public abstract class AbstractConfigurableEmbeddedServletContainer implements
private InetAddress address;
private int sessionTimeout;
private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
private Ssl ssl;

@ -49,8 +49,8 @@ public interface ConfigurableEmbeddedServletContainer {
void setPort(int port);
/**
* The session timeout in seconds (default 30). If 0 or negative then sessions never
* expire.
* The session timeout in seconds (default 30 minutes). If 0 or negative then sessions
* never expire.
* @param sessionTimeout the session timeout
*/
void setSessionTimeout(int sessionTimeout);

@ -28,6 +28,7 @@ import java.util.List;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
@ -227,13 +228,13 @@ public class JettyEmbeddedServletContainerFactory extends
.getClassLoader())) {
addJspServlet(context);
}
ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
Configuration[] configurations = getWebAppContextConfigurations(context,
initializersToUse);
context.setConfigurations(configurations);
context.getSessionHandler().getSessionManager()
.setMaxInactiveInterval(getSessionTimeout());
int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
SessionManager sessionManager = context.getSessionHandler().getSessionManager();
sessionManager.setMaxInactiveInterval(sessionTimeout);
postProcessWebAppContext(context);
}

@ -344,12 +344,12 @@ public class TomcatEmbeddedServletContainerFactory extends
for (MimeMappings.Mapping mapping : getMimeMappings()) {
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
}
long timeout = getSessionTimeout();
if (timeout > 0) {
long sessionTimeout = getSessionTimeout();
if (sessionTimeout > 0) {
// Tomcat timeouts are in minutes
timeout = Math.max(TimeUnit.SECONDS.toMinutes(timeout), 1L);
sessionTimeout = Math.max(TimeUnit.SECONDS.toMinutes(sessionTimeout), 1L);
}
context.setSessionTimeout((int) timeout);
context.setSessionTimeout((int) sessionTimeout);
for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
customizer.customize(context);
}

Loading…
Cancel
Save