Search in sources :

Example 1 with ConfigurableTomcatWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory in project spring-boot by spring-projects.

the class TomcatWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableTomcatWebServerFactory factory) {
    ServerProperties properties = this.serverProperties;
    ServerProperties.Tomcat tomcatProperties = properties.getTomcat();
    PropertyMapper propertyMapper = PropertyMapper.get();
    propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory);
    propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay).whenNonNull().as(Duration::getSeconds).as(Long::intValue).to(factory::setBackgroundProcessorDelay);
    customizeRemoteIpValve(factory);
    ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads();
    propertyMapper.from(threadProperties::getMax).when(this::isPositive).to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax()));
    propertyMapper.from(threadProperties::getMinSpare).when(this::isPositive).to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
    propertyMapper.from(this.serverProperties.getMaxHttpHeaderSize()).whenNonNull().asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
    propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes).to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
    propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0).to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
    propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled).to((enabled) -> customizeAccessLog(factory));
    propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
    propertyMapper.from(tomcatProperties::getConnectionTimeout).whenNonNull().to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
    propertyMapper.from(tomcatProperties::getMaxConnections).when(this::isPositive).to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
    propertyMapper.from(tomcatProperties::getAcceptCount).when(this::isPositive).to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
    propertyMapper.from(tomcatProperties::getProcessorCache).to((processorCache) -> customizeProcessorCache(factory, processorCache));
    propertyMapper.from(tomcatProperties::getKeepAliveTimeout).whenNonNull().to((keepAliveTimeout) -> customizeKeepAliveTimeout(factory, keepAliveTimeout));
    propertyMapper.from(tomcatProperties::getMaxKeepAliveRequests).to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
    propertyMapper.from(tomcatProperties::getRelaxedPathChars).as(this::joinCharacters).whenHasText().to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars));
    propertyMapper.from(tomcatProperties::getRelaxedQueryChars).as(this::joinCharacters).whenHasText().to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
    propertyMapper.from(tomcatProperties::isRejectIllegalHeader).to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader));
    customizeStaticResources(factory);
    customizeErrorReportValve(properties.getError(), factory);
}
Also used : IncludeAttribute(org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Ordered(org.springframework.core.Ordered) CloudPlatform(org.springframework.boot.cloud.CloudPlatform) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) Lifecycle(org.apache.catalina.Lifecycle) ErrorReportValve(org.apache.catalina.valves.ErrorReportValve) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) WebServerFactoryCustomizer(org.springframework.boot.web.server.WebServerFactoryCustomizer) Collectors(java.util.stream.Collectors) AccessLogValve(org.apache.catalina.valves.AccessLogValve) ErrorProperties(org.springframework.boot.autoconfigure.web.ErrorProperties) List(java.util.List) ProtocolHandler(org.apache.coyote.ProtocolHandler) Accesslog(org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog) Environment(org.springframework.core.env.Environment) Duration(java.time.Duration) Remoteip(org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip) ConfigurableTomcatWebServerFactory(org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory) AbstractProtocol(org.apache.coyote.AbstractProtocol) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) StringUtils(org.springframework.util.StringUtils) DataSize(org.springframework.util.unit.DataSize) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DataSize(org.springframework.util.unit.DataSize) Duration(java.time.Duration) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Aggregations

Duration (java.time.Duration)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Lifecycle (org.apache.catalina.Lifecycle)1 AccessLogValve (org.apache.catalina.valves.AccessLogValve)1 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)1 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)1 AbstractProtocol (org.apache.coyote.AbstractProtocol)1 ProtocolHandler (org.apache.coyote.ProtocolHandler)1 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)1 ErrorProperties (org.springframework.boot.autoconfigure.web.ErrorProperties)1 IncludeAttribute (org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1 Accesslog (org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog)1 Remoteip (org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip)1 CloudPlatform (org.springframework.boot.cloud.CloudPlatform)1 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)1 ConfigurableTomcatWebServerFactory (org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory)1 WebServerFactoryCustomizer (org.springframework.boot.web.server.WebServerFactoryCustomizer)1 Ordered (org.springframework.core.Ordered)1