|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
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 |
|
| 23 | +import javax.servlet.DispatcherType; |
21 | 24 | import javax.servlet.ServletContext;
|
22 | 25 |
|
23 | 26 | import org.junit.jupiter.api.AfterEach;
|
|
31 | 34 | import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
32 | 35 | import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
33 | 36 | import org.springframework.boot.web.server.WebServer;
|
| 37 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; |
34 | 38 | import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
35 | 39 | import org.springframework.context.ApplicationListener;
|
36 | 40 | import org.springframework.context.ConfigurableApplicationContext;
|
@@ -116,6 +120,28 @@ void errorPageFilterRegistrationCanBeDisabled() {
|
116 | 120 | }
|
117 | 121 | }
|
118 | 122 |
|
| 123 | + @Test |
| 124 | + @SuppressWarnings("rawtypes") |
| 125 | + void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() { |
| 126 | + WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> { |
| 127 | + try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter() |
| 128 | + .createRootApplicationContext(servletContext)) { |
| 129 | + Map<String, FilterRegistrationBean> registrations = context |
| 130 | + .getBeansOfType(FilterRegistrationBean.class); |
| 131 | + assertThat(registrations).hasSize(1); |
| 132 | + FilterRegistrationBean errorPageFilterRegistration = registrations.get("errorPageFilterRegistration"); |
| 133 | + assertThat(errorPageFilterRegistration).hasFieldOrPropertyWithValue("dispatcherTypes", |
| 134 | + EnumSet.of(DispatcherType.ASYNC, DispatcherType.REQUEST)); |
| 135 | + } |
| 136 | + }); |
| 137 | + try { |
| 138 | + webServer.start(); |
| 139 | + } |
| 140 | + finally { |
| 141 | + webServer.stop(); |
| 142 | + } |
| 143 | + } |
| 144 | + |
119 | 145 | @Test
|
120 | 146 | void executableWarThatUsesServletInitializerDoesNotHaveErrorPageFilterConfigured() {
|
121 | 147 | try (ConfigurableApplicationContext context = new SpringApplication(ExecutableWar.class).run()) {
|
@@ -199,6 +225,11 @@ static class WithErrorPageFilterNotRegistered extends SpringBootServletInitializ
|
199 | 225 |
|
200 | 226 | }
|
201 | 227 |
|
| 228 | + @Configuration(proxyBeanMethods = false) |
| 229 | + static class WithErrorPageFilter extends SpringBootServletInitializer { |
| 230 | + |
| 231 | + } |
| 232 | + |
202 | 233 | @Configuration(proxyBeanMethods = false)
|
203 | 234 | static class ExecutableWar extends SpringBootServletInitializer {
|
204 | 235 |
|
|
0 commit comments