Skip to content

Commit 6ee0f8d

Browse files
committed
Merge branch '2.2.x' into 2.3.x
Closes gh-22672
2 parents 45346b6 + 49f8943 commit 6ee0f8d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/ErrorPageFilterConfiguration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.boot.web.servlet.support;
1818

19+
import javax.servlet.DispatcherType;
20+
21+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
1922
import org.springframework.context.annotation.Bean;
2023
import org.springframework.context.annotation.Configuration;
2124

@@ -32,4 +35,11 @@ ErrorPageFilter errorPageFilter() {
3235
return new ErrorPageFilter();
3336
}
3437

38+
@Bean
39+
FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration(ErrorPageFilter filter) {
40+
FilterRegistrationBean<ErrorPageFilter> registration = new FilterRegistrationBean<>(filter);
41+
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
42+
return registration;
43+
}
44+
3545
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
package org.springframework.boot.web.servlet.support;
1818

1919
import java.util.Collections;
20+
import java.util.EnumSet;
21+
import java.util.Map;
2022
import java.util.Vector;
2123
import java.util.concurrent.atomic.AtomicBoolean;
2224

25+
import javax.servlet.DispatcherType;
2326
import javax.servlet.ServletContext;
2427
import javax.servlet.ServletContextEvent;
2528
import javax.servlet.ServletContextListener;
@@ -37,6 +40,7 @@
3740
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
3841
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
3942
import org.springframework.boot.web.server.WebServer;
43+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
4044
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
4145
import org.springframework.context.ApplicationListener;
4246
import org.springframework.context.ConfigurableApplicationContext;
@@ -129,6 +133,28 @@ void errorPageFilterRegistrationCanBeDisabled() {
129133
}
130134
}
131135

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+
132158
@Test
133159
void executableWarThatUsesServletInitializerDoesNotHaveErrorPageFilterConfigured() {
134160
try (ConfigurableApplicationContext context = new SpringApplication(ExecutableWar.class).run()) {
@@ -237,6 +263,11 @@ static class WithErrorPageFilterNotRegistered extends SpringBootServletInitializ
237263

238264
}
239265

266+
@Configuration(proxyBeanMethods = false)
267+
static class WithErrorPageFilter extends SpringBootServletInitializer {
268+
269+
}
270+
240271
@Configuration(proxyBeanMethods = false)
241272
static class ExecutableWar extends SpringBootServletInitializer {
242273

0 commit comments

Comments
 (0)