Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Sep 7, 2020
2 parents 3dfe11e + 116b247 commit 9bf6e1c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.util.ClassUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.NestedServletException;
Expand All @@ -62,8 +61,7 @@
* @author Andy Wilkinson
* @since 2.0.0
*/
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public class ErrorPageFilter implements Filter, ErrorPageRegistry {
public class ErrorPageFilter implements Filter, ErrorPageRegistry, Ordered {

private static final Log logger = LogFactory.getLog(ErrorPageFilter.class);

Expand Down Expand Up @@ -298,6 +296,11 @@ else if (errorPage.getStatus() != null) {
public void destroy() {
}

@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 1;
}

private static void addClassIfPresent(Collection<Class<?>> collection, String className) {
try {
collection.add(ClassUtils.forName(className, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ErrorPageFilter errorPageFilter() {
@Bean
FilterRegistrationBean<ErrorPageFilter> errorPageFilterRegistration(ErrorPageFilter filter) {
FilterRegistrationBean<ErrorPageFilter> registration = new FilterRegistrationBean<>(filter);
registration.setOrder(filter.getOrder());
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
return registration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.WebApplicationContext;
Expand Down Expand Up @@ -133,6 +134,27 @@ void errorPageFilterRegistrationCanBeDisabled() {
}
}

@Test
@SuppressWarnings("rawtypes")
void errorPageFilterIsRegisteredWithNearHighestPrecedence() {
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.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE + 1);
}
});
try {
webServer.start();
}
finally {
webServer.stop();
}
}

@Test
@SuppressWarnings("rawtypes")
void errorPageFilterIsRegisteredForRequestAndAsyncDispatch() {
Expand Down

0 comments on commit 9bf6e1c

Please sign in to comment.