Search in sources :

Example 16 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class ReactiveElasticsearchRestClientAutoConfiguration method clientConfiguration.

@Bean
@ConditionalOnMissingBean
public ClientConfiguration clientConfiguration() {
    ClientConfiguration.MaybeSecureClientConfigurationBuilder builder = ClientConfiguration.builder().connectedTo(this.properties.getEndpoints().toArray(new String[0]));
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(this.properties.isUseSsl()).whenTrue().toCall(builder::usingSsl);
    map.from(this.properties.getCredentials()).to((credentials) -> builder.withBasicAuth(credentials.getUsername(), credentials.getPassword()));
    map.from(this.properties.getConnectionTimeout()).to(builder::withConnectTimeout);
    map.from(this.properties.getSocketTimeout()).to(builder::withSocketTimeout);
    map.from(this.properties.getPathPrefix()).to(builder::withPathPrefix);
    configureExchangeStrategies(map, builder);
    return builder.build();
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) ClientConfiguration(org.springframework.data.elasticsearch.client.ClientConfiguration) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizer method customize.

@Override
public void customize(NettyReactiveWebServerFactory factory) {
    factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
    PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
    ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
    propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull().to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
    propertyMapper.from(nettyProperties::getIdleTimeout).whenNonNull().to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
    propertyMapper.from(nettyProperties::getMaxKeepAliveRequests).to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
    customizeRequestDecoder(factory, propertyMapper);
}
Also used : ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 18 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper in project spring-boot by spring-projects.

the class UndertowWebServerFactoryCustomizer method mapAccessLogProperties.

private void mapAccessLogProperties(ConfigurableUndertowWebServerFactory factory) {
    Accesslog properties = this.serverProperties.getUndertow().getAccesslog();
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(properties::isEnabled).to(factory::setAccessLogEnabled);
    map.from(properties::getDir).to(factory::setAccessLogDirectory);
    map.from(properties::getPattern).to(factory::setAccessLogPattern);
    map.from(properties::getPrefix).to(factory::setAccessLogPrefix);
    map.from(properties::getSuffix).to(factory::setAccessLogSuffix);
    map.from(properties::isRotate).to(factory::setAccessLogRotate);
}
Also used : Accesslog(org.springframework.boot.autoconfigure.web.ServerProperties.Undertow.Accesslog) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 19 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper 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 20 with PropertyMapper

use of org.springframework.boot.context.properties.PropertyMapper 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)

Aggregations

PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)49 Bean (org.springframework.context.annotation.Bean)9 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)8 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)4 DataSize (org.springframework.util.unit.DataSize)4 Duration (java.time.Duration)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IOException (java.io.IOException)2 Map (java.util.Map)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)2 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)2 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)2 Connection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Connection)2 Controlconnection (org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Controlconnection)2 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)2 Listener (org.springframework.boot.autoconfigure.kafka.KafkaProperties.Listener)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 ConsumerAwareRebalanceListener (org.springframework.kafka.listener.ConsumerAwareRebalanceListener)2 StringUtils (org.springframework.util.StringUtils)2