Search in sources :

Example 1 with AwsClientBuilder

use of software.amazon.awssdk.awscore.client.builder.AwsClientBuilder in project cas by apereo.

the class AmazonClientConfigurationBuilder method prepareClientBuilder.

/**
 * Build client configuration.
 *
 * @param builder             the builder
 * @param credentialsProvider the credentials provider
 * @param props               the props
 * @return the aws sync client builder
 */
@SneakyThrows
public static AwsSyncClientBuilder prepareClientBuilder(final AwsSyncClientBuilder builder, final AwsCredentialsProvider credentialsProvider, final BaseAmazonWebServicesProperties props) {
    val proxyConfig = ProxyConfiguration.builder();
    if (StringUtils.isNotBlank(props.getProxyHost())) {
        proxyConfig.endpoint(new URI(props.getProxyHost())).password(props.getProxyPassword()).username(props.getProxyUsername());
    }
    val httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
    httpClientBuilder.useIdleConnectionReaper(props.isUseReaper()).socketTimeout(Beans.newDuration(props.getSocketTimeout())).maxConnections(props.getMaxConnections()).connectionTimeout(Beans.newDuration(props.getConnectionTimeout())).connectionAcquisitionTimeout(Beans.newDuration(props.getClientExecutionTimeout()));
    if (StringUtils.isNotBlank(props.getLocalAddress())) {
        LOGGER.trace("Creating DynamoDb client local address [{}]", props.getLocalAddress());
        httpClientBuilder.localAddress(InetAddress.getByName(props.getLocalAddress()));
    }
    val clientBuilder = builder.httpClientBuilder(httpClientBuilder);
    if (clientBuilder instanceof AwsClientBuilder) {
        val overrideConfig = ClientOverrideConfiguration.builder().retryPolicy(RetryMode.valueOf(props.getRetryMode())).build();
        val awsClientBuilder = (AwsClientBuilder) clientBuilder;
        awsClientBuilder.overrideConfiguration(overrideConfig);
        awsClientBuilder.credentialsProvider(credentialsProvider);
        val region = props.getRegion();
        awsClientBuilder.region(StringUtils.isBlank(region) ? Region.AWS_GLOBAL : Region.of(region));
        val endpoint = props.getEndpoint();
        if (StringUtils.isNotBlank(endpoint)) {
            awsClientBuilder.endpointOverride(new URI(endpoint));
        }
    }
    return builder;
}
Also used : lombok.val(lombok.val) AwsClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsClientBuilder) URI(java.net.URI) SneakyThrows(lombok.SneakyThrows)

Aggregations

URI (java.net.URI)1 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 AwsClientBuilder (software.amazon.awssdk.awscore.client.builder.AwsClientBuilder)1