|
17 | 17 | package org.springframework.boot.web.servlet.support; |
18 | 18 |
|
19 | 19 | import java.util.Collections; |
| 20 | +import java.util.EnumSet; |
| 21 | +import java.util.Map; |
20 | 22 | import java.util.Vector; |
21 | 23 | import java.util.concurrent.atomic.AtomicBoolean; |
22 | 24 |
|
| 25 | +import javax.servlet.DispatcherType; |
23 | 26 | import javax.servlet.ServletContext; |
24 | 27 | import javax.servlet.ServletContextEvent; |
25 | 28 | import javax.servlet.ServletContextListener; |
|
37 | 40 | import org.springframework.boot.testsupport.system.OutputCaptureExtension; |
38 | 41 | import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; |
39 | 42 | import org.springframework.boot.web.server.WebServer; |
| 43 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; |
40 | 44 | import org.springframework.boot.web.servlet.server.ServletWebServerFactory; |
41 | 45 | import org.springframework.context.ApplicationListener; |
42 | 46 | import org.springframework.context.ConfigurableApplicationContext; |
@@ -129,6 +133,28 @@ void errorPageFilterRegistrationCanBeDisabled() { |
129 | 133 | } |
130 | 134 | } |
131 | 135 |
|
| 136 | + @Test |
| 137 | + @SuppressWarnings("rawtypes") |
| 138 | + void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() { |
| 139 | + WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> { |
| 140 | + try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter() |
| 141 | + .createRootApplicationContext(servletContext)) { |
| 142 | + Map<String, FilterRegistrationBean> registrations = context |
| 143 | + .getBeansOfType(FilterRegistrationBean.class); |
| 144 | + assertThat(registrations).hasSize(1); |
| 145 | + FilterRegistrationBean errorPageFilterRegistration = registrations.get("errorPageFilterRegistration"); |
| 146 | + assertThat(errorPageFilterRegistration).hasFieldOrPropertyWithValue("dispatcherTypes", |
| 147 | + EnumSet.of(DispatcherType.ASYNC, DispatcherType.REQUEST)); |
| 148 | + } |
| 149 | + }); |
| 150 | + try { |
| 151 | + webServer.start(); |
| 152 | + } |
| 153 | + finally { |
| 154 | + webServer.stop(); |
| 155 | + } |
| 156 | + } |
| 157 | + |
132 | 158 | @Test |
133 | 159 | void executableWarThatUsesServletInitializerDoesNotHaveErrorPageFilterConfigured() { |
134 | 160 | try (ConfigurableApplicationContext context = new SpringApplication(ExecutableWar.class).run()) { |
@@ -237,6 +263,11 @@ static class WithErrorPageFilterNotRegistered extends SpringBootServletInitializ |
237 | 263 |
|
238 | 264 | } |
239 | 265 |
|
| 266 | + @Configuration(proxyBeanMethods = false) |
| 267 | + static class WithErrorPageFilter extends SpringBootServletInitializer { |
| 268 | + |
| 269 | + } |
| 270 | + |
240 | 271 | @Configuration(proxyBeanMethods = false) |
241 | 272 | static class ExecutableWar extends SpringBootServletInitializer { |
242 | 273 |
|
|
0 commit comments