software.amazon.awssdk.utils.AttributeMap Java Examples

The following examples show how to use software.amazon.awssdk.utils.AttributeMap. 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: AwsModuleTest.java    From beam with 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 #2
Source File: BaseClientBuilderClass.java    From aws-sdk-java-v2 with 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 #3
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #4
Source File: ServerCloseConnectionTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 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 #5
Source File: NettyNioAsyncHttpClientWireMockTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: AwaitCloseChannelPoolMapTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: NettyNioAsyncHttpClient.java    From aws-sdk-java-v2 with 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 #8
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 #9
Source File: ServerNotRespondingTest.java    From aws-sdk-java-v2 with 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 #10
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 #11
Source File: UrlConnectionHttpClient.java    From aws-sdk-java-v2 with 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 #12
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 #13
Source File: BaseClientBuilderClass.java    From aws-sdk-java-v2 with 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 #14
Source File: ResponseCompletionTest.java    From aws-sdk-java-v2 with 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 #15
Source File: HttpOrHttp2ChannelPoolTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: HttpOrHttp2ChannelPoolTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: UrlConnectionHttpClient.java    From aws-sdk-java-v2 with 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 #18
Source File: H1ServerErrorTest.java    From aws-sdk-java-v2 with 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 #19
Source File: NettyNioAsyncHttpClient.java    From aws-sdk-java-v2 with 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 #20
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #21
Source File: AwsModule.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AttributeMap deserialize(JsonParser jsonParser, DeserializationContext context)
    throws IOException {
  Map<String, String> map = jsonParser.readValueAs(new TypeReference<Map<String, String>>() {});

  // Add new attributes below.
  final AttributeMap.Builder attributeMapBuilder = AttributeMap.builder();
  if (map.containsKey(CONNECTION_ACQUIRE_TIMEOUT)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT,
        Duration.parse(map.get(CONNECTION_ACQUIRE_TIMEOUT)));
  }
  if (map.containsKey(CONNECTION_MAX_IDLE_TIMEOUT)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT,
        Duration.parse(map.get(CONNECTION_MAX_IDLE_TIMEOUT)));
  }
  if (map.containsKey(CONNECTION_TIMEOUT)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.CONNECTION_TIMEOUT,
        Duration.parse(map.get(CONNECTION_TIMEOUT)));
  }
  if (map.containsKey(CONNECTION_TIME_TO_LIVE)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE,
        Duration.parse(map.get(CONNECTION_TIME_TO_LIVE)));
  }
  if (map.containsKey(MAX_CONNECTIONS)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.MAX_CONNECTIONS, Integer.parseInt(map.get(MAX_CONNECTIONS)));
  }
  if (map.containsKey(READ_TIMEOUT)) {
    attributeMapBuilder.put(
        SdkHttpConfigurationOption.READ_TIMEOUT, Duration.parse(map.get(READ_TIMEOUT)));
  }
  return attributeMapBuilder.build();
}
 
Example #22
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #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: DefaultSdkAsyncHttpClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #26
Source File: ApacheHttpClientWireMockTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: AwsModule.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(
    AttributeMap attributeMap, JsonGenerator jsonGenerator, SerializerProvider serializer)
    throws IOException {

  jsonGenerator.writeStartObject();
  if (attributeMap.containsKey(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT)) {
    jsonGenerator.writeStringField(
        CONNECTION_ACQUIRE_TIMEOUT,
        String.valueOf(
            attributeMap.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT)));
  }
  if (attributeMap.containsKey(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT)) {
    jsonGenerator.writeStringField(
        CONNECTION_MAX_IDLE_TIMEOUT,
        String.valueOf(
            attributeMap.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT)));
  }
  if (attributeMap.containsKey(SdkHttpConfigurationOption.CONNECTION_TIMEOUT)) {
    jsonGenerator.writeStringField(
        CONNECTION_TIMEOUT,
        String.valueOf(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT)));
  }
  if (attributeMap.containsKey(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE)) {
    jsonGenerator.writeStringField(
        CONNECTION_TIME_TO_LIVE,
        String.valueOf(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE)));
  }
  if (attributeMap.containsKey(SdkHttpConfigurationOption.MAX_CONNECTIONS)) {
    jsonGenerator.writeStringField(
        MAX_CONNECTIONS,
        String.valueOf(attributeMap.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)));
  }
  if (attributeMap.containsKey(SdkHttpConfigurationOption.READ_TIMEOUT)) {
    jsonGenerator.writeStringField(
        READ_TIMEOUT,
        String.valueOf(attributeMap.get(SdkHttpConfigurationOption.READ_TIMEOUT)));
  }
  jsonGenerator.writeEndObject();
}
 
Example #28
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #29
Source File: ApacheHttpClient.java    From aws-sdk-java-v2 with 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 #30
Source File: H2ServerErrorTest.java    From aws-sdk-java-v2 with 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());
}