|
44 | 44 | import org.apache.hc.client5.http.auth.AuthSchemeFactory;
|
45 | 45 | import org.apache.hc.client5.http.auth.CredentialsProvider;
|
46 | 46 | import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
|
| 47 | +import org.apache.hc.client5.http.config.ConnectionConfig; |
47 | 48 | import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
|
48 | 49 | import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
49 | 50 | import org.apache.hc.client5.http.impl.classic.HttpClients;
|
|
71 | 72 | import org.apache.hc.core5.pool.PoolStats;
|
72 | 73 | import org.apache.hc.core5.ssl.SSLInitializationException;
|
73 | 74 | import org.apache.hc.core5.util.TimeValue;
|
| 75 | +import org.apache.hc.core5.util.Timeout; |
74 | 76 | import software.amazon.awssdk.annotations.SdkPreviewApi;
|
75 | 77 | import software.amazon.awssdk.annotations.SdkPublicApi;
|
76 | 78 | import software.amazon.awssdk.annotations.SdkTestInternalApi;
|
|
88 | 90 | import software.amazon.awssdk.http.apache5.internal.DefaultConfiguration;
|
89 | 91 | import software.amazon.awssdk.http.apache5.internal.SdkProxyRoutePlanner;
|
90 | 92 | import software.amazon.awssdk.http.apache5.internal.conn.ClientConnectionManagerFactory;
|
91 |
| -import software.amazon.awssdk.http.apache5.internal.conn.ConnectionSocketFactoryToTlsStrategyAdapter; |
92 | 93 | import software.amazon.awssdk.http.apache5.internal.conn.IdleConnectionReaper;
|
93 | 94 | import software.amazon.awssdk.http.apache5.internal.conn.SdkConnectionKeepAliveStrategy;
|
94 | 95 | import software.amazon.awssdk.http.apache5.internal.conn.SdkTlsSocketFactory;
|
@@ -345,7 +346,6 @@ private Apache5HttpRequestConfig createRequestConfig(DefaultBuilder builder,
|
345 | 346 | AttributeMap resolvedOptions) {
|
346 | 347 | return Apache5HttpRequestConfig.builder()
|
347 | 348 | .socketTimeout(resolvedOptions.get(SdkHttpConfigurationOption.READ_TIMEOUT))
|
348 |
| - .connectionTimeout(resolvedOptions.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT)) |
349 | 349 | .connectionAcquireTimeout(
|
350 | 350 | resolvedOptions.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT))
|
351 | 351 | .proxyConfiguration(builder.proxyConfiguration)
|
@@ -453,27 +453,15 @@ public interface Builder extends SdkHttpClient.Builder<Apache5HttpClient.Builder
|
453 | 453 | */
|
454 | 454 | Builder dnsResolver(DnsResolver dnsResolver);
|
455 | 455 |
|
456 |
| - /** |
457 |
| - * @deprecated this has been replaced with {@link #tlsSocketStrategy(TlsSocketStrategy)}. |
458 |
| - * This method is retained for backwards compatibility to ease migration from Apache HttpClient 4.5.x. |
459 |
| - * Configuration that defines a custom Socket factory. If set to a null value, a default factory is used. |
460 |
| - * <p> |
461 |
| - * When set to a non-null value, the use of a custom factory implies the configuration options TRUST_ALL_CERTIFICATES, |
462 |
| - * TLS_TRUST_MANAGERS_PROVIDER, and TLS_KEY_MANAGERS_PROVIDER are ignored. |
463 |
| - */ |
464 |
| - @Deprecated |
465 |
| - Builder socketFactory(ConnectionSocketFactory socketFactory); |
466 |
| - |
467 | 456 | /**
|
468 | 457 | * Configure a custom TLS strategy for SSL/TLS connections.
|
469 |
| - * This is the preferred method over the deprecated {@link #socketFactory(ConnectionSocketFactory)}. |
| 458 | + * This is the preferred method over the {@link ConnectionSocketFactory)}. |
470 | 459 | *
|
471 | 460 | * @param tlsSocketStrategy The TLS strategy to use for upgrading connections to TLS.
|
472 | 461 | * If null, default TLS configuration will be used.
|
473 | 462 | * @return This builder for method chaining
|
474 | 463 |
|
475 | 464 | */
|
476 |
| - |
477 | 465 | Builder tlsSocketStrategy(TlsSocketStrategy tlsSocketStrategy);
|
478 | 466 |
|
479 | 467 | /**
|
@@ -532,7 +520,6 @@ private static final class DefaultBuilder implements Builder {
|
532 | 520 | private HttpRoutePlanner httpRoutePlanner;
|
533 | 521 | private CredentialsProvider credentialsProvider;
|
534 | 522 | private DnsResolver dnsResolver;
|
535 |
| - private ConnectionSocketFactory legacyConnectionSocketFactory; |
536 | 523 | private TlsSocketStrategy tlsStrategy;
|
537 | 524 |
|
538 | 525 | private DefaultBuilder() {
|
@@ -654,16 +641,6 @@ public void setDnsResolver(DnsResolver dnsResolver) {
|
654 | 641 | dnsResolver(dnsResolver);
|
655 | 642 | }
|
656 | 643 |
|
657 |
| - @Override |
658 |
| - public Builder socketFactory(ConnectionSocketFactory socketFactory) { |
659 |
| - this.legacyConnectionSocketFactory = socketFactory; |
660 |
| - return this; |
661 |
| - } |
662 |
| - |
663 |
| - public void setSocketFactory(ConnectionSocketFactory socketFactory) { |
664 |
| - socketFactory(socketFactory); |
665 |
| - } |
666 |
| - |
667 | 644 | @Override
|
668 | 645 | public Builder tlsSocketStrategy(TlsSocketStrategy tlsSocketStrategy) {
|
669 | 646 | this.tlsStrategy = tlsSocketStrategy;
|
@@ -738,54 +715,46 @@ public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
|
738 | 715 | SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS);
|
739 | 716 | return new Apache5HttpClient(this, resolvedOptions);
|
740 | 717 | }
|
741 |
| - |
742 |
| - // Internal method to get the effective TLS strategy |
743 |
| - TlsSocketStrategy getEffectiveTlsStrategy() { |
744 |
| - if (tlsStrategy != null) { |
745 |
| - return tlsStrategy; |
746 |
| - } |
747 |
| - if (legacyConnectionSocketFactory != null) { |
748 |
| - return new ConnectionSocketFactoryToTlsStrategyAdapter(legacyConnectionSocketFactory); |
749 |
| - } |
750 |
| - return null; |
751 |
| - } |
752 | 718 | }
|
753 | 719 |
|
754 | 720 | private static class ApacheConnectionManagerFactory {
|
755 | 721 |
|
756 | 722 | public PoolingHttpClientConnectionManager create(Apache5HttpClient.DefaultBuilder configuration,
|
757 | 723 | AttributeMap standardOptions) {
|
758 | 724 |
|
759 |
| - Validate.isTrue(configuration.tlsStrategy == null || configuration.legacyConnectionSocketFactory == null, |
760 |
| - "Cannot configure both tlsSocketStrategy and socketFactory. " |
761 |
| - + "The connectionSocketFactory is deprecated; use tlsSocketStrategy for new implementations."); |
762 |
| - |
763 | 725 | TlsSocketStrategy tlsStrategy = getPreferredTlsStrategy(configuration, standardOptions);
|
764 | 726 |
|
765 | 727 | PoolingHttpClientConnectionManagerBuilder builder =
|
766 | 728 | PoolingHttpClientConnectionManagerBuilder.create()
|
767 | 729 | .setTlsSocketStrategy(tlsStrategy)
|
768 | 730 | .setSchemePortResolver(DefaultSchemePortResolver.INSTANCE)
|
769 | 731 | .setDnsResolver(configuration.dnsResolver);
|
| 732 | + builder.setMaxConnPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); |
| 733 | + builder.setMaxConnTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); |
| 734 | + builder.setDefaultSocketConfig(buildSocketConfig(standardOptions)); |
| 735 | + builder.setDefaultConnectionConfig(getConnectionConfig(standardOptions)); |
| 736 | + return builder.build(); |
| 737 | + } |
770 | 738 |
|
771 |
| - |
| 739 | + private static ConnectionConfig getConnectionConfig(AttributeMap standardOptions) { |
| 740 | + ConnectionConfig.Builder connectionConfigBuilder = |
| 741 | + ConnectionConfig.custom() |
| 742 | + .setConnectTimeout(Timeout.ofMilliseconds( |
| 743 | + standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).toMillis())) |
| 744 | + .setSocketTimeout(Timeout.ofMilliseconds( |
| 745 | + standardOptions.get(SdkHttpConfigurationOption.READ_TIMEOUT).toMillis())); |
772 | 746 | Duration connectionTtl = standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE);
|
773 | 747 | if (!connectionTtl.isZero()) {
|
774 | 748 | // Skip TTL=0 to maintain backward compatibility (infinite in 4.x vs immediate expiration in 5.x)
|
775 |
| - builder.setConnectionTimeToLive(TimeValue.of(connectionTtl.toMillis(), TimeUnit.MILLISECONDS)); |
| 749 | + connectionConfigBuilder.setTimeToLive(TimeValue.ofMilliseconds(connectionTtl.toMillis())); |
776 | 750 | }
|
777 |
| - builder.setMaxConnPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); |
778 |
| - builder.setMaxConnTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS)); |
779 |
| - builder.setDefaultSocketConfig(buildSocketConfig(standardOptions)); |
780 |
| - return builder.build(); |
| 751 | + return connectionConfigBuilder.build(); |
781 | 752 | }
|
782 | 753 |
|
783 | 754 | private TlsSocketStrategy getPreferredTlsStrategy(Apache5HttpClient.DefaultBuilder configuration,
|
784 | 755 | AttributeMap standardOptions) {
|
785 |
| - // Use the effective strategy which handles both legacy and new approaches |
786 |
| - TlsSocketStrategy configuredStrategy = configuration.getEffectiveTlsStrategy(); |
787 |
| - if (configuredStrategy != null) { |
788 |
| - return configuredStrategy; |
| 756 | + if (configuration.tlsStrategy != null) { |
| 757 | + return configuration.tlsStrategy; |
789 | 758 | }
|
790 | 759 | return new SdkTlsSocketFactory(getSslContext(standardOptions),
|
791 | 760 | getHostNameVerifier(standardOptions));
|
@@ -860,7 +829,6 @@ private SocketConfig buildSocketConfig(AttributeMap standardOptions) {
|
860 | 829 | .build();
|
861 | 830 | }
|
862 | 831 |
|
863 |
| - |
864 | 832 | }
|
865 | 833 |
|
866 | 834 | private static class LocalAddressRoutePlanner extends DefaultRoutePlanner {
|
|
0 commit comments