-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
We use Spring Boot with Jetty and Jersey for microservices. We want to expose as little server information as possible so the Jetty server is customized with silent error handler to return no content on errors.
/**
* Custom Jetty container with no server tag and content empty error response
*/
@Bean
public ServletWebServerFactory servletContainer() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.setDocumentRoot(new File(System.getProperty("java.io.tmpdir")));
factory.addServerCustomizers(server -> {
Handler handler = server.getHandler();
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(handler);
server.setHandler(stats);
if (handler instanceof GzipHandler) {
handler = ((GzipHandler) handler).getHandler();
}
WebAppContext context = (WebAppContext) handler;
context.setErrorHandler(new SilentErrorHandler());
for (Connector connector : server.getConnectors()) {
for (ConnectionFactory connFac : connector.getConnectionFactories()) {
if (connFac instanceof HttpConnectionFactory) {
((HttpConnectionFactory) connFac).getHttpConfiguration().setSendServerVersion(false);
}
}
}
});
return factory;
}
After upgrade from 2.2.1 to 2.2.2 the custom error handler is no longer invoked.
A minimal sample can be found here: https://github.com/oleborup/spring-boot-jetty-jersey-error-handling
Tests will fail when changing version from 2.2.1 to 2.2.2.
In some cases we use MVC
for static resources and property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "(/.*\\.html)");
in JerseyConfig
. For errors in the static matched cases the default MVC error handler started to be invoked after upgrade to 2.2.2. Solved with @EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
but again the default Jetty error handler was invoked by JettyEmbeddedErrorHandler
and not the custom error handler.
Best regards, Ole