diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java similarity index 79% rename from spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java index 291b39a1a7..a16f36f250 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java @@ -30,33 +30,30 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedServletContainer; +import org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerException; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.ErrorPage; -import org.springframework.boot.context.embedded.ServletContextInitializer; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** - * A special {@link EmbeddedServletContainerFactory} for non-embedded applications (i.e. - * deployed WAR files). It registers error pages and handles application errors by - * filtering requests and forwarding to the error pages instead of letting the container - * handle them. Error pages are a feature of the servlet spec but there is no Java API for - * registering them in the spec. This filter works around that by accepting error page - * registrations from Spring Boot's {@link EmbeddedServletContainerCustomizer} (any beans - * of that type in the context will be applied to this container). + * A special {@link AbstractConfigurableEmbeddedServletContainer} for non-embedded + * applications (i.e. deployed WAR files). It registers error pages and handles + * application errors by filtering requests and forwarding to the error pages instead of + * letting the container handle them. Error pages are a feature of the servlet spec but + * there is no Java API for registering them in the spec. This filter works around that by + * accepting error page registrations from Spring Boot's + * {@link EmbeddedServletContainerCustomizer} (any beans of that type in the context will + * be applied to this container). * * @author Dave Syer * @author Phillip Webb */ @Component @Order(Ordered.HIGHEST_PRECEDENCE) -public class ErrorWrapperEmbeddedServletContainerFactory extends - AbstractEmbeddedServletContainerFactory implements Filter { +class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer implements + Filter { // From RequestDispatcher but not referenced to remain compatible with Servlet 2.5 @@ -161,28 +158,6 @@ public class ErrorWrapperEmbeddedServletContainerFactory extends throw new IllegalStateException(ex); } - @Override - public EmbeddedServletContainer getEmbeddedServletContainer( - ServletContextInitializer... initializers) { - - return new EmbeddedServletContainer() { - - @Override - public void start() throws EmbeddedServletContainerException { - } - - @Override - public void stop() throws EmbeddedServletContainerException { - } - - @Override - public int getPort() { - return -1; - } - }; - - } - @Override public void addErrorPages(ErrorPage... errorPages) { for (ErrorPage errorPage : errorPages) { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java b/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java index fef93f465c..abbe9b2219 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java @@ -85,7 +85,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); application = configure(application); // Ensure error pages are registered - application.sources(ErrorWrapperEmbeddedServletContainerFactory.class); + application.sources(ErrorPageFilter.class); return (WebApplicationContext) application.run(); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java index 6f74b87e34..4119a117fd 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java @@ -36,13 +36,13 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /** - * Tests for {@link ErrorWrapperEmbeddedServletContainerFactory}. + * Tests for {@link ErrorPageFilter}. * * @author Dave Syer */ public class ErrorWrapperEmbeddedServletContainerFactoryTests { - private ErrorWrapperEmbeddedServletContainerFactory filter = new ErrorWrapperEmbeddedServletContainerFactory(); + private ErrorPageFilter filter = new ErrorPageFilter(); private MockHttpServletRequest request = new MockHttpServletRequest();