Commit 2fe08194 authored by Andy Wilkinson's avatar Andy Wilkinson

Isolate multiple Undertow deployments

Previously, UndertowEmbeddedServletContainerFactory always used
Undertow’s default ServletContainer. This meant that if there were two
UndertowEmbeddedServletContainers created, they would share the same
ServletContainer and the second one that was created would overwrite
the deployment for the first. This resulted in a async request
handling failing as the attempt to look up the deployment for the
first embedded Undertow instance would incorrectly find the deployment
for the second.

This commit fixes the problem by ensuring that each 
UndertowEmbeddedServletContainerFactory uses a separate Undertow
ServletContainer instance.

Closes gh-4329
parent 604ca524
...@@ -336,7 +336,7 @@ public class UndertowEmbeddedServletContainerFactory ...@@ -336,7 +336,7 @@ public class UndertowEmbeddedServletContainerFactory
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) { for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
customizer.customize(deployment); customizer.customize(deployment);
} }
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment); DeploymentManager manager = Servlets.newContainer().addDeployment(deployment);
manager.deploy(); manager.deploy();
SessionManager sessionManager = manager.getDeployment().getSessionManager(); SessionManager sessionManager = manager.getDeployment().getSessionManager();
int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1); int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
......
...@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference; ...@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference;
import io.undertow.Undertow.Builder; import io.undertow.Undertow.Builder;
import io.undertow.servlet.api.DeploymentInfo; import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager; import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ServletContainer;
import org.junit.Test; import org.junit.Test;
import org.mockito.InOrder; import org.mockito.InOrder;
...@@ -39,6 +40,8 @@ import org.springframework.http.HttpStatus; ...@@ -39,6 +40,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyObject;
...@@ -156,6 +159,19 @@ public class UndertowEmbeddedServletContainerFactoryTests ...@@ -156,6 +159,19 @@ public class UndertowEmbeddedServletContainerFactoryTests
assertEquals("/", contextPath.get()); assertEquals("/", contextPath.get());
} }
@Test
public void eachFactoryUsesADiscreteServletContainer() {
assertThat(getServletContainerFromNewFactory(),
is(not(equalTo(getServletContainerFromNewFactory()))));
}
private ServletContainer getServletContainerFromNewFactory() {
UndertowEmbeddedServletContainer undertow1 = (UndertowEmbeddedServletContainer) getFactory()
.getEmbeddedServletContainer();
return ((DeploymentManager) ReflectionTestUtils.getField(undertow1, "manager"))
.getDeployment().getServletContainer();
}
@Override @Override
protected Map<String, String> getActualMimeMappings() { protected Map<String, String> getActualMimeMappings() {
return ((DeploymentManager) ReflectionTestUtils.getField(this.container, return ((DeploymentManager) ReflectionTestUtils.getField(this.container,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment