parent
988fc18f8c
commit
19542b975f
|
|
@ -30,6 +30,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
|
|||
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
|
@ -50,24 +51,17 @@ public final class JettyCustomizer {
|
|||
ServerProperties.Jetty jettyProperties = serverProperties.getJetty();
|
||||
factory.setUseForwardHeaders(
|
||||
getOrDeduceUseForwardHeaders(serverProperties, environment));
|
||||
if (jettyProperties.getAcceptors() != null) {
|
||||
factory.setAcceptors(jettyProperties.getAcceptors());
|
||||
}
|
||||
if (jettyProperties.getSelectors() != null) {
|
||||
factory.setSelectors(jettyProperties.getSelectors());
|
||||
}
|
||||
if (serverProperties.getMaxHttpHeaderSize() > 0) {
|
||||
customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize());
|
||||
}
|
||||
if (jettyProperties.getMaxHttpPostSize() > 0) {
|
||||
customizeMaxHttpPostSize(factory, jettyProperties.getMaxHttpPostSize());
|
||||
}
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout());
|
||||
}
|
||||
if (jettyProperties.getAccesslog().isEnabled()) {
|
||||
customizeAccessLog(factory, jettyProperties.getAccesslog());
|
||||
}
|
||||
PropertyMapper propertyMapper = PropertyMapper.get();
|
||||
propertyMapper.from(jettyProperties::getAcceptors).whenNonNull().to(factory::setAcceptors);
|
||||
propertyMapper.from(jettyProperties::getSelectors).whenNonNull().to(factory::setSelectors);
|
||||
propertyMapper.from(serverProperties::getMaxHttpHeaderSize).when(maxHttpHeaderSize -> maxHttpHeaderSize > 0)
|
||||
.to(maxHttpHeaderSize -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
||||
propertyMapper.from(jettyProperties::getMaxHttpPostSize).when(maxHttpPostSize -> maxHttpPostSize > 0)
|
||||
.to(maxHttpPostSize -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
||||
propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull()
|
||||
.to(connectionTimeout -> customizeConnectionTimeout(factory, connectionTimeout));
|
||||
propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled)
|
||||
.to(accesslog -> customizeAccessLog(factory, accesslog));
|
||||
}
|
||||
|
||||
private static boolean getOrDeduceUseForwardHeaders(ServerProperties serverProperties,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.apache.coyote.http11.AbstractHttp11Protocol;
|
|||
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
|
@ -36,6 +37,7 @@ import org.springframework.util.StringUtils;
|
|||
* servers.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Yulin Qin
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class TomcatCustomizer {
|
||||
|
|
@ -46,44 +48,32 @@ public final class TomcatCustomizer {
|
|||
public static void customizeTomcat(ServerProperties serverProperties,
|
||||
Environment environment, ConfigurableTomcatWebServerFactory factory) {
|
||||
ServerProperties.Tomcat tomcatProperties = serverProperties.getTomcat();
|
||||
if (tomcatProperties.getBasedir() != null) {
|
||||
factory.setBaseDirectory(tomcatProperties.getBasedir());
|
||||
}
|
||||
if (tomcatProperties.getBackgroundProcessorDelay() != null) {
|
||||
factory.setBackgroundProcessorDelay(
|
||||
(int) tomcatProperties.getBackgroundProcessorDelay().getSeconds());
|
||||
}
|
||||
|
||||
PropertyMapper propertyMapper = PropertyMapper.get();
|
||||
propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory);
|
||||
propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay).whenNonNull()
|
||||
.to((backgroundProcessorDelay) -> factory.setBackgroundProcessorDelay((int) backgroundProcessorDelay.getSeconds()));
|
||||
customizeRemoteIpValve(serverProperties, environment, factory);
|
||||
if (tomcatProperties.getMaxThreads() > 0) {
|
||||
customizeMaxThreads(factory, tomcatProperties.getMaxThreads());
|
||||
}
|
||||
if (tomcatProperties.getMinSpareThreads() > 0) {
|
||||
customizeMinThreads(factory, tomcatProperties.getMinSpareThreads());
|
||||
}
|
||||
int maxHttpHeaderSize = (serverProperties.getMaxHttpHeaderSize() > 0
|
||||
propertyMapper.from(tomcatProperties::getMaxThreads).when(maxThreads -> maxThreads > 0)
|
||||
.to(maxThreads -> customizeMaxThreads(factory, tomcatProperties.getMaxThreads()));
|
||||
propertyMapper.from(tomcatProperties::getMinSpareThreads).when(minSpareThreads -> minSpareThreads > 0)
|
||||
.to(minSpareThreads -> customizeMinThreads(factory, minSpareThreads));
|
||||
propertyMapper.from(() -> (serverProperties.getMaxHttpHeaderSize() > 0
|
||||
? serverProperties.getMaxHttpHeaderSize()
|
||||
: tomcatProperties.getMaxHttpHeaderSize());
|
||||
if (maxHttpHeaderSize > 0) {
|
||||
customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize);
|
||||
}
|
||||
if (tomcatProperties.getMaxHttpPostSize() != 0) {
|
||||
customizeMaxHttpPostSize(factory, tomcatProperties.getMaxHttpPostSize());
|
||||
}
|
||||
if (tomcatProperties.getAccesslog().isEnabled()) {
|
||||
customizeAccessLog(tomcatProperties, factory);
|
||||
}
|
||||
if (tomcatProperties.getUriEncoding() != null) {
|
||||
factory.setUriEncoding(tomcatProperties.getUriEncoding());
|
||||
}
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout());
|
||||
}
|
||||
if (tomcatProperties.getMaxConnections() > 0) {
|
||||
customizeMaxConnections(factory, tomcatProperties.getMaxConnections());
|
||||
}
|
||||
if (tomcatProperties.getAcceptCount() > 0) {
|
||||
customizeAcceptCount(factory, tomcatProperties.getAcceptCount());
|
||||
}
|
||||
: tomcatProperties.getMaxHttpHeaderSize()))
|
||||
.when(maxHttpHeaderSize -> maxHttpHeaderSize > 0)
|
||||
.to(maxHttpHeaderSize -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
||||
propertyMapper.from(tomcatProperties::getMaxHttpPostSize).when(maxHttpPostSize -> maxHttpPostSize != 0)
|
||||
.to(maxHttpPostSize -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
||||
propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
|
||||
.to(enabled -> customizeAccessLog(tomcatProperties, factory));
|
||||
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
|
||||
propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull()
|
||||
.to(connectionTimeout -> customizeConnectionTimeout(factory, connectionTimeout));
|
||||
propertyMapper.from(tomcatProperties::getMaxConnections).when(maxConnections -> maxConnections > 0)
|
||||
.to(maxConnections -> customizeMaxConnections(factory, maxConnections));
|
||||
propertyMapper.from(tomcatProperties::getAcceptCount).when(acceptCount -> acceptCount > 0)
|
||||
.to(acceptCount -> customizeAcceptCount(factory, acceptCount));
|
||||
customizeStaticResources(serverProperties.getTomcat().getResource(), factory);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import io.undertow.UndertowOptions;
|
|||
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.web.embedded.undertow.ConfigurableUndertowWebServerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ import org.springframework.core.env.Environment;
|
|||
* servers.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Yulin Qin
|
||||
*/
|
||||
public final class UndertowCustomizer {
|
||||
|
||||
|
|
@ -41,38 +43,27 @@ public final class UndertowCustomizer {
|
|||
ServerProperties.Undertow undertowProperties = serverProperties.getUndertow();
|
||||
ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties
|
||||
.getAccesslog();
|
||||
if (undertowProperties.getBufferSize() != null) {
|
||||
factory.setBufferSize(undertowProperties.getBufferSize());
|
||||
}
|
||||
if (undertowProperties.getIoThreads() != null) {
|
||||
factory.setIoThreads(undertowProperties.getIoThreads());
|
||||
}
|
||||
if (undertowProperties.getWorkerThreads() != null) {
|
||||
factory.setWorkerThreads(undertowProperties.getWorkerThreads());
|
||||
}
|
||||
if (undertowProperties.getDirectBuffers() != null) {
|
||||
factory.setUseDirectBuffers(undertowProperties.getDirectBuffers());
|
||||
}
|
||||
if (undertowProperties.getAccesslog().getEnabled() != null) {
|
||||
factory.setAccessLogEnabled(accesslogProperties.getEnabled());
|
||||
}
|
||||
factory.setAccessLogDirectory(accesslogProperties.getDir());
|
||||
factory.setAccessLogPattern(accesslogProperties.getPattern());
|
||||
factory.setAccessLogPrefix(accesslogProperties.getPrefix());
|
||||
factory.setAccessLogSuffix(accesslogProperties.getSuffix());
|
||||
factory.setAccessLogRotate(accesslogProperties.isRotate());
|
||||
factory.setUseForwardHeaders(
|
||||
getOrDeduceUseForwardHeaders(serverProperties, environment));
|
||||
if (serverProperties.getMaxHttpHeaderSize() > 0) {
|
||||
customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize());
|
||||
}
|
||||
if (undertowProperties.getMaxHttpPostSize() > 0) {
|
||||
customizeMaxHttpPostSize(factory, undertowProperties.getMaxHttpPostSize());
|
||||
}
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout());
|
||||
}
|
||||
factory.addDeploymentInfoCustomizers((deploymentInfo) -> deploymentInfo
|
||||
|
||||
PropertyMapper propertyMapper = PropertyMapper.get();
|
||||
propertyMapper.from(undertowProperties::getBufferSize).whenNonNull().to(factory::setBufferSize);
|
||||
propertyMapper.from(undertowProperties::getIoThreads).whenNonNull().to(factory::setIoThreads);
|
||||
propertyMapper.from(undertowProperties::getWorkerThreads).whenNonNull().to(factory::setWorkerThreads);
|
||||
propertyMapper.from(undertowProperties::getDirectBuffers).whenNonNull().to(factory::setUseDirectBuffers);
|
||||
propertyMapper.from(accesslogProperties::getEnabled).whenNonNull().to(factory::setAccessLogEnabled);
|
||||
propertyMapper.from(accesslogProperties::getDir).to(factory::setAccessLogDirectory);
|
||||
propertyMapper.from(accesslogProperties::getPattern).to(factory::setAccessLogPattern);
|
||||
propertyMapper.from(accesslogProperties::getPrefix).to(factory::setAccessLogPrefix);
|
||||
propertyMapper.from(accesslogProperties::getSuffix).to(factory::setAccessLogSuffix);
|
||||
propertyMapper.from(accesslogProperties::isRotate).to(factory::setAccessLogRotate);
|
||||
propertyMapper.from(() -> getOrDeduceUseForwardHeaders(serverProperties, environment)).to(factory::setUseForwardHeaders);
|
||||
|
||||
propertyMapper.from(serverProperties::getMaxHttpHeaderSize).when(maxHttpHeaderSize -> maxHttpHeaderSize > 0)
|
||||
.to(maxHttpHeaderSize -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
||||
propertyMapper.from(undertowProperties::getMaxHttpPostSize).when(maxHttpPostSize -> maxHttpPostSize > 0)
|
||||
.to(maxHttpPostSize -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
||||
propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull()
|
||||
.to(connectionTimeout -> customizeConnectionTimeout(factory, connectionTimeout));
|
||||
factory.addDeploymentInfoCustomizers(deploymentInfo -> deploymentInfo
|
||||
.setEagerFilterInit(undertowProperties.isEagerFilterInit()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue