|
|
|
@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.jetty.JettyCustomizer; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.tomcat.TomcatCustomizer; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer; |
|
|
|
import org.springframework.boot.autoconfigure.web.embedded.undertow.UndertowCustomizer; |
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.PropertyMapper; |
|
|
|
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; |
|
|
|
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; |
|
|
|
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory; |
|
|
|
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory; |
|
|
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; |
|
|
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; |
|
|
|
@ -37,6 +38,7 @@ import org.springframework.util.ObjectUtils; |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Olivier Lamy |
|
|
|
* @author Olivier Lamy |
|
|
|
|
|
|
|
* @author Yunkun Huang |
|
|
|
* @since 2.0.0 |
|
|
|
* @since 2.0.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DefaultServletWebServerFactoryCustomizer |
|
|
|
public class DefaultServletWebServerFactoryCustomizer |
|
|
|
@ -67,49 +69,34 @@ public class DefaultServletWebServerFactoryCustomizer |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void customize(ConfigurableServletWebServerFactory factory) { |
|
|
|
public void customize(ConfigurableServletWebServerFactory factory) { |
|
|
|
if (this.serverProperties.getPort() != null) { |
|
|
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); |
|
|
|
factory.setPort(this.serverProperties.getPort()); |
|
|
|
map.from(this.serverProperties::getPort).to(factory::setPort); |
|
|
|
} |
|
|
|
map.from(this.serverProperties::getAddress).to(factory::setAddress); |
|
|
|
if (this.serverProperties.getAddress() != null) { |
|
|
|
map.from(this.serverProperties.getServlet()::getContextPath) |
|
|
|
factory.setAddress(this.serverProperties.getAddress()); |
|
|
|
.to(factory::setContextPath); |
|
|
|
} |
|
|
|
map.from(this.serverProperties::getDisplayName).to(factory::setDisplayName); |
|
|
|
if (this.serverProperties.getServlet().getContextPath() != null) { |
|
|
|
map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession); |
|
|
|
factory.setContextPath(this.serverProperties.getServlet().getContextPath()); |
|
|
|
map.from(this.serverProperties::getSsl).to(factory::setSsl); |
|
|
|
} |
|
|
|
map.from(this.serverProperties::getServlet).as(ServerProperties.Servlet::getJsp) |
|
|
|
if (this.serverProperties.getDisplayName() != null) { |
|
|
|
.to(factory::setJsp); |
|
|
|
factory.setDisplayName(this.serverProperties.getDisplayName()); |
|
|
|
map.from(this.serverProperties::getCompression).to(factory::setCompression); |
|
|
|
} |
|
|
|
map.from(this.serverProperties::getHttp2).to(factory::setHttp2); |
|
|
|
factory.setSession(this.serverProperties.getServlet().getSession()); |
|
|
|
map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader); |
|
|
|
if (this.serverProperties.getSsl() != null) { |
|
|
|
map.from(() -> factory).whenInstanceOf(TomcatServletWebServerFactory.class) |
|
|
|
factory.setSsl(this.serverProperties.getSsl()); |
|
|
|
.to(tomcatFactory -> { |
|
|
|
} |
|
|
|
TomcatCustomizer.customizeTomcat(this.serverProperties, |
|
|
|
if (this.serverProperties.getServlet() != null) { |
|
|
|
this.environment, tomcatFactory); |
|
|
|
factory.setJsp(this.serverProperties.getServlet().getJsp()); |
|
|
|
TomcatServletCustomizer.customizeTomcat(this.serverProperties, |
|
|
|
} |
|
|
|
this.environment, tomcatFactory); |
|
|
|
if (this.serverProperties.getCompression() != null) { |
|
|
|
}); |
|
|
|
factory.setCompression(this.serverProperties.getCompression()); |
|
|
|
map.from(() -> factory).whenInstanceOf(JettyServletWebServerFactory.class) |
|
|
|
} |
|
|
|
.to(jettyFactory -> JettyCustomizer.customizeJetty(this.serverProperties, |
|
|
|
if (this.serverProperties.getHttp2() != null) { |
|
|
|
this.environment, jettyFactory)); |
|
|
|
factory.setHttp2(this.serverProperties.getHttp2()); |
|
|
|
map.from(() -> factory).whenInstanceOf(UndertowServletWebServerFactory.class) |
|
|
|
} |
|
|
|
.to(undertowFactory -> UndertowCustomizer.customizeUndertow( |
|
|
|
factory.setServerHeader(this.serverProperties.getServerHeader()); |
|
|
|
this.serverProperties, this.environment, undertowFactory)); |
|
|
|
if (factory instanceof TomcatServletWebServerFactory) { |
|
|
|
map.from(this.serverProperties.getServlet()::getContextParameters) |
|
|
|
TomcatServletWebServerFactory tomcatFactory = (TomcatServletWebServerFactory) factory; |
|
|
|
.to(factory::setInitParameters); |
|
|
|
TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, |
|
|
|
|
|
|
|
tomcatFactory); |
|
|
|
|
|
|
|
TomcatServletCustomizer.customizeTomcat(this.serverProperties, |
|
|
|
|
|
|
|
this.environment, tomcatFactory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (factory instanceof JettyServletWebServerFactory) { |
|
|
|
|
|
|
|
JettyCustomizer.customizeJetty(this.serverProperties, this.environment, |
|
|
|
|
|
|
|
(JettyServletWebServerFactory) factory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (factory instanceof UndertowServletWebServerFactory) { |
|
|
|
|
|
|
|
UndertowCustomizer.customizeUndertow(this.serverProperties, this.environment, |
|
|
|
|
|
|
|
(UndertowServletWebServerFactory) factory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
factory.setInitParameters( |
|
|
|
|
|
|
|
this.serverProperties.getServlet().getContextParameters()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class TomcatServletCustomizer { |
|
|
|
private static class TomcatServletCustomizer { |
|
|
|
|