Search in sources :

Example 1 with DataSize

use of org.springframework.util.unit.DataSize 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)

Example 2 with DataSize

use of org.springframework.util.unit.DataSize in project spring-boot by spring-projects.

the class UndertowWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableUndertowWebServerFactory factory) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    ServerOptions options = new ServerOptions(factory);
    ServerProperties properties = this.serverProperties;
    map.from(properties::getMaxHttpHeaderSize).asInt(DataSize::toBytes).when(this::isPositive).to(options.option(UndertowOptions.MAX_HEADER_SIZE));
    mapUndertowProperties(factory, options);
    mapAccessLogProperties(factory);
    map.from(this::getOrDeduceUseForwardHeaders).to(factory::setUseForwardHeaders);
}
Also used : ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DataSize(org.springframework.util.unit.DataSize) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 3 with DataSize

use of org.springframework.util.unit.DataSize in project spring-boot by spring-projects.

the class UndertowWebServerFactoryCustomizer method mapUndertowProperties.

private void mapUndertowProperties(ConfigurableUndertowWebServerFactory factory, ServerOptions serverOptions) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Undertow properties = this.serverProperties.getUndertow();
    map.from(properties::getBufferSize).whenNonNull().asInt(DataSize::toBytes).to(factory::setBufferSize);
    ServerProperties.Undertow.Threads threadProperties = properties.getThreads();
    map.from(threadProperties::getIo).to(factory::setIoThreads);
    map.from(threadProperties::getWorker).to(factory::setWorkerThreads);
    map.from(properties::getDirectBuffers).to(factory::setUseDirectBuffers);
    map.from(properties::getMaxHttpPostSize).as(DataSize::toBytes).when(this::isPositive).to(serverOptions.option(UndertowOptions.MAX_ENTITY_SIZE));
    map.from(properties::getMaxParameters).to(serverOptions.option(UndertowOptions.MAX_PARAMETERS));
    map.from(properties::getMaxHeaders).to(serverOptions.option(UndertowOptions.MAX_HEADERS));
    map.from(properties::getMaxCookies).to(serverOptions.option(UndertowOptions.MAX_COOKIES));
    map.from(properties::isAllowEncodedSlash).to(serverOptions.option(UndertowOptions.ALLOW_ENCODED_SLASH));
    map.from(properties::isDecodeUrl).to(serverOptions.option(UndertowOptions.DECODE_URL));
    map.from(properties::getUrlCharset).as(Charset::name).to(serverOptions.option(UndertowOptions.URL_CHARSET));
    map.from(properties::isAlwaysSetKeepAlive).to(serverOptions.option(UndertowOptions.ALWAYS_SET_KEEP_ALIVE));
    map.from(properties::getNoRequestTimeout).asInt(Duration::toMillis).to(serverOptions.option(UndertowOptions.NO_REQUEST_TIMEOUT));
    map.from(properties.getOptions()::getServer).to(serverOptions.forEach(serverOptions::option));
    SocketOptions socketOptions = new SocketOptions(factory);
    map.from(properties.getOptions()::getSocket).to(socketOptions.forEach(socketOptions::option));
}
Also used : DataSize(org.springframework.util.unit.DataSize) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) Undertow(org.springframework.boot.autoconfigure.web.ServerProperties.Undertow)

Example 4 with DataSize

use of org.springframework.util.unit.DataSize in project spring-boot by spring-projects.

the class JettyWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableJettyWebServerFactory factory) {
    ServerProperties properties = this.serverProperties;
    ServerProperties.Jetty jettyProperties = properties.getJetty();
    factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
    ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads();
    factory.setThreadPool(determineThreadPool(jettyProperties.getThreads()));
    PropertyMapper propertyMapper = PropertyMapper.get();
    propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors);
    propertyMapper.from(threadProperties::getSelectors).whenNonNull().to(factory::setSelectors);
    propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpHeaderSize) -> factory.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
    propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive).to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
    propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull().to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
    propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled).to((accesslog) -> customizeAccessLog(factory, accesslog));
}
Also used : ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DataSize(org.springframework.util.unit.DataSize) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 5 with DataSize

use of org.springframework.util.unit.DataSize in project spring-boot by spring-projects.

the class ReactiveMultipartAutoConfiguration method defaultPartHttpMessageReaderCustomizer.

@Bean
@Order(0)
CodecCustomizer defaultPartHttpMessageReaderCustomizer(ReactiveMultipartProperties multipartProperties) {
    return (configurer) -> configurer.defaultCodecs().configureDefaultCodec((codec) -> {
        if (codec instanceof DefaultPartHttpMessageReader) {
            DefaultPartHttpMessageReader defaultPartHttpMessageReader = (DefaultPartHttpMessageReader) codec;
            PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
            map.from(multipartProperties::getMaxInMemorySize).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxInMemorySize);
            map.from(multipartProperties::getMaxHeadersSize).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxHeadersSize);
            map.from(multipartProperties::getMaxDiskUsagePerPart).asInt(DataSize::toBytes).to(defaultPartHttpMessageReader::setMaxDiskUsagePerPart);
            map.from(multipartProperties::getMaxParts).to(defaultPartHttpMessageReader::setMaxParts);
            map.from(multipartProperties::getStreaming).to(defaultPartHttpMessageReader::setStreaming);
            map.from(multipartProperties::getFileStorageDirectory).as(Paths::get).to((dir) -> configureFileStorageDirectory(defaultPartHttpMessageReader, dir));
            map.from(multipartProperties::getHeadersCharset).to(defaultPartHttpMessageReader::setHeadersCharset);
        }
    });
}
Also used : Order(org.springframework.core.annotation.Order) WebFluxConfigurer(org.springframework.web.reactive.config.WebFluxConfigurer) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) IOException(java.io.IOException) Paths(java.nio.file.Paths) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Bean(org.springframework.context.annotation.Bean) AutoConfiguration(org.springframework.boot.autoconfigure.AutoConfiguration) Path(java.nio.file.Path) ConditionalOnWebApplication(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication) Type(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) DataSize(org.springframework.util.unit.DataSize) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Aggregations

DataSize (org.springframework.util.unit.DataSize)6 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)5 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)3 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 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 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnWebApplication (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication)1