Hi,
I currently testing Spring Boot 2.0.0.M2 and I was wondering how to customize Jetty Server with JettyReactiveWebServerFactory
?
With previous version I used JettyServletWebServerFactory
which allowed to add Jetty Customizers. I was able to customize port, thread pool size and Jetty behaviour like remove ServerVersion Http header, enable Jetty request logging and so on. Ex :
@Bean
public ConfigurableServletWebServerFactory webServerFactory(BeanFactory beanFactory) {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.setPort(8080);
final QueuedThreadPool threadPool = new QueuedThreadPool(applicationConfig.getServerMaxThreads(), applicationConfig.getServerMinThreads(),
applicationConfig.getServerIdleTimeout(), new BlockingArrayQueue<>(100, 100));
threadPool.setName("http");
factory.setThreadPool(threadPool);
// Add customized Jetty configuration
factory.addServerCustomizers(new JettyServerCustomizer[]{(JettyServerCustomizer) server -> {
ServerConnector httpConnector = (ServerConnector) server.getConnectors()[0];
// Remove non necessary headers (Server, X-Powered-By and Date).
HttpConfiguration httpConfiguration = httpConnector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
httpConfiguration.setSendServerVersion(false);
httpConfiguration.setSendXPoweredBy(false);
httpConfiguration.setSendDateHeader(false);
server.addConnector(httpConnector);
...
}
With the reactive version, I still can configure port and pool but I can't found how to customize other specific setting of Jetty server such as enabling logging of requests or disable some headers
@Bean
public JettyReactiveWebServerFactory webServerFactory(BeanFactory beanFactory) {
JettyReactiveWebServerFactory factory = new JettyReactiveWebServerFactory();
factory.setPort(8080);
final QueuedThreadPool threadPool = new QueuedThreadPool(applicationConfig.getServerMaxThreads(), applicationConfig.getServerMinThreads(),
applicationConfig.getServerIdleTimeout(), new BlockingArrayQueue<>(100, 100));
threadPool.setName("http");
factory.setThreadPool(threadPool);
// :-( Not available on reactive version : factory.addServerCustomizers(...)
return factory;
}
Is it intentional ? Is there any kind of limitation concerning customization of Jetty when using the reactive version ?
Thank in advance for your help.
Comment From: wilkinsona
The reactive factories for Tomcat and Undertow are also missing some customiser support: Connector customisers for the former and DeploymentInfo customisers for the latter.
Perhaps that was intentional, but I can't think of a reason why such customisation shouldn't be supported in the reactive case.
Comment From: philwebb
I don't think it was intentional, probably just an oversight.
Comment From: mbhave
probably also need BuilderCustomizer
for Undertow?
Comment From: wilkinsona
Oops, I missed that. Yeah, I think we do. Thanks @mbhave!
Comment From: oneutf
How about a Chinese document