Search in sources :

Example 41 with PropertyMapper

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

the class CassandraAutoConfiguration method mapControlConnectionOptions.

private void mapControlConnectionOptions(CassandraProperties properties, CassandraDriverOptions options) {
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    Controlconnection controlProperties = properties.getControlconnection();
    map.from(controlProperties::getTimeout).asInt(Duration::toMillis).to((timeout) -> options.add(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, timeout));
}
Also used : Controlconnection(org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Controlconnection) PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 42 with PropertyMapper

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

the class RabbitConnectionFactoryBeanConfigurer method configure.

/**
 * Configure the specified rabbit connection factory bean. The factory bean can be
 * further tuned and default settings can be overridden. It is the responsibility of
 * the caller to invoke {@link RabbitConnectionFactoryBean#afterPropertiesSet()}
 * though.
 * @param factory the {@link RabbitConnectionFactoryBean} instance to configure
 */
public void configure(RabbitConnectionFactoryBean factory) {
    Assert.notNull(factory, "RabbitConnectionFactoryBean must not be null");
    factory.setResourceLoader(this.resourceLoader);
    PropertyMapper map = PropertyMapper.get();
    map.from(this.rabbitProperties::determineHost).whenNonNull().to(factory::setHost);
    map.from(this.rabbitProperties::determinePort).to(factory::setPort);
    map.from(this.rabbitProperties::determineUsername).whenNonNull().to(factory::setUsername);
    map.from(this.rabbitProperties::determinePassword).whenNonNull().to(factory::setPassword);
    map.from(this.rabbitProperties::determineVirtualHost).whenNonNull().to(factory::setVirtualHost);
    map.from(this.rabbitProperties::getRequestedHeartbeat).whenNonNull().asInt(Duration::getSeconds).to(factory::setRequestedHeartbeat);
    map.from(this.rabbitProperties::getRequestedChannelMax).to(factory::setRequestedChannelMax);
    RabbitProperties.Ssl ssl = this.rabbitProperties.getSsl();
    if (ssl.determineEnabled()) {
        factory.setUseSSL(true);
        map.from(ssl::getAlgorithm).whenNonNull().to(factory::setSslAlgorithm);
        map.from(ssl::getKeyStoreType).to(factory::setKeyStoreType);
        map.from(ssl::getKeyStore).to(factory::setKeyStore);
        map.from(ssl::getKeyStorePassword).to(factory::setKeyStorePassphrase);
        map.from(ssl::getKeyStoreAlgorithm).whenNonNull().to(factory::setKeyStoreAlgorithm);
        map.from(ssl::getTrustStoreType).to(factory::setTrustStoreType);
        map.from(ssl::getTrustStore).to(factory::setTrustStore);
        map.from(ssl::getTrustStorePassword).to(factory::setTrustStorePassphrase);
        map.from(ssl::getTrustStoreAlgorithm).whenNonNull().to(factory::setTrustStoreAlgorithm);
        map.from(ssl::isValidateServerCertificate).to((validate) -> factory.setSkipServerCertificateValidation(!validate));
        map.from(ssl::getVerifyHostname).to(factory::setEnableHostnameVerification);
    }
    map.from(this.rabbitProperties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis).to(factory::setConnectionTimeout);
    map.from(this.rabbitProperties::getChannelRpcTimeout).whenNonNull().asInt(Duration::toMillis).to(factory::setChannelRpcTimeout);
    map.from(this.credentialsProvider).whenNonNull().to(factory::setCredentialsProvider);
    map.from(this.credentialsRefreshService).whenNonNull().to(factory::setCredentialsRefreshService);
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 43 with PropertyMapper

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

the class RabbitTemplateConfigurer method configure.

/**
 * Configure the specified {@link RabbitTemplate}. The template can be further tuned
 * and default settings can be overridden.
 * @param template the {@link RabbitTemplate} instance to configure
 * @param connectionFactory the {@link ConnectionFactory} to use
 */
public void configure(RabbitTemplate template, ConnectionFactory connectionFactory) {
    PropertyMapper map = PropertyMapper.get();
    template.setConnectionFactory(connectionFactory);
    if (this.messageConverter != null) {
        template.setMessageConverter(this.messageConverter);
    }
    template.setMandatory(determineMandatoryFlag());
    RabbitProperties.Template templateProperties = this.rabbitProperties.getTemplate();
    if (templateProperties.getRetry().isEnabled()) {
        template.setRetryTemplate(new RetryTemplateFactory(this.retryTemplateCustomizers).createRetryTemplate(templateProperties.getRetry(), RabbitRetryTemplateCustomizer.Target.SENDER));
    }
    map.from(templateProperties::getReceiveTimeout).whenNonNull().as(Duration::toMillis).to(template::setReceiveTimeout);
    map.from(templateProperties::getReplyTimeout).whenNonNull().as(Duration::toMillis).to(template::setReplyTimeout);
    map.from(templateProperties::getExchange).to(template::setExchange);
    map.from(templateProperties::getRoutingKey).to(template::setRoutingKey);
    map.from(templateProperties::getDefaultReceiveQueue).whenNonNull().to(template::setDefaultReceiveQueue);
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 44 with PropertyMapper

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

the class SimpleRabbitListenerContainerFactoryConfigurer method configure.

@Override
public void configure(SimpleRabbitListenerContainerFactory factory, ConnectionFactory connectionFactory) {
    PropertyMapper map = PropertyMapper.get();
    RabbitProperties.SimpleContainer config = getRabbitProperties().getListener().getSimple();
    configure(factory, connectionFactory, config);
    map.from(config::getConcurrency).whenNonNull().to(factory::setConcurrentConsumers);
    map.from(config::getMaxConcurrency).whenNonNull().to(factory::setMaxConcurrentConsumers);
    map.from(config::getBatchSize).whenNonNull().to(factory::setBatchSize);
    map.from(config::isConsumerBatchEnabled).to(factory::setConsumerBatchEnabled);
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper)

Example 45 with PropertyMapper

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

the class IntegrationAutoConfiguration method integrationGlobalProperties.

@Bean(name = IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME)
@ConditionalOnMissingBean(name = IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME)
public static org.springframework.integration.context.IntegrationProperties integrationGlobalProperties(IntegrationProperties properties) {
    org.springframework.integration.context.IntegrationProperties integrationProperties = new org.springframework.integration.context.IntegrationProperties();
    PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
    map.from(properties.getChannel().isAutoCreate()).to(integrationProperties::setChannelsAutoCreate);
    map.from(properties.getChannel().getMaxUnicastSubscribers()).to(integrationProperties::setChannelsMaxUnicastSubscribers);
    map.from(properties.getChannel().getMaxBroadcastSubscribers()).to(integrationProperties::setChannelsMaxBroadcastSubscribers);
    map.from(properties.getError().isRequireSubscribers()).to(integrationProperties::setErrorChannelRequireSubscribers);
    map.from(properties.getError().isIgnoreFailures()).to(integrationProperties::setErrorChannelIgnoreFailures);
    map.from(properties.getEndpoint().isThrowExceptionOnLateReply()).to(integrationProperties::setMessagingTemplateThrowExceptionOnLateReply);
    map.from(properties.getEndpoint().getReadOnlyHeaders()).as(StringUtils::toStringArray).to(integrationProperties::setReadOnlyHeaders);
    map.from(properties.getEndpoint().getNoAutoStartup()).as(StringUtils::toStringArray).to(integrationProperties::setNoAutoStartupEndpoints);
    return integrationProperties;
}
Also used : PropertyMapper(org.springframework.boot.context.properties.PropertyMapper) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) Bean(org.springframework.context.annotation.Bean)

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