Skip to content

Commit 6c8e81f

Browse files
author
Phillip Webb
committed
Rework ErrorWrapperEmbeddedServletContainerFactory
Rename ErrorWrapperEmbeddedServletContainerFactory to ErrorPageFilter and extend AbstractConfigurableEmbeddedServletContainer rather than AbstractEmbeddedServletContainerFactory. Fixes spring-projectsgh-416
1 parent 99350a2 commit 6c8e81f

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,30 @@
3030
import javax.servlet.http.HttpServletResponse;
3131
import javax.servlet.http.HttpServletResponseWrapper;
3232

33-
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory;
34-
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
33+
import org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer;
3534
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
36-
import org.springframework.boot.context.embedded.EmbeddedServletContainerException;
37-
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
3835
import org.springframework.boot.context.embedded.ErrorPage;
39-
import org.springframework.boot.context.embedded.ServletContextInitializer;
4036
import org.springframework.core.Ordered;
4137
import org.springframework.core.annotation.Order;
4238
import org.springframework.stereotype.Component;
4339

4440
/**
45-
* A special {@link EmbeddedServletContainerFactory} for non-embedded applications (i.e.
46-
* deployed WAR files). It registers error pages and handles application errors by
47-
* filtering requests and forwarding to the error pages instead of letting the container
48-
* handle them. Error pages are a feature of the servlet spec but there is no Java API for
49-
* registering them in the spec. This filter works around that by accepting error page
50-
* registrations from Spring Boot's {@link EmbeddedServletContainerCustomizer} (any beans
51-
* of that type in the context will be applied to this container).
41+
* A special {@link AbstractConfigurableEmbeddedServletContainer} for non-embedded
42+
* applications (i.e. deployed WAR files). It registers error pages and handles
43+
* application errors by filtering requests and forwarding to the error pages instead of
44+
* letting the container handle them. Error pages are a feature of the servlet spec but
45+
* there is no Java API for registering them in the spec. This filter works around that by
46+
* accepting error page registrations from Spring Boot's
47+
* {@link EmbeddedServletContainerCustomizer} (any beans of that type in the context will
48+
* be applied to this container).
5249
*
5350
* @author Dave Syer
5451
* @author Phillip Webb
5552
*/
5653
@Component
5754
@Order(Ordered.HIGHEST_PRECEDENCE)
58-
public class ErrorWrapperEmbeddedServletContainerFactory extends
59-
AbstractEmbeddedServletContainerFactory implements Filter {
55+
class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer implements
56+
Filter {
6057

6158
// From RequestDispatcher but not referenced to remain compatible with Servlet 2.5
6259

@@ -161,28 +158,6 @@ private void rethrow(Throwable ex) throws IOException, ServletException {
161158
throw new IllegalStateException(ex);
162159
}
163160

164-
@Override
165-
public EmbeddedServletContainer getEmbeddedServletContainer(
166-
ServletContextInitializer... initializers) {
167-
168-
return new EmbeddedServletContainer() {
169-
170-
@Override
171-
public void start() throws EmbeddedServletContainerException {
172-
}
173-
174-
@Override
175-
public void stop() throws EmbeddedServletContainerException {
176-
}
177-
178-
@Override
179-
public int getPort() {
180-
return -1;
181-
}
182-
};
183-
184-
}
185-
186161
@Override
187162
public void addErrorPages(ErrorPage... errorPages) {
188163
for (ErrorPage errorPage : errorPages) {

spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected WebApplicationContext createRootApplicationContext(
8585
application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class);
8686
application = configure(application);
8787
// Ensure error pages are registered
88-
application.sources(ErrorWrapperEmbeddedServletContainerFactory.class);
88+
application.sources(ErrorPageFilter.class);
8989
return (WebApplicationContext) application.run();
9090
}
9191

spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
import static org.junit.Assert.assertThat;
3737

3838
/**
39-
* Tests for {@link ErrorWrapperEmbeddedServletContainerFactory}.
39+
* Tests for {@link ErrorPageFilter}.
4040
*
4141
* @author Dave Syer
4242
*/
4343
public class ErrorWrapperEmbeddedServletContainerFactoryTests {
4444

45-
private ErrorWrapperEmbeddedServletContainerFactory filter = new ErrorWrapperEmbeddedServletContainerFactory();
45+
private ErrorPageFilter filter = new ErrorPageFilter();
4646

4747
private MockHttpServletRequest request = new MockHttpServletRequest();
4848

0 commit comments

Comments
 (0)