org.springframework.boot.context.properties.PropertyMapper Java Examples

The following examples show how to use org.springframework.boot.context.properties.PropertyMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeihuMutilElasticsearchJestAutoConfiguration.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
protected HttpClientConfig createHttpClientConfig(BeihuMutilElasticsearchJestProperties.Instances instance) {
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder(
            instance.getUris());
    PropertyMapper map = PropertyMapper.get();
    map.from(instance::getUsername).whenHasText().to((username) -> builder
            .defaultCredentials(username, instance.getPassword()));

    map.from(this.gsonProvider::getIfUnique).whenNonNull().to(builder::gson);
    map.from(instance::isMultiThreaded).to(builder::multiThreaded);
    map.from(instance::getConnectionTimeout).whenNonNull()
            .asInt(Duration::toMillis).to(builder::connTimeout);
    map.from(instance::getReadTimeout).whenNonNull().asInt(Duration::toMillis)
            .to(builder::readTimeout);
    customize(builder);
    return builder.build();
}
 
Example #2
Source File: RestAutoConfigure.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * 异步httpclient连接数配置
 */
private void setHttpClientConfig(RestClientBuilder builder, RestClientPoolProperties poolProperties, RestClientProperties restProperties){
    builder.setHttpClientConfigCallback(httpClientBuilder -> {
        httpClientBuilder.setMaxConnTotal(poolProperties.getMaxConnectNum())
                .setMaxConnPerRoute(poolProperties.getMaxConnectPerRoute());

        PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
        map.from(restProperties::getUsername).to(username -> {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(username, restProperties.getPassword()));
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        });
        return httpClientBuilder;
    });
}
 
Example #3
Source File: CorsProperties.java    From syhthems-platform with MIT License 6 votes vote down vote up
public CorsConfiguration toCorsConfiguration() {
    if (CollectionUtils.isEmpty(this.allowedOrigins)) {
        return null;
    }
    PropertyMapper map = PropertyMapper.get();
    CorsConfiguration configuration = new CorsConfiguration();
    map.from(this::getAllowedOrigins).to(configuration::setAllowedOrigins);
    map.from(this::getAllowedHeaders).whenNot(CollectionUtils::isEmpty)
            .to(configuration::setAllowedHeaders);
    map.from(this::getAllowedMethods).whenNot(CollectionUtils::isEmpty)
            .to(configuration::setAllowedMethods);
    map.from(this::getExposedHeaders).whenNot(CollectionUtils::isEmpty)
            .to(configuration::setExposedHeaders);
    map.from(this::getMaxAge).whenNonNull().as(Duration::getSeconds)
            .to(configuration::setMaxAge);
    map.from(this::getAllowCredentials).whenNonNull()
            .to(configuration::setAllowCredentials);
    return configuration;
}
 
Example #4
Source File: GatewayAutoConfiguration.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Bean
public ReactorNettyRequestUpgradeStrategy reactorNettyRequestUpgradeStrategy(
		HttpClientProperties httpClientProperties) {
	ReactorNettyRequestUpgradeStrategy requestUpgradeStrategy = new ReactorNettyRequestUpgradeStrategy();

	HttpClientProperties.Websocket websocket = httpClientProperties
			.getWebsocket();
	PropertyMapper map = PropertyMapper.get();
	map.from(websocket::getMaxFramePayloadLength).whenNonNull()
			.to(requestUpgradeStrategy::setMaxFramePayloadLength);
	map.from(websocket::isProxyPing).to(requestUpgradeStrategy::setHandlePing);
	return requestUpgradeStrategy;
}
 
Example #5
Source File: LealoneServletWebServerFactoryCustomizer.java    From Lealone-Plugins with Apache License 2.0 5 votes vote down vote up
@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()::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);
}
 
Example #6
Source File: SslCustomizer.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
public SslCustomizer(AbstractConfigurableWebServerFactory factory) {
    this.factory = factory;
    this.propertyMapper = PropertyMapper.get();
}