mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Call ServletContextListener.contextDestroyed() when Undertow is stopped
Previously, when the embedded Undertow container was stopped, the servlet deployment was stopped but it was not undeployed. This meant that contextDestroyed() callback of any registered ServletContextListeners was not called. This commit updates UndertowEmbeddedServletContainer to call undeploy on the deployment manager in addition to the existing call to stop. Undeploying the servlet deployment calls Undertow to drive the contextDestroyed callback on any registered ServletContextListeners. Closes gh-13134
This commit is contained in:
parent
f07daf898b
commit
339fd74810
@ -333,6 +333,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine
|
||||
this.started = false;
|
||||
try {
|
||||
this.manager.stop();
|
||||
this.manager.undeploy();
|
||||
this.undertow.stop();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -55,6 +55,8 @@ import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.servlet.GenericServlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
@ -110,6 +112,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -1035,6 +1038,26 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
assertThat(documentRoot).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletContextListenerContextDestroyedIsCalledWhenContainerIsStopped()
|
||||
throws Exception {
|
||||
final ServletContextListener listener = mock(ServletContextListener.class);
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletContextInitializer() {
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext)
|
||||
throws ServletException {
|
||||
servletContext.addListener(listener);
|
||||
}
|
||||
|
||||
});
|
||||
this.container.start();
|
||||
this.container.stop();
|
||||
verify(listener).contextDestroyed(any(ServletContextEvent.class));
|
||||
}
|
||||
|
||||
protected abstract void addConnector(int port,
|
||||
AbstractEmbeddedServletContainerFactory factory);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user