Register ErrorPageFilter for async dispatch
Fixes gh-19471
This commit is contained in:
parent
22dc4e7608
commit
49f8943a5f
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.web.servlet.support;
|
package org.springframework.boot.web.servlet.support;
|
||||||
|
|
||||||
|
import javax.servlet.DispatcherType;
|
||||||
|
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@ -32,4 +35,11 @@ class ErrorPageFilterConfiguration {
|
||||||
return new ErrorPageFilter();
|
return new ErrorPageFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration(ErrorPageFilter filter) {
|
||||||
|
FilterRegistrationBean<ErrorPageFilter> registration = new FilterRegistrationBean<>(filter);
|
||||||
|
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,10 @@
|
||||||
package org.springframework.boot.web.servlet.support;
|
package org.springframework.boot.web.servlet.support;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
@ -31,6 +34,7 @@ import org.springframework.boot.testsupport.system.CapturedOutput;
|
||||||
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
||||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||||
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.boot.web.server.WebServer;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
@ -116,6 +120,28 @@ class SpringBootServletInitializerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() {
|
||||||
|
WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> {
|
||||||
|
try (AbstractApplicationContext context = (AbstractApplicationContext) new WithErrorPageFilter()
|
||||||
|
.createRootApplicationContext(servletContext)) {
|
||||||
|
Map<String, FilterRegistrationBean> registrations = context
|
||||||
|
.getBeansOfType(FilterRegistrationBean.class);
|
||||||
|
assertThat(registrations).hasSize(1);
|
||||||
|
FilterRegistrationBean errorPageFilterRegistration = registrations.get("errorPageFilterRegistration");
|
||||||
|
assertThat(errorPageFilterRegistration).hasFieldOrPropertyWithValue("dispatcherTypes",
|
||||||
|
EnumSet.of(DispatcherType.ASYNC, DispatcherType.REQUEST));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
webServer.start();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
webServer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void executableWarThatUsesServletInitializerDoesNotHaveErrorPageFilterConfigured() {
|
void executableWarThatUsesServletInitializerDoesNotHaveErrorPageFilterConfigured() {
|
||||||
try (ConfigurableApplicationContext context = new SpringApplication(ExecutableWar.class).run()) {
|
try (ConfigurableApplicationContext context = new SpringApplication(ExecutableWar.class).run()) {
|
||||||
|
@ -199,6 +225,11 @@ class SpringBootServletInitializerTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
static class WithErrorPageFilter extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class ExecutableWar extends SpringBootServletInitializer {
|
static class ExecutableWar extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue