software.amazon.awssdk.http.SdkHttpClient Java Examples

The following examples show how to use software.amazon.awssdk.http.SdkHttpClient. 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: SignersIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 7 votes vote down vote up
@Test
public void sign_WithoutUsingSdkClient_ThroughExecutionAttributes() throws Exception {
    Aws4Signer signer = Aws4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicRequest();

    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructExecutionAttributes());

    SdkHttpClient httpClient = ApacheHttpClient.builder().build();

    HttpExecuteRequest request = HttpExecuteRequest.builder()
                                                   .request(signedRequest)
                                                   .contentStreamProvider(signedRequest.contentStreamProvider().orElse(null))
                                                   .build();

    HttpExecuteResponse response = httpClient.prepareRequest(request)
                                             .call();

    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());

    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(getExpectedResult(), actualResult);
}
 
Example #2
Source File: AbstractAmazonServiceProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
protected void createClientBuilders(List<AmazonClientTransportsBuildItem> clients,
        BuildProducer<AmazonClientBuilderBuildItem> builderProducer,
        Function<RuntimeValue<SdkHttpClient.Builder>, RuntimeValue<AwsClientBuilder>> syncFunc,
        Function<RuntimeValue<SdkAsyncHttpClient.Builder>, RuntimeValue<AwsClientBuilder>> asyncFunc) {

    for (AmazonClientTransportsBuildItem client : clients) {
        if (configName().equals(client.getAwsClientName())) {
            RuntimeValue<AwsClientBuilder> syncBuilder = null;
            RuntimeValue<AwsClientBuilder> asyncBuilder = null;
            if (client.getSyncClassName().isPresent()) {
                syncBuilder = syncFunc.apply(client.getSyncTransport());
            }
            if (client.getAsyncClassName().isPresent()) {
                asyncBuilder = asyncFunc.apply(client.getAsyncTransport());
            }
            builderProducer.produce(new AmazonClientBuilderBuildItem(client.getAwsClientName(), syncBuilder, asyncBuilder));
        }
    }
}
 
Example #3
Source File: SignersIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_SignMethod_WithModeledParam_And_WithoutUsingSdkClient() throws Exception {
    Aws4Signer signer = Aws4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicRequest();

    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructSignerParams());

    SdkHttpClient httpClient = ApacheHttpClient.builder().build();

    HttpExecuteRequest request = HttpExecuteRequest.builder()
                                                   .request(signedRequest)
                                                   .contentStreamProvider(signedRequest.contentStreamProvider().orElse(null))
                                                   .build();
    HttpExecuteResponse response = httpClient.prepareRequest(request)
                                             .call();

    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());

    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(getExpectedResult(), actualResult);
}
 
Example #4
Source File: AwsS3V4SignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_SignMethod_WithModeledParam_And_WithoutUsingSdkClient() throws Exception {
    AwsS3V4Signer signer = AwsS3V4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicGetRequest();

    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructSignerParams());

    SdkHttpClient httpClient = ApacheHttpClient.builder().build();

    HttpExecuteResponse response = httpClient.prepareRequest(HttpExecuteRequest.builder().request(signedRequest).build())
                                             .call();

    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());

    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(CONTENT, actualResult);
}
 
Example #5
Source File: AwsS3V4SignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_SignMethod_WithExecutionAttributes_And_WithoutUsingSdkClient() throws Exception {
    AwsS3V4Signer signer = AwsS3V4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicGetRequest();

    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructExecutionAttributes());

    SdkHttpClient httpClient = ApacheHttpClient.builder().build();

    HttpExecuteResponse response = httpClient.prepareRequest(HttpExecuteRequest.builder().request(signedRequest).build())
                                             .call();

    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());

    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(CONTENT, actualResult);
}
 
Example #6
Source File: ApacheHttpClientWireMockTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
protected SdkHttpClient createSdkHttpClient(SdkHttpClientOptions options) {
    ApacheHttpClient.Builder builder = ApacheHttpClient.builder();

    AttributeMap.Builder attributeMap = AttributeMap.builder();

    if (options.tlsTrustManagersProvider() != null) {
        builder.tlsTrustManagersProvider(options.tlsTrustManagersProvider());
    }

    if (options.trustAll()) {
        attributeMap.put(TRUST_ALL_CERTIFICATES, options.trustAll());
    }

    return builder.buildWithDefaults(attributeMap.build());
}
 
Example #7
Source File: S3PresignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private HttpExecuteResponse execute(PresignedRequest presigned, String payload) throws IOException {
    SdkHttpClient httpClient = ApacheHttpClient.builder().build();

    ContentStreamProvider requestPayload = payload == null ? null : () -> new StringInputStream(payload);

    HttpExecuteRequest request = HttpExecuteRequest.builder()
                                                   .request(presigned.httpRequest())
                                                   .contentStreamProvider(requestPayload)
                                                   .build();

    return httpClient.prepareRequest(request).call();
}
 
Example #8
Source File: ServiceHandlerWrapper.java    From cloudformation-cli-java-plugin with Apache License 2.0 5 votes vote down vote up
public ServiceHandlerWrapper(final CredentialsProvider providerLoggingCredentialsProvider,
                             final CloudWatchLogPublisher providerEventsLogger,
                             final LogPublisher platformEventsLogger,
                             final MetricsPublisher providerMetricsPublisher,
                             final SchemaValidator validator,
                             final Serializer serializer,
                             final ServiceClient client,
                             final SdkHttpClient httpClient) {
    super(providerLoggingCredentialsProvider, platformEventsLogger, providerEventsLogger, providerMetricsPublisher, validator,
          serializer, httpClient);
    this.serviceClient = client;
}
 
Example #9
Source File: ApacheClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * @param configuration The Apache client configuration
 * @return An instance of {@link SdkHttpClient}
 */
@Bean(preDestroy = "close")
@Singleton
@Requires(property = UrlConnectionClientFactory.HTTP_SERVICE_IMPL, value = APACHE_SDK_HTTP_SERVICE)
public SdkHttpClient systemPropertyClient(ApacheClientConfiguration configuration) {
    return doCreateClient(configuration);
}
 
Example #10
Source File: ApacheClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * @param configuration The Apache client configuration
 * @return An instance of {@link SdkHttpClient}
 */
@Bean(preDestroy = "close")
@Singleton
@Requires(property = UrlConnectionClientFactory.HTTP_SERVICE_IMPL, notEquals = UrlConnectionClientFactory.URL_CONNECTION_SDK_HTTP_SERVICE)
public SdkHttpClient apacheClient(ApacheClientConfiguration configuration) {
    return doCreateClient(configuration);
}
 
Example #11
Source File: LambdaWrapper.java    From cloudformation-cli-java-plugin with Apache License 2.0 5 votes vote down vote up
public LambdaWrapper(final CredentialsProvider providerCredentialsProvider,
                     final LogPublisher platformEventsLogger,
                     final CloudWatchLogPublisher providerEventsLogger,
                     final MetricsPublisher providerMetricsPublisher,
                     final SchemaValidator validator,
                     final Serializer serializer,
                     final SdkHttpClient httpClient) {

    this.providerCredentialsProvider = providerCredentialsProvider;
    this.providerCloudWatchProvider = new CloudWatchProvider(this.providerCredentialsProvider, httpClient);
    this.cloudWatchLogsProvider = new CloudWatchLogsProvider(this.providerCredentialsProvider, httpClient);
    this.providerEventsLogger = providerEventsLogger;
    this.platformLambdaLogger = platformEventsLogger;
    this.providerMetricsPublisher = providerMetricsPublisher;
    this.serializer = serializer;
    this.validator = validator;
    this.typeReference = getTypeReference();
}
 
Example #12
Source File: DynamodbRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createSyncBuilder(DynamodbConfig config,
        RuntimeValue<SdkHttpClient.Builder> transport) {
    DynamoDbClientBuilder builder = DynamoDbClient.builder();
    builder.endpointDiscoveryEnabled(config.enableEndpointDiscovery);

    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #13
Source File: AbstractAmazonServiceProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void createTransportBuilders(List<AmazonClientBuildItem> amazonClients,
        AmazonClientTransportRecorder recorder,
        SyncHttpClientBuildTimeConfig buildSyncConfig,
        RuntimeValue<SyncHttpClientConfig> syncConfig,
        RuntimeValue<NettyHttpClientConfig> asyncConfig,
        BuildProducer<AmazonClientTransportsBuildItem> clientTransports) {

    Optional<AmazonClientBuildItem> matchingClientBuildItem = amazonClients.stream()
            .filter(c -> c.getAwsClientName().equals(configName()))
            .findAny();

    matchingClientBuildItem.ifPresent(client -> {
        RuntimeValue<SdkHttpClient.Builder> syncTransport = null;
        RuntimeValue<SdkAsyncHttpClient.Builder> asyncTransport = null;

        if (client.getSyncClassName().isPresent()) {
            syncTransport = recorder.configureSync(configName(), buildSyncConfig,
                    syncConfig);
        }

        if (client.getAsyncClassName().isPresent()) {
            asyncTransport = recorder.configureAsync(configName(), asyncConfig);
        }

        clientTransports.produce(
                new AmazonClientTransportsBuildItem(
                        client.getSyncClassName(), client.getAsyncClassName(),
                        syncTransport,
                        asyncTransport,
                        client.getAwsClientName()));
    });

}
 
Example #14
Source File: TracingInterceptorTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
private SdkHttpClient mockSdkHttpClient(SdkHttpResponse response, String body) throws Exception {
    ExecutableHttpRequest abortableCallable = Mockito.mock(ExecutableHttpRequest.class);
    SdkHttpClient mockClient = Mockito.mock(SdkHttpClient.class);

    Mockito.when(mockClient.prepareRequest(Mockito.any())).thenReturn(abortableCallable);
    Mockito.when(abortableCallable.call()).thenReturn(HttpExecuteResponse.builder()
            .response(response)
            .responseBody(AbortableInputStream.create(
                    new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))
            ))
            .build()
    );
    return mockClient;
}
 
Example #15
Source File: S3PresignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void getObject_PresignedHttpRequestCanBeInvokedDirectlyBySdk() throws IOException {
    PresignedGetObjectRequest presigned =
        presigner.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(5))
                                         .getObjectRequest(gor -> gor.bucket(testBucket)
                                                                     .key(testGetObjectKey)
                                                                     .requestPayer(RequestPayer.REQUESTER)));

    assertThat(presigned.isBrowserExecutable()).isFalse();

    SdkHttpClient httpClient = ApacheHttpClient.builder().build(); // or UrlConnectionHttpClient.builder().build()

    ContentStreamProvider requestPayload = presigned.signedPayload()
                                                    .map(SdkBytes::asContentStreamProvider)
                                                    .orElse(null);

    HttpExecuteRequest request = HttpExecuteRequest.builder()
                                                   .request(presigned.httpRequest())
                                                   .contentStreamProvider(requestPayload)
                                                   .build();

    HttpExecuteResponse response = httpClient.prepareRequest(request).call();

    assertThat(response.responseBody()).isPresent();
    try (InputStream responseStream = response.responseBody().get()) {
        assertThat(IoUtils.toUtf8String(responseStream)).isEqualTo(testObjectContent);
    }
}
 
Example #16
Source File: S3PresignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void putObject_PresignedHttpRequestCanBeInvokedDirectlyBySdk() throws IOException {
    String objectKey = generateRandomObjectKey();
    S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class,
                               () -> client.deleteObject(r -> r.bucket(testBucket).key(objectKey)));

    PresignedPutObjectRequest presigned =
        presigner.presignPutObject(r -> r.signatureDuration(Duration.ofMinutes(5))
                                         .putObjectRequest(por -> por.bucket(testBucket).key(objectKey)));

    assertThat(presigned.isBrowserExecutable()).isFalse();

    SdkHttpClient httpClient = ApacheHttpClient.builder().build(); // or UrlConnectionHttpClient.builder().build()

    ContentStreamProvider requestPayload = () -> new StringInputStream(testObjectContent);

    HttpExecuteRequest request = HttpExecuteRequest.builder()
                                                   .request(presigned.httpRequest())
                                                   .contentStreamProvider(requestPayload)
                                                   .build();

    HttpExecuteResponse response = httpClient.prepareRequest(request).call();

    assertThat(response.responseBody()).isPresent();
    assertThat(response.httpResponse().isSuccessful()).isTrue();
    response.responseBody().ifPresent(AbortableInputStream::abort);
    String content = client.getObjectAsBytes(r -> r.bucket(testBucket).key(objectKey)).asUtf8String();
    assertThat(content).isEqualTo(testObjectContent);
}
 
Example #17
Source File: ITTracingExecutionInterceptor.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
SdkHttpClient primeHttpClient() throws IOException {
  server.enqueue(new MockResponse());
  SdkHttpClient httpClient = UrlConnectionHttpClient.builder().build();
  try {
    httpClient.prepareRequest(HttpExecuteRequest.builder()
        .request(SdkHttpRequest.builder()
            .method(SdkHttpMethod.GET)
            .uri(server.url("/").uri())
            .build())
        .build()).call();
  } finally {
    takeRequest();
  }
  return httpClient;
}
 
Example #18
Source File: ApacheClientTlsAuthTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private HttpExecuteResponse makeRequestWithHttpClient(SdkHttpClient httpClient) throws IOException {
    SdkHttpRequest httpRequest = SdkHttpFullRequest.builder()
            .method(SdkHttpMethod.GET)
            .protocol("https")
            .host("localhost:" + wireMockServer.httpsPort())
            .build();

    HttpExecuteRequest request = HttpExecuteRequest.builder()
            .request(httpRequest)
            .build();

    return httpClient.prepareRequest(request).call();
}
 
Example #19
Source File: UrlConnectionHttpClient.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Used by the SDK to create a {@link SdkHttpClient} with service-default values if no other values have been configured
 *
 * @param serviceDefaults Service specific defaults. Keys will be one of the constants defined in
 * {@link SdkHttpConfigurationOption}.
 * @return an instance of {@link SdkHttpClient}
 */
@Override
public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
    return new UrlConnectionHttpClient(standardOptions.build()
                                                      .merge(serviceDefaults)
                                                      .merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS),
                                       null);
}
 
Example #20
Source File: UrlConnectionHttpClientWireMockTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected SdkHttpClient createSdkHttpClient(SdkHttpClientOptions options) {
    UrlConnectionHttpClient.Builder builder = UrlConnectionHttpClient.builder();
    AttributeMap.Builder attributeMap = AttributeMap.builder();

    if (options.tlsTrustManagersProvider() != null) {
        builder.tlsTrustManagersProvider(options.tlsTrustManagersProvider());
    }

    if (options.trustAll()) {
        attributeMap.put(TRUST_ALL_CERTIFICATES, options.trustAll());
    }

    return builder.buildWithDefaults(attributeMap.build());
}
 
Example #21
Source File: ResourceManagementTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void httpClientFromBuilderShutdown() {
    SdkHttpClient httpClient = mock(SdkHttpClient.class);
    SdkHttpClient.Builder httpClientBuilder = mock(SdkHttpClient.Builder.class);

    when(httpClientBuilder.buildWithDefaults(any())).thenReturn(httpClient);

    syncClientBuilder().httpClientBuilder(httpClientBuilder).build().close();
    verify(httpClient).close();
}
 
Example #22
Source File: SdkDefaultClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Finalize which sync HTTP client will be used for the created client.
 */
private SdkHttpClient resolveSyncHttpClient(SdkClientConfiguration config) {
    Validate.isTrue(config.option(SdkClientOption.SYNC_HTTP_CLIENT) == null || httpClientBuilder == null,
                    "The httpClient and the httpClientBuilder can't both be configured.");

    return Either.fromNullable(config.option(SdkClientOption.SYNC_HTTP_CLIENT), httpClientBuilder)
                 .map(e -> e.map(NonManagedSdkHttpClient::new, b -> b.buildWithDefaults(childHttpConfig())))
                 .orElseGet(() -> defaultHttpClientBuilder.buildWithDefaults(childHttpConfig()));
}
 
Example #23
Source File: DefaultSdkHttpClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
    // TODO We create and build every time. Do we want to cache it instead of the service binding?
    return DEFAULT_CHAIN
            .loadService()
            .map(SdkHttpService::createHttpClientBuilder)
            .map(f -> f.buildWithDefaults(serviceDefaults))
            .orElseThrow(
                () -> SdkClientException.builder()
                                        .message("Unable to load an HTTP implementation from any provider in the " +
                                                 "chain. You must declare a dependency on an appropriate HTTP " +
                                                 "implementation or pass in an SdkHttpClient explicitly to the " +
                                                 "client builder.")
                                        .build());
}
 
Example #24
Source File: HttpTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public AmazonSyncHttpClient build() {
    SdkHttpClient sdkHttpClient = this.httpClient != null ? this.httpClient : testSdkHttpClient();
    return new AmazonSyncHttpClient(testClientConfiguration().toBuilder()
                                                             .option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient)
                                                             .applyMutation(this::configureRetryPolicy)
                                                             .applyMutation(this::configureAdditionalHeaders)
                                                             .option(SdkClientOption.API_CALL_TIMEOUT, apiCallTimeout)
                                                             .option(SdkClientOption.API_CALL_ATTEMPT_TIMEOUT, apiCallAttemptTimeout)
                                                             .build());
}
 
Example #25
Source File: DefaultClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void clientFactoryProvided_ClientIsManagedBySdk() {
    TestClient client = testClientBuilder().httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
        Assertions.assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
        return mock(SdkHttpClient.class);
    })
            .build();
    assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
            .isNotInstanceOf(SdkDefaultClientBuilder.NonManagedSdkHttpClient.class);
    verify(defaultHttpClientFactory, never()).buildWithDefaults(any());
}
 
Example #26
Source File: DefaultClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void explicitClientProvided_ClientIsNotManagedBySdk() {
    TestClient client = testClientBuilder()

            .httpClient(mock(SdkHttpClient.class))
            .build();
    assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
            .isInstanceOf(SdkDefaultClientBuilder.NonManagedSdkHttpClient.class);
    verify(defaultHttpClientFactory, never()).buildWithDefaults(any());
}
 
Example #27
Source File: HttpTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public AmazonSyncHttpClient build() {
    SdkHttpClient sdkHttpClient = this.httpClient != null ? this.httpClient : testSdkHttpClient();
    return new AmazonSyncHttpClient(testClientConfiguration().toBuilder()
                                                             .option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient)
                                                             .applyMutation(this::configureRetryPolicy)
                                                             .build());
}
 
Example #28
Source File: DefaultAwsClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void clientFactoryProvided_ClientIsManagedBySdk() {
    TestClient client = testClientBuilder()
        .region(Region.US_WEST_2)
        .httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
            assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
            return mock(SdkHttpClient.class);
        })
        .build();
    assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
        .isNotInstanceOf(AwsDefaultClientBuilder.NonManagedSdkHttpClient.class);
    verify(defaultHttpClientBuilder, never()).buildWithDefaults(any());
}
 
Example #29
Source File: DefaultAwsClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void explicitClientProvided_ClientIsNotManagedBySdk() {
    TestClient client = testClientBuilder()
        .region(Region.US_WEST_2)
        .httpClient(mock(SdkHttpClient.class))
        .build();
    assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
        .isInstanceOf(AwsDefaultClientBuilder.NonManagedSdkHttpClient.class);
    verify(defaultHttpClientBuilder, never()).buildWithDefaults(any());
}
 
Example #30
Source File: STSCredentialProviderV2.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static SdkHttpClient.Builder initConnectionSettings(Configuration conf) {
  final ApacheHttpClient.Builder httpBuilder = ApacheHttpClient.builder();
  httpBuilder.maxConnections(intOption(conf, Constants.MAXIMUM_CONNECTIONS, Constants.DEFAULT_MAXIMUM_CONNECTIONS, 1));
  httpBuilder.connectionTimeout(
    Duration.ofSeconds(intOption(conf, Constants.ESTABLISH_TIMEOUT, Constants.DEFAULT_ESTABLISH_TIMEOUT, 0)));
  httpBuilder.socketTimeout(
    Duration.ofSeconds(intOption(conf, Constants.SOCKET_TIMEOUT, Constants.DEFAULT_SOCKET_TIMEOUT, 0)));
  httpBuilder.proxyConfiguration(initProxySupport(conf));

  return httpBuilder;
}