Add sessionTimeout to embedded servlet containers

* ConfigurableEmbeddedServletContainerFactory now has a sessionTimeout
property
* The ServerProperties in Actuator supports it

[Fixes #53667353] [bs-243] Support setSessionTimeout
pull/9/head
Dave Syer 11 years ago
parent 1b780beddd
commit ea3d2e74dd

@ -55,6 +55,7 @@ public class EndpointWebMvcChildContextConfiguration implements
factory.setPort(this.managementServerProperties.getPort());
factory.setAddress(this.managementServerProperties.getAddress());
factory.setContextPath(this.managementServerProperties.getContextPath());
// TODO: Disable sessions
}
@Bean

@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for the
* {@link ManagementServerPropertiesAutoConfiguration} bean.
* {@link ManagementServerProperties} bean.
*
* @author Dave Syer
*/

@ -67,6 +67,8 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
private InetAddress address;
private int sessionTimeout;
/**
* Create a new {@link AbstractEmbeddedServletContainerFactory} instance.
*/
@ -155,6 +157,30 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
return this.address;
}
/**
* The session timeout in minutes.
*
* @param sessionTimeout the session timeout to set (default 30)
*/
public void setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
/**
* @return the session timeout in minutes
*/
public int getSessionTimeout() {
return this.sessionTimeout;
}
/**
* Sets {@link ServletContextInitializer} that should be applied in addition to
* {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. This
* method will replace any previously set or added initializers.
* @param initializers the initializers to set
* @see #addInitializers
* @see #getInitializers
*/
@Override
public void setInitializers(List<? extends ServletContextInitializer> initializers) {
Assert.notNull(initializers, "Initializers must not be null");

@ -46,6 +46,25 @@ public interface ConfigurableEmbeddedServletContainerFactory extends
*/
void setPort(int port);
/**
* The port that the embedded server listens on.
* @return the port
*/
int getPort();
/**
* The session timeout in seconds (default 30). If 0 or negative then sessions never
* expire.
*
* @param sessionTimeout the session timeout
*/
void setSessionTimeout(int sessionTimeout);
/**
* @return the session timeout value
*/
int getSessionTimeout();
/**
* Sets the specific network address that the server should bind to.
* @param address the address to set (defaults to {@code null})

@ -121,6 +121,8 @@ public class JettyEmbeddedServletContainerFactory extends
Configuration[] configurations = getWebAppContextConfigurations(context,
initializersToUse);
context.setConfigurations(configurations);
context.getSessionHandler().getSessionManager()
.setMaxInactiveInterval(getSessionTimeout());
postProcessWebAppContext(context);
server.setHandler(context);

@ -45,6 +45,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
private InetAddress address;
private int sessionTimeout = 30;
@NotNull
private String contextPath = "";
@ -78,11 +80,20 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
this.address = address;
}
public int getSessionTimeout() {
return this.sessionTimeout;
}
public void setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
@Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
factory.setPort(getPort());
factory.setAddress(getAddress());
factory.setContextPath(getContextPath());
factory.setSessionTimeout(getSessionTimeout());
if (factory instanceof TomcatEmbeddedServletContainerFactory) {
getTomcat().customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
}

@ -220,6 +220,7 @@ public class TomcatEmbeddedServletContainerFactory extends
for (MimeMappings.Mapping mapping : getMimeMappings()) {
context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
}
context.setSessionTimeout(getSessionTimeout());
}
/**

Loading…
Cancel
Save