software.amazon.awssdk.http.SdkHttpConfigurationOption Java Examples
The following examples show how to use
software.amazon.awssdk.http.SdkHttpConfigurationOption.
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 |
@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: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 #3
Source File: NettyNioAsyncHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 #4
Source File: UrlConnectionHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private HttpURLConnection createDefaultConnection(URI uri) { HttpURLConnection connection = invokeSafely(() -> (HttpURLConnection) uri.toURL().openConnection()); if (connection instanceof HttpsURLConnection) { HttpsURLConnection httpsConnection = (HttpsURLConnection) connection; if (options.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES)) { httpsConnection.setHostnameVerifier(NoOpHostNameVerifier.INSTANCE); } httpsConnection.setSSLSocketFactory(sslContext.getSocketFactory()); } connection.setConnectTimeout(saturatedCast(options.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).toMillis())); connection.setReadTimeout(saturatedCast(options.get(SdkHttpConfigurationOption.READ_TIMEOUT).toMillis())); return connection; }
Example #5
Source File: ConnectionReaperTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void oldConnectionReaperReapsActiveConnections() throws InterruptedException { Duration connectionTtl = Duration.ofMillis(200); try (SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder() .connectionTimeToLive(connectionTtl) .buildWithDefaults(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)) { Instant end = Instant.now().plus(Duration.ofSeconds(5)); verify(TRAFFIC_LISTENER, new Times(0)).closed(any()); // Send requests frequently, validating that connections are still being closed. while (Instant.now().isBefore(end)) { makeRequest(client); Thread.sleep(100); } verify(TRAFFIC_LISTENER, new AtLeast(20)).closed(any()); } }
Example #6
Source File: ConnectionReaperTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void idleConnectionReaperDoesNotReapActiveConnections() throws InterruptedException { Duration maxIdleTime = Duration.ofSeconds(2); try(SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder() .connectionMaxIdleTime(maxIdleTime) .buildWithDefaults(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)) { Instant end = Instant.now().plus(maxIdleTime.plusSeconds(1)); // Send requests for longer than the max-idle time, ensuring no connections are closed. while (Instant.now().isBefore(end)) { makeRequest(client); Thread.sleep(100); verify(TRAFFIC_LISTENER, new Times(0)).closed(any()); } // Do nothing for longer than the max-idle time, ensuring connections are closed. Thread.sleep(maxIdleTime.plusSeconds(1).toMillis()); verify(TRAFFIC_LISTENER, new AtLeast(1)).closed(any()); } }
Example #7
Source File: BaseClientBuilderClass.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
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 File: UrlConnectionHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * 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 #9
Source File: UrlConnectionHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #10
Source File: AwsModule.java From beam with Apache License 2.0 | 5 votes |
@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 #11
Source File: NettyNioAsyncHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public SdkAsyncHttpClient buildWithDefaults(AttributeMap serviceDefaults) { return new NettyNioAsyncHttpClient(this, standardOptions.build() .merge(serviceDefaults) .merge(NETTY_HTTP_DEFAULTS) .merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)); }
Example #12
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #13
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #14
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #15
Source File: AwsModule.java From beam with Apache License 2.0 | 5 votes |
@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 #16
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #17
Source File: HttpTestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public static SdkHttpClient testSdkHttpClient() { return new DefaultSdkHttpClientBuilder().buildWithDefaults( AttributeMap.empty().merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)); }
Example #18
Source File: HttpTestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public static SdkAsyncHttpClient testSdkAsyncHttpClient() { return new DefaultSdkAsyncHttpClientBuilder().buildWithDefaults( AttributeMap.empty().merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)); }
Example #19
Source File: HttpTestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public static SdkHttpClient testSdkHttpClient() { return new DefaultSdkHttpClientBuilder().buildWithDefaults( AttributeMap.empty().merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)); }
Example #20
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private HostnameVerifier getHostNameVerifier(AttributeMap standardOptions) { return standardOptions.get(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES) ? NoopHostnameVerifier.INSTANCE : SSLConnectionSocketFactory.getDefaultHostnameVerifier(); }
Example #21
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private boolean useIdleConnectionReaper(AttributeMap standardOptions) { return Boolean.TRUE.equals(standardOptions.get(SdkHttpConfigurationOption.REAP_IDLE_CONNECTIONS)); }
Example #22
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) { AttributeMap resolvedOptions = standardOptions.build().merge(serviceDefaults).merge( SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS); return new ApacheHttpClient(this, resolvedOptions); }
Example #23
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public Builder connectionMaxIdleTime(Duration maxIdleConnectionTimeout) { standardOptions.put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, maxIdleConnectionTimeout); return this; }
Example #24
Source File: ApacheHttpClient.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private ConnectionKeepAliveStrategy buildKeepAliveStrategy(AttributeMap standardOptions) { long maxIdle = standardOptions.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis(); return maxIdle > 0 ? new SdkConnectionKeepAliveStrategy(maxIdle) : null; }
Example #25
Source File: NettyNioAsyncHttpClientSpiVerificationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private static AttributeMap mapWithTrustAllCerts() { return AttributeMap.builder() .put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, true) .build(); }
Example #26
Source File: NettyNioAsyncHttpClientWireMockTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private static AttributeMap mapWithTrustAllCerts() { return AttributeMap.builder() .put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, true) .build(); }
Example #27
Source File: NettyConfiguration.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public TlsTrustManagersProvider tlsTrustManagersProvider() { return configuration.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER); }
Example #28
Source File: NettyConfiguration.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public TlsKeyManagersProvider tlsKeyManagersProvider() { return configuration.get(SdkHttpConfigurationOption.TLS_KEY_MANAGERS_PROVIDER); }
Example #29
Source File: NettyConfiguration.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public boolean reapIdleConnections() { return configuration.get(SdkHttpConfigurationOption.REAP_IDLE_CONNECTIONS); }
Example #30
Source File: NettyConfiguration.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
public int connectionTtlMillis() { return saturatedCast(configuration.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE).toMillis()); }