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
pull/4844/head
Andy Wilkinson 9 years ago
parent 604ca52491
commit 2fe0819495

@ -336,7 +336,7 @@ public class UndertowEmbeddedServletContainerFactory
for (UndertowDeploymentInfoCustomizer customizer : this.deploymentInfoCustomizers) {
customizer.customize(deployment);
}
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
DeploymentManager manager = Servlets.newContainer().addDeployment(deployment);
manager.deploy();
SessionManager sessionManager = manager.getDeployment().getSessionManager();
int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);

@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference;
import io.undertow.Undertow.Builder;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ServletContainer;
import org.junit.Test;
import org.mockito.InOrder;
@ -39,6 +40,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.test.util.ReflectionTestUtils;
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.assertThat;
import static org.mockito.Matchers.anyObject;
@ -156,6 +159,19 @@ public class UndertowEmbeddedServletContainerFactoryTests
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
protected Map<String, String> getActualMimeMappings() {
return ((DeploymentManager) ReflectionTestUtils.getField(this.container,

Loading…
Cancel
Save