Commit 98c667c2 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Use PropertyMapper to configure WebServerFactory"

Closes gh-11773
parent 7d4e558f
...@@ -61,21 +61,21 @@ public class DefaultReactiveWebServerFactoryCustomizer ...@@ -61,21 +61,21 @@ public class DefaultReactiveWebServerFactoryCustomizer
@Override @Override
public void customize(ConfigurableReactiveWebServerFactory factory) { public void customize(ConfigurableReactiveWebServerFactory factory) {
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(this.serverProperties::getPort).whenNonNull().to(factory::setPort); map.from(this.serverProperties::getPort).to(factory::setPort);
map.from(this.serverProperties::getAddress).whenNonNull().to(factory::setAddress); map.from(this.serverProperties::getAddress).to(factory::setAddress);
map.from(this.serverProperties::getSsl).whenNonNull().to(factory::setSsl); map.from(this.serverProperties::getSsl).to(factory::setSsl);
map.from(this.serverProperties::getCompression).whenNonNull().to(factory::setCompression); map.from(this.serverProperties::getCompression).to(factory::setCompression);
map.from(this.serverProperties::getHttp2).whenNonNull().to(factory::setHttp2); map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
map.from(() -> factory).when(configurableReactiveWebServerFactory -> factory instanceof TomcatReactiveWebServerFactory) map.from(() -> factory).whenInstanceOf(TomcatReactiveWebServerFactory.class)
.to(configurableReactiveWebServerFactory -> TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, .to(tomcatFactory -> TomcatCustomizer.customizeTomcat(
(TomcatReactiveWebServerFactory) factory)); this.serverProperties, this.environment, tomcatFactory));
map.from(() -> factory).when(configurableReactiveWebServerFactory -> factory instanceof JettyReactiveWebServerFactory) map.from(() -> factory).whenInstanceOf(JettyReactiveWebServerFactory.class)
.to(configurableReactiveWebServerFactory -> JettyCustomizer.customizeJetty(this.serverProperties, this.environment, .to(jettyFactory -> JettyCustomizer.customizeJetty(this.serverProperties,
(JettyReactiveWebServerFactory) factory)); this.environment, jettyFactory));
map.from(() -> factory).when(configurableReactiveWebServerFactory -> factory instanceof UndertowReactiveWebServerFactory) map.from(() -> factory).whenInstanceOf(UndertowReactiveWebServerFactory.class)
.to(configurableReactiveWebServerFactory -> UndertowCustomizer.customizeUndertow(this.serverProperties, this.environment, .to(undertowFactory -> UndertowCustomizer.customizeUndertow(
(UndertowReactiveWebServerFactory) factory)); this.serverProperties, this.environment, undertowFactory));
} }
} }
...@@ -69,30 +69,34 @@ public class DefaultServletWebServerFactoryCustomizer ...@@ -69,30 +69,34 @@ public class DefaultServletWebServerFactoryCustomizer
@Override @Override
public void customize(ConfigurableServletWebServerFactory factory) { public void customize(ConfigurableServletWebServerFactory factory) {
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(this.serverProperties::getPort).whenNonNull().to(factory::setPort); map.from(this.serverProperties::getPort).to(factory::setPort);
map.from(this.serverProperties::getAddress).whenNonNull().to(factory::setAddress); map.from(this.serverProperties::getAddress).to(factory::setAddress);
map.from(this.serverProperties.getServlet()::getContextPath).whenNonNull().to(factory::setContextPath); map.from(this.serverProperties.getServlet()::getContextPath)
map.from(this.serverProperties::getDisplayName).whenNonNull().to(factory::setDisplayName); .to(factory::setContextPath);
map.from(this.serverProperties::getDisplayName).to(factory::setDisplayName);
map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession); map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession);
map.from(this.serverProperties::getSsl).whenNonNull().to(factory::setSsl); map.from(this.serverProperties::getSsl).to(factory::setSsl);
map.from(this.serverProperties::getServlet).whenNonNull().as(ServerProperties.Servlet::getJsp).to(factory::setJsp); map.from(this.serverProperties::getServlet).as(ServerProperties.Servlet::getJsp)
map.from(this.serverProperties::getCompression).whenNonNull().to(factory::setCompression); .to(factory::setJsp);
map.from(this.serverProperties::getHttp2).whenNonNull().to(factory::setHttp2); map.from(this.serverProperties::getCompression).to(factory::setCompression);
map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader); map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader);
map.from(() -> factory).when(configurableServletWebServerFactory -> factory instanceof TomcatServletWebServerFactory) map.from(() -> factory).whenInstanceOf(TomcatServletWebServerFactory.class)
.to(configurableServletWebServerFactory -> { .to(tomcatFactory -> {
TomcatServletWebServerFactory tomcatFactory = (TomcatServletWebServerFactory) factory; TomcatCustomizer.customizeTomcat(this.serverProperties,
TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, tomcatFactory); this.environment, tomcatFactory);
TomcatServletCustomizer.customizeTomcat(this.serverProperties, this.environment, tomcatFactory); TomcatServletCustomizer.customizeTomcat(this.serverProperties,
this.environment, tomcatFactory);
}); });
map.from(() -> factory).when(configurableServletWebServerFactory -> factory instanceof JettyServletWebServerFactory) map.from(() -> factory).whenInstanceOf(JettyServletWebServerFactory.class)
.to(configurableServletWebServerFactory -> JettyCustomizer.customizeJetty(this.serverProperties, this.environment, .to(jettyFactory -> JettyCustomizer.customizeJetty(this.serverProperties,
(JettyServletWebServerFactory) factory)); this.environment, jettyFactory));
map.from(() -> factory).when(configurableServletWebServerFactory -> factory instanceof UndertowServletWebServerFactory) map.from(() -> factory).whenInstanceOf(UndertowServletWebServerFactory.class)
.to(configurableServletWebServerFactory -> UndertowCustomizer.customizeUndertow(this.serverProperties, this.environment, .to(undertowFactory -> UndertowCustomizer.customizeUndertow(
(UndertowServletWebServerFactory) factory)); this.serverProperties, this.environment, undertowFactory));
map.from(this.serverProperties.getServlet()::getContextParameters).to(factory::setInitParameters); map.from(this.serverProperties.getServlet()::getContextParameters)
.to(factory::setInitParameters);
} }
private static class TomcatServletCustomizer { private static class TomcatServletCustomizer {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment