Skip to content

Commit 4c8626e

Browse files
committed
Allow Boot's Jetty error handler to be overridden
Fixes gh-19520
1 parent a162c8a commit 4c8626e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java

Lines changed: 2 additions & 2 deletions
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.
@@ -327,9 +327,9 @@ protected Configuration[] getWebAppContextConfigurations(WebAppContext webAppCon
327327
ServletContextInitializer... initializers) {
328328
List<Configuration> configurations = new ArrayList<>();
329329
configurations.add(getServletContextInitializerConfiguration(webAppContext, initializers));
330-
configurations.addAll(getConfigurations());
331330
configurations.add(getErrorPageConfiguration());
332331
configurations.add(getMimeTypeConfiguration());
332+
configurations.addAll(getConfigurations());
333333
return configurations.toArray(new Configuration[0]);
334334
}
335335

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java

Lines changed: 23 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.
@@ -35,8 +35,10 @@
3535
import org.eclipse.jetty.server.handler.ErrorHandler;
3636
import org.eclipse.jetty.server.handler.HandlerCollection;
3737
import org.eclipse.jetty.server.handler.HandlerWrapper;
38+
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
3839
import org.eclipse.jetty.util.thread.QueuedThreadPool;
3940
import org.eclipse.jetty.util.thread.ThreadPool;
41+
import org.eclipse.jetty.webapp.AbstractConfiguration;
4042
import org.eclipse.jetty.webapp.Configuration;
4143
import org.eclipse.jetty.webapp.WebAppContext;
4244
import org.junit.jupiter.api.Test;
@@ -301,4 +303,24 @@ public void contextDestroyed(ServletContextEvent event) {
301303
});
302304
}
303305

306+
@Test
307+
void errorHandlerCanBeOverridden() {
308+
JettyServletWebServerFactory factory = getFactory();
309+
factory.addConfigurations(new AbstractConfiguration() {
310+
311+
@Override
312+
public void configure(WebAppContext context) throws Exception {
313+
context.setErrorHandler(new CustomErrorHandler());
314+
}
315+
316+
});
317+
JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer();
318+
WebAppContext context = (WebAppContext) jettyWebServer.getServer().getHandler();
319+
assertThat(context.getErrorHandler()).isInstanceOf(CustomErrorHandler.class);
320+
}
321+
322+
private static class CustomErrorHandler extends ErrorPageErrorHandler {
323+
324+
}
325+
304326
}

0 commit comments

Comments
 (0)