Ensure DeploymentInfo contextPath is never "/"

Undertow 1.1 expects that DeploymentInfo.contextPath is set to "/" for
a root context. If it is left as "" the session cookie path is not
correctly set. See UNDERTOW-350 for background.

This commit simplifies the original work-around committed in 78c22813d.

Fixes gh-2065
pull/2090/head
Phillip Webb 10 years ago
parent 90e9187b80
commit c8b9da0492

@ -31,7 +31,6 @@ import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager; import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ListenerInfo; import io.undertow.servlet.api.ListenerInfo;
import io.undertow.servlet.api.MimeMapping; import io.undertow.servlet.api.MimeMapping;
import io.undertow.servlet.api.ServletSessionConfig;
import io.undertow.servlet.api.ServletStackTraces; import io.undertow.servlet.api.ServletStackTraces;
import io.undertow.servlet.handlers.DefaultServlet; import io.undertow.servlet.handlers.DefaultServlet;
import io.undertow.servlet.util.ImmediateInstanceFactory; import io.undertow.servlet.util.ImmediateInstanceFactory;
@ -322,7 +321,8 @@ public class UndertowEmbeddedServletContainerFactory extends
deployment.addListener(new ListenerInfo(StartupListener.class, deployment.addListener(new ListenerInfo(StartupListener.class,
new ImmediateInstanceFactory<StartupListener>(startupListener))); new ImmediateInstanceFactory<StartupListener>(startupListener)));
deployment.setClassLoader(getServletClassLoader()); deployment.setClassLoader(getServletClassLoader());
deployment.setContextPath(getContextPath()); String contextPath = getContextPath();
deployment.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
deployment.setDeploymentName("spring-boot"); deployment.setDeploymentName("spring-boot");
if (isRegisterDefaultServlet()) { if (isRegisterDefaultServlet()) {
deployment.addServlet(Servlets.servlet("default", DefaultServlet.class)); deployment.addServlet(Servlets.servlet("default", DefaultServlet.class));
@ -331,12 +331,6 @@ public class UndertowEmbeddedServletContainerFactory extends
deployment.setServletStackTraces(ServletStackTraces.NONE); deployment.setServletStackTraces(ServletStackTraces.NONE);
deployment.setResourceManager(getDocumentRootResourceManager()); deployment.setResourceManager(getDocumentRootResourceManager());
configureMimeMappings(deployment); configureMimeMappings(deployment);
if (StringUtils.isEmpty(getContextPath())) {
// Work around UNDERTOW-350
ServletSessionConfig servletSessionConfig = new ServletSessionConfig();
servletSessionConfig.setPath("/");
deployment.setServletSessionConfig(servletSessionConfig);
}
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) { for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
customizer.customize(deployment); customizer.customize(deployment);
} }

Loading…
Cancel
Save