Search in sources :

Example 31 with PropertyMapper

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

the class TomcatWebServerFactoryCustomizer method customizeAccessLog.

private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
    ServerProperties.Tomcat tomcatProperties = this.serverProperties.getTomcat();
    AccessLogValve valve = new AccessLogValve();
    PropertyMapper map = PropertyMapper.get();
    Accesslog accessLogConfig = tomcatProperties.getAccesslog();
    map.from(accessLogConfig.getConditionIf()).to(valve::setConditionIf);
    map.from(accessLogConfig.getConditionUnless()).to(valve::setConditionUnless);
    map.from(accessLogConfig.getPattern()).to(valve::setPattern);
    map.from(accessLogConfig.getDirectory()).to(valve::setDirectory);
    map.from(accessLogConfig.getPrefix()).to(valve::setPrefix);
    map.from(accessLogConfig.getSuffix()).to(valve::setSuffix);
    map.from(accessLogConfig.getEncoding()).whenHasText().to(valve::setEncoding);
    map.from(accessLogConfig.getLocale()).whenHasText().to(valve::setLocale);
    map.from(accessLogConfig.isCheckExists()).to(valve::setCheckExists);
    map.from(accessLogConfig.isRotate()).to(valve::setRotatable);
    map.from(accessLogConfig.isRenameOnRotate()).to(valve::setRenameOnRotate);
    map.from(accessLogConfig.getMaxDays()).to(valve::setMaxDays);
    map.from(accessLogConfig.getFileDateFormat()).to(valve::setFileDateFormat);
    map.from(accessLogConfig.isIpv6Canonical()).to(valve::setIpv6Canonical);
    map.from(accessLogConfig.isRequestAttributesEnabled()).to(valve::setRequestAttributesEnabled);
    map.from(accessLogConfig.isBuffered()).to(valve::setBuffered);
    factory.addEngineValves(valve);
}
Also used : Accesslog(org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) AccessLogValve(org.apache.catalina.valves.AccessLogValve)

Example 32 with PropertyMapper

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

Example 33 with PropertyMapper

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

the class ServletWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableServletWebServerFactory factory) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(this.serverProperties::getPort).to(factory::setPort);
    map.from(this.serverProperties::getAddress).to(factory::setAddress);
    map.from(this.serverProperties.getServlet()::getContextPath).to(factory::setContextPath);
    map.from(this.serverProperties.getServlet()::getApplicationDisplayName).to(factory::setDisplayName);
    map.from(this.serverProperties.getServlet()::isRegisterDefaultServlet).to(factory::setRegisterDefaultServlet);
    map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession);
    map.from(this.serverProperties::getSsl).to(factory::setSsl);
    map.from(this.serverProperties.getServlet()::getJsp).to(factory::setJsp);
    map.from(this.serverProperties::getCompression).to(factory::setCompression);
    map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
    map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader);
    map.from(this.serverProperties.getServlet()::getContextParameters).to(factory::setInitParameters);
    map.from(this.serverProperties.getShutdown()).to(factory::setShutdown);
    for (WebListenerRegistrar registrar : this.webListenerRegistrars) {
        registrar.register(factory);
    }
    if (!CollectionUtils.isEmpty(this.cookieSameSiteSuppliers)) {
        factory.setCookieSameSiteSuppliers(this.cookieSameSiteSuppliers);
    }
}
Also used : WebListenerRegistrar(org.springframework.boot.web.servlet.WebListenerRegistrar) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 34 with PropertyMapper

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

the class ReactiveWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableReactiveWebServerFactory factory) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(this.serverProperties::getPort).to(factory::setPort);
    map.from(this.serverProperties::getAddress).to(factory::setAddress);
    map.from(this.serverProperties::getSsl).to(factory::setSsl);
    map.from(this.serverProperties::getCompression).to(factory::setCompression);
    map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
    map.from(this.serverProperties.getShutdown()).to(factory::setShutdown);
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 35 with PropertyMapper

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

the class OAuth2ClientPropertiesRegistrationAdapter method getClientRegistration.

private static ClientRegistration getClientRegistration(String registrationId, OAuth2ClientProperties.Registration properties, Map<String, Provider> providers) {
    Builder builder = getBuilderFromIssuerIfPossible(registrationId, properties.getProvider(), providers);
    if (builder == null) {
        builder = getBuilder(registrationId, properties.getProvider(), providers);
    }
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(properties::getClientId).to(builder::clientId);
    map.from(properties::getClientSecret).to(builder::clientSecret);
    map.from(properties::getClientAuthenticationMethod).as(ClientAuthenticationMethod::new).to(builder::clientAuthenticationMethod);
    map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new).to(builder::authorizationGrantType);
    map.from(properties::getRedirectUri).to(builder::redirectUri);
    map.from(properties::getScope).as(StringUtils::toStringArray).to(builder::scope);
    map.from(properties::getClientName).to(builder::clientName);
    return builder.build();
}
Also used : Builder(org.springframework.security.oauth2.client.registration.ClientRegistration.Builder) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

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