Java Code Examples for software.amazon.awssdk.utils.AttributeMap

The following examples show how to use software.amazon.awssdk.utils.AttributeMap. These examples are extracted from open source projects. 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 Project: aws-sdk-java-v2   Source File: NettyNioAsyncHttpClient.java    License: Apache License 2.0 6 votes vote down vote up
private NettyNioAsyncHttpClient(DefaultBuilder builder, AttributeMap serviceDefaultsMap) {
    this.configuration = new NettyConfiguration(serviceDefaultsMap);
    Protocol protocol = serviceDefaultsMap.get(SdkHttpConfigurationOption.PROTOCOL);
    this.sdkEventLoopGroup = eventLoopGroup(builder);

    Http2Configuration http2Configuration = builder.http2Configuration;

    long maxStreams = resolveMaxHttp2Streams(builder.maxHttp2Streams, http2Configuration);
    int initialWindowSize = resolveInitialWindowSize(http2Configuration);

    this.pools = AwaitCloseChannelPoolMap.builder()
                                         .sdkChannelOptions(builder.sdkChannelOptions)
                                         .configuration(configuration)
                                         .protocol(protocol)
                                         .maxStreams(maxStreams)
                                         .initialWindowSize(initialWindowSize)
                                         .healthCheckPingPeriod(resolveHealthCheckPingPeriod(http2Configuration))
                                         .sdkEventLoopGroup(sdkEventLoopGroup)
                                         .sslProvider(resolveSslProvider(builder))
                                         .proxyConfiguration(builder.proxyConfiguration)
                                         .build();
}
 
Example 2
@Test
public void usesProvidedKeyManagersProvider() {
    TlsKeyManagersProvider provider = mock(TlsKeyManagersProvider.class);

    AttributeMap config = AttributeMap.builder()
            .put(TLS_KEY_MANAGERS_PROVIDER, provider)
            .build();

    channelPoolMap = AwaitCloseChannelPoolMap.builder()
            .sdkChannelOptions(new SdkChannelOptions())
            .sdkEventLoopGroup(SdkEventLoopGroup.builder().build())
            .configuration(new NettyConfiguration(config.merge(GLOBAL_HTTP_DEFAULTS)))
            .build();

    ChannelPool channelPool = channelPoolMap.newPool(URI.create("https://localhost:" + mockProxy.port()));
    channelPool.acquire().awaitUninterruptibly();
    verify(provider).keyManagers();
}
 
Example 3
@Test
public void closeClient_shouldCloseUnderlyingResources() {
    SdkEventLoopGroup eventLoopGroup = SdkEventLoopGroup.builder().build();
    ChannelPool channelPool = mock(ChannelPool.class);
    SdkChannelPoolMap<URI, ChannelPool> sdkChannelPoolMap = new SdkChannelPoolMap<URI, ChannelPool>() {
        @Override
        protected ChannelPool newPool(URI key) {
            return channelPool;
        }
    };

    sdkChannelPoolMap.get(URI.create("http://blah"));
    NettyConfiguration nettyConfiguration = new NettyConfiguration(AttributeMap.empty());

    SdkAsyncHttpClient customerClient =
        new NettyNioAsyncHttpClient(eventLoopGroup, sdkChannelPoolMap, nettyConfiguration);

    customerClient.close();
    assertThat(eventLoopGroup.eventLoopGroup().isShuttingDown()).isTrue();
    assertThat(eventLoopGroup.eventLoopGroup().isTerminated()).isTrue();
    assertThat(sdkChannelPoolMap).isEmpty();
    Mockito.verify(channelPool).close();
}
 
Example 4
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 6 votes vote down vote up
public HttpClientConnectionManager create(ApacheHttpClient.DefaultBuilder configuration,
                                          AttributeMap standardOptions) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(configuration, standardOptions);

    PoolingHttpClientConnectionManager cm = new
            PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf),
            null,
            DefaultSchemePortResolver.INSTANCE,
            null,
            standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE).toMillis(),
            TimeUnit.MILLISECONDS);

    cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
    cm.setDefaultSocketConfig(buildSocketConfig(standardOptions));

    return cm;
}
 
Example 5
@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 6
@Test
public void routePlannerIsInvoked() throws Exception {
    mockProxyServer.resetToDefaultMappings();
    mockProxyServer.addStubMapping(WireMock.any(urlPathEqualTo("/"))
                                           .willReturn(aResponse().proxiedFrom("http://localhost:" + mockServer.port()))
                                           .build());

    SdkHttpClient client = ApacheHttpClient.builder()
                                           .httpRoutePlanner(
                                               (host, request, context) ->
                                                   new HttpRoute(
                                                       new HttpHost("localhost", mockProxyServer.httpsPort(), "https")
                                                   )
                                           )
                                           .buildWithDefaults(AttributeMap.builder()
                                                                          .put(TRUST_ALL_CERTIFICATES, Boolean.TRUE)
                                                                          .build());

    testForResponseCodeUsingHttps(client, HttpURLConnection.HTTP_OK);

    mockProxyServer.verify(1, RequestPatternBuilder.allRequests());
}
 
Example 7
Source Project: aws-sdk-java-v2   Source File: BaseClientBuilderClass.java    License: Apache License 2.0 6 votes vote down vote up
private CodeBlock serviceSpecificHttpConfigMethodBody(String serviceDefaultFqcn, boolean supportsH2) {
    CodeBlock.Builder builder =  CodeBlock.builder();

    if (serviceDefaultFqcn != null) {
        builder.addStatement("$T result = $T.defaultHttpConfig()",
                             AttributeMap.class,
                             PoetUtils.classNameFromFqcn(model.getCustomizationConfig().getServiceSpecificHttpConfig()));
    } else {
        builder.addStatement("$1T result = $1T.empty()", AttributeMap.class);
    }

    if (supportsH2) {
        builder.addStatement("return result.merge(AttributeMap.builder()"
                             + ".put($T.PROTOCOL, $T.HTTP2)"
                             + ".build())",
                             SdkHttpConfigurationOption.class, Protocol.class);
    } else {
        builder.addStatement("return result");
    }

    return builder.build();
}
 
Example 8
Source Project: beam   Source File: AwsModuleTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHttpClientConfigurationSerializationDeserialization() throws Exception {

  AttributeMap attributeMap =
      AttributeMap.builder()
          .put(SdkHttpConfigurationOption.CONNECTION_TIMEOUT, Duration.parse("PT100S"))
          .put(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE, Duration.parse("PT30S"))
          .put(SdkHttpConfigurationOption.MAX_CONNECTIONS, 15)
          .build();

  String valueAsJson = objectMapper.writeValueAsString(attributeMap);
  AttributeMap deserializedAttributeMap = objectMapper.readValue(valueAsJson, AttributeMap.class);

  assertEquals(
      Duration.parse("PT100S"),
      deserializedAttributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT));
  assertEquals(
      Duration.parse("PT30S"),
      deserializedAttributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE));
  assertEquals(
      (Integer) 15, deserializedAttributeMap.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
}
 
Example 9
Source Project: aws-sdk-java-v2   Source File: NettyNioAsyncHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
    return new NettyNioAsyncHttpClient(this, standardOptions.build()
                                                            .merge(serviceDefaults)
                                                            .merge(NETTY_HTTP_DEFAULTS)
                                                            .merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS));

}
 
Example 10
Source Project: aws-sdk-java-v2   Source File: ResponseCompletionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void connectionCloseAfterResponse_shouldNotReuseConnection() throws Exception {
    server = new Server();
    server.init();

    netty = NettyNioAsyncHttpClient.builder()
                                   .eventLoopGroup(SdkEventLoopGroup.builder().numberOfThreads(2).build())
                                   .protocol(Protocol.HTTP1_1)
                                   .buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());

    sendGetRequest().join();
    sendGetRequest().join();

    assertThat(server.channels.size()).isEqualTo(2);
}
 
Example 11
@Before
public void methodSetup() {
    httpOrHttp2ChannelPool = new HttpOrHttp2ChannelPool(mockDelegatePool,
                                                        eventLoopGroup,
                                                        4,
                                                        new NettyConfiguration(AttributeMap.builder()
                                                                .put(CONNECTION_ACQUIRE_TIMEOUT, Duration.ofSeconds(1))
                                                                .put(MAX_PENDING_CONNECTION_ACQUIRES, 5)
                                                                .build()));
}
 
Example 12
@Test(timeout = 5_000)
public void invalidProtocolConfig_shouldFailPromise() throws Exception {
    HttpOrHttp2ChannelPool invalidChannelPool = new HttpOrHttp2ChannelPool(mockDelegatePool,
                                                        eventLoopGroup,
                                                        4,
                                                        new NettyConfiguration(AttributeMap.builder()
                                                                                           .put(CONNECTION_ACQUIRE_TIMEOUT, Duration.ofSeconds(1))
                                                                                           .put(MAX_PENDING_CONNECTION_ACQUIRES, 0)
                                                                                           .build()));

    Promise<Channel> acquirePromise = eventLoopGroup.next().newPromise();
    when(mockDelegatePool.acquire()).thenReturn(acquirePromise);

    Thread.sleep(500);

    Channel channel = new MockChannel();
    eventLoopGroup.register(channel);

    channel.attr(PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP1_1));

    acquirePromise.setSuccess(channel);

    Future<Channel> p = invalidChannelPool.acquire();
    assertThat(p.await().cause().getMessage()).contains("maxPendingAcquires: 0 (expected: >= 1)");
    verify(mockDelegatePool).release(channel);
    assertThat(channel.isOpen()).isFalse();
}
 
Example 13
Source Project: aws-sdk-java-v2   Source File: NettyRequestExecutorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    mockChannelPool = mock(ChannelPool.class);

    eventLoopGroup = new NioEventLoopGroup();

    requestContext = new RequestContext(mockChannelPool,
                                        eventLoopGroup,
                                        AsyncExecuteRequest.builder().build(),
                                        new NettyConfiguration(AttributeMap.empty()));
    nettyRequestExecutor = new NettyRequestExecutor(requestContext);
}
 
Example 14
Source Project: aws-sdk-java-v2   Source File: H1ServerErrorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    server = new Server();
    server.init();

    netty = NettyNioAsyncHttpClient.builder()
                                   .eventLoopGroup(SdkEventLoopGroup.builder().numberOfThreads(2).build())
                                   .protocol(Protocol.HTTP1_1)
                                   .buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}
 
Example 15
Source Project: aws-sdk-java-v2   Source File: H2ServerErrorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    server = new Server();
    server.init();

    netty = NettyNioAsyncHttpClient.builder()
                                   .eventLoopGroup(SdkEventLoopGroup.builder().numberOfThreads(3).build())
                                   .protocol(Protocol.HTTP2)
                                   .buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}
 
Example 16
Source Project: aws-sdk-java-v2   Source File: ServerCloseConnectionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    server = new Server();
    server.init();

    netty = NettyNioAsyncHttpClient.builder()
                                   .readTimeout(Duration.ofMillis(500))
                                   .eventLoopGroup(SdkEventLoopGroup.builder().numberOfThreads(3).build())
                                   .protocol(Protocol.HTTP2)
                                   .buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}
 
Example 17
Source Project: aws-sdk-java-v2   Source File: ServerNotRespondingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    server = new Server();
    server.init();

    netty = NettyNioAsyncHttpClient.builder()
                                   .readTimeout(Duration.ofMillis(1000))
                                   .eventLoopGroup(SdkEventLoopGroup.builder().numberOfThreads(3).build())
                                   .http2Configuration(h -> h.healthCheckPingPeriod(Duration.ofMillis(200)))
                                   .protocol(Protocol.HTTP2)
                                   .buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
}
 
Example 18
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
@SdkTestInternalApi
ApacheHttpClient(ConnectionManagerAwareHttpClient httpClient,
                 ApacheHttpRequestConfig requestConfig,
                 AttributeMap resolvedOptions) {
    this.httpClient = httpClient;
    this.requestConfig = requestConfig;
    this.resolvedOptions = resolvedOptions;
}
 
Example 19
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private ConnectionManagerAwareHttpClient createClient(ApacheHttpClient.DefaultBuilder configuration,
                                                      AttributeMap standardOptions) {
    ApacheConnectionManagerFactory cmFactory = new ApacheConnectionManagerFactory();

    HttpClientBuilder builder = HttpClients.custom();
    // Note that it is important we register the original connection manager with the
    // IdleConnectionReaper as it's required for the successful deregistration of managers
    // from the reaper. See https://github.com/aws/aws-sdk-java/issues/722.
    HttpClientConnectionManager cm = cmFactory.create(configuration, standardOptions);

    builder.setRequestExecutor(new HttpRequestExecutor())
           // SDK handles decompression
           .disableContentCompression()
           .setKeepAliveStrategy(buildKeepAliveStrategy(standardOptions))
           .disableRedirectHandling()
           .disableAutomaticRetries()
           .setUserAgent("") // SDK will set the user agent header in the pipeline. Don't let Apache waste time
           .setConnectionManager(ClientConnectionManagerFactory.wrap(cm));

    addProxyConfig(builder, configuration);

    if (useIdleConnectionReaper(standardOptions)) {
        IdleConnectionReaper.getInstance().registerConnectionManager(
                cm, standardOptions.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis());
    }

    return new ApacheSdkHttpClient(builder.build(), cm);
}
 
Example 20
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private ApacheHttpRequestConfig createRequestConfig(DefaultBuilder builder,
                                                    AttributeMap resolvedOptions) {
    return ApacheHttpRequestConfig.builder()
                                  .socketTimeout(resolvedOptions.get(SdkHttpConfigurationOption.READ_TIMEOUT))
                                  .connectionTimeout(resolvedOptions.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT))
                                  .connectionAcquireTimeout(
                                      resolvedOptions.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT))
                                  .proxyConfiguration(builder.proxyConfiguration)
                                  .localAddress(Optional.ofNullable(builder.localAddress).orElse(null))
                                  .expectContinueEnabled(Optional.ofNullable(builder.expectContinueEnabled)
                                                                 .orElse(DefaultConfiguration.EXPECT_CONTINUE_ENABLED))
                                  .build();
}
 
Example 21
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private SSLContext getSslContext(AttributeMap standardOptions) {
    Validate.isTrue(standardOptions.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) == null ||
                    !standardOptions.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES),
                    "A TlsTrustManagerProvider can't be provided if TrustAllCertificates is also set");

    TrustManager[] trustManagers = null;
    if (standardOptions.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) != null) {
        trustManagers = standardOptions.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER).trustManagers();
    }

    if (standardOptions.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)) {
        log.warn(() -> "SSL Certificate verification is disabled. This is not a safe setting and should only be "
                       + "used for testing.");
        trustManagers = trustAllTrustManager();
    }

    TlsKeyManagersProvider provider = standardOptions.get(SdkHttpConfigurationOption.TLS_KEY_MANAGERS_PROVIDER);
    KeyManager[] keyManagers = provider.keyManagers();

    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html
        sslcontext.init(keyManagers, trustManagers, null);
        return sslcontext;
    } catch (final NoSuchAlgorithmException | KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}
 
Example 22
Source Project: aws-sdk-java-v2   Source File: ApacheHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private SocketConfig buildSocketConfig(AttributeMap standardOptions) {
    return SocketConfig.custom()
                       // TODO do we want to keep SO keep alive
                       .setSoKeepAlive(false)
                       .setSoTimeout(
                               saturatedCast(standardOptions.get(SdkHttpConfigurationOption.READ_TIMEOUT)
                                                            .toMillis()))
                       .setTcpNoDelay(true)
                       .build();
}
 
Example 23
@Test
public void closeClient_shouldCloseUnderlyingResources() {
    ApacheHttpClient client = new ApacheHttpClient(httpClient, ApacheHttpRequestConfig.builder().build(), AttributeMap.empty());
    when(httpClient.getHttpClientConnectionManager()).thenReturn(connectionManager);

    client.close();
    verify(connectionManager).shutdown();
}
 
Example 24
Source Project: aws-sdk-java-v2   Source File: UrlConnectionHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private UrlConnectionHttpClient(AttributeMap options, UrlConnectionFactory connectionFactory) {
    this.options = options;
    if (connectionFactory != null) {
        this.sslContext = null;
        this.connectionFactory = connectionFactory;
    } else {
        this.sslContext = getSslContext(options);
        this.connectionFactory = this::createDefaultConnection;
    }

}
 
Example 25
Source Project: aws-sdk-java-v2   Source File: UrlConnectionHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
private SSLContext getSslContext(AttributeMap options) {
    Validate.isTrue(options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) == null ||
                    !options.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES),
                    "A TlsTrustManagerProvider can't be provided if TrustAllCertificates is also set");

    TrustManager[] trustManagers = null;
    if (options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER) != null) {
        trustManagers = options.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER).trustManagers();
    }

    if (options.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)) {
        log.warn(() -> "SSL Certificate verification is disabled. This is not a safe setting and should only be "
                       + "used for testing.");
        trustManagers = new TrustManager[] { TrustAllManager.INSTANCE };
    }

    TlsKeyManagersProvider provider = this.options.get(SdkHttpConfigurationOption.TLS_KEY_MANAGERS_PROVIDER);
    KeyManager[] keyManagers = provider.keyManagers();

    SSLContext context;
    try {
        context = SSLContext.getInstance("TLS");
        context.init(keyManagers, trustManagers, null);
        return context;
    } catch (NoSuchAlgorithmException | KeyManagementException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
 
Example 26
Source Project: aws-sdk-java-v2   Source File: UrlConnectionHttpClient.java    License: 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 27
@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 28
Source Project: aws-sdk-java-v2   Source File: BaseClientBuilderClass.java    License: Apache License 2.0 5 votes vote down vote up
private MethodSpec serviceSpecificHttpConfigMethod(String serviceDefaultFqcn, boolean supportsH2) {
    return MethodSpec.methodBuilder("serviceHttpConfig")
                     .addAnnotation(Override.class)
                     .addModifiers(PROTECTED, FINAL)
                     .returns(AttributeMap.class)
                     .addCode(serviceSpecificHttpConfigMethodBody(serviceDefaultFqcn, supportsH2))
                     .build();
}
 
Example 29
@Override
public SdkAsyncHttpClient 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(SdkAsyncHttpService::createAsyncHttpClientFactory)
            .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 30
@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());
}