5656import org .apache .hc .client5 .http .ssl .DefaultHostnameVerifier ;
5757import org .apache .hc .client5 .http .ssl .NoopHostnameVerifier ;
5858import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
59+ import org .apache .hc .client5 .http .ssl .TlsSocketStrategy ;
5960import org .apache .hc .core5 .http .ClassicHttpResponse ;
6061import org .apache .hc .core5 .http .Header ;
6162import org .apache .hc .core5 .http .HttpEntity ;
8889import software .amazon .awssdk .http .apache5 .internal .SdkProxyRoutePlanner ;
8990import software .amazon .awssdk .http .apache5 .internal .conn .ClientConnectionManagerFactory ;
9091import software .amazon .awssdk .http .apache5 .internal .conn .IdleConnectionReaper ;
92+ import software .amazon .awssdk .http .apache5 .internal .conn .SslSocketFactoryToTlsStrategyAdapter ;
9193import software .amazon .awssdk .http .apache5 .internal .conn .SdkConnectionKeepAliveStrategy ;
9294import software .amazon .awssdk .http .apache5 .internal .conn .SdkTlsSocketFactory ;
9395import software .amazon .awssdk .http .apache5 .internal .impl .Apache5HttpRequestFactory ;
@@ -457,8 +459,12 @@ public interface Builder extends SdkHttpClient.Builder<Apache5HttpClient.Builder
457459 * When set to a non-null value, the use of a custom factory implies the configuration options TRUST_ALL_CERTIFICATES,
458460 * TLS_TRUST_MANAGERS_PROVIDER, and TLS_KEY_MANAGERS_PROVIDER are ignored.
459461 */
462+ @ Deprecated
460463 Builder socketFactory (SSLConnectionSocketFactory socketFactory );
461464
465+
466+ Builder tlsStrategy (TlsSocketStrategy tlsStrategy );
467+
462468 /**
463469 * Configuration that defines an HTTP route planner that computes the route an HTTP request should take.
464470 * May not be used in conjunction with {@link #proxyConfiguration(ProxyConfiguration)}.
@@ -515,7 +521,8 @@ private static final class DefaultBuilder implements Builder {
515521 private HttpRoutePlanner httpRoutePlanner ;
516522 private CredentialsProvider credentialsProvider ;
517523 private DnsResolver dnsResolver ;
518- private SSLConnectionSocketFactory socketFactory ;
524+ private SSLConnectionSocketFactory legacySocketFactory ;
525+ private TlsSocketStrategy tlsStrategy ;
519526
520527 private DefaultBuilder () {
521528 }
@@ -638,12 +645,23 @@ public void setDnsResolver(DnsResolver dnsResolver) {
638645
639646 @ Override
640647 public Builder socketFactory (SSLConnectionSocketFactory socketFactory ) {
641- this .socketFactory = socketFactory ;
648+ log .warn (() -> "SSLConnectionSocketFactory is deprecated. Consider migrating to tlsStrategy()." );
649+ this .legacySocketFactory = socketFactory ;
650+ this .tlsStrategy = null ; // Clear any previously set strategy
642651 return this ;
643652 }
644653
645- public void setSocketFactory (SSLConnectionSocketFactory socketFactory ) {
646- socketFactory (socketFactory );
654+ @ Override
655+ public Builder tlsStrategy (TlsSocketStrategy tlsStrategy ) {
656+ this .tlsStrategy = tlsStrategy ;
657+ this .legacySocketFactory = null ; // Clear any legacy factory
658+ return this ;
659+ }
660+
661+
662+
663+ public void setLegacySocketFactory (SSLConnectionSocketFactory legacySocketFactory ) {
664+ socketFactory (legacySocketFactory );
647665 }
648666
649667 @ Override
@@ -714,20 +732,36 @@ public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
714732 SdkHttpConfigurationOption .GLOBAL_HTTP_DEFAULTS );
715733 return new Apache5HttpClient (this , resolvedOptions );
716734 }
735+
736+ // Internal method to get the effective TLS strategy
737+
738+ TlsSocketStrategy getEffectiveTlsStrategy () {
739+ if (tlsStrategy != null ) {
740+ return tlsStrategy ;
741+ }
742+ if (legacySocketFactory != null ) {
743+ return new SslSocketFactoryToTlsStrategyAdapter (legacySocketFactory );
744+ }
745+ return null ;
746+ }
747+
748+
717749 }
718750
719751 private static class ApacheConnectionManagerFactory {
720752
721753 public PoolingHttpClientConnectionManager create (Apache5HttpClient .DefaultBuilder configuration ,
722- AttributeMap standardOptions ) {
723- // TODO : Deprecated method needs to be removed with new replacements
724- SSLConnectionSocketFactory sslsf = getPreferredSocketFactory (configuration , standardOptions );
754+ AttributeMap standardOptions ) {
755+
756+ TlsSocketStrategy tlsStrategy = getPreferredTlsStrategy (configuration , standardOptions );
725757
726758 PoolingHttpClientConnectionManagerBuilder builder =
727759 PoolingHttpClientConnectionManagerBuilder .create ()
728- .setSSLSocketFactory ( sslsf )
760+ .setTlsSocketStrategy ( tlsStrategy )
729761 .setSchemePortResolver (DefaultSchemePortResolver .INSTANCE )
730762 .setDnsResolver (configuration .dnsResolver );
763+
764+
731765 Duration connectionTtl = standardOptions .get (SdkHttpConfigurationOption .CONNECTION_TIME_TO_LIVE );
732766 if (!connectionTtl .isZero ()) {
733767 // Skip TTL=0 to maintain backward compatibility (infinite in 4.x vs immediate expiration in 5.x)
@@ -739,11 +773,15 @@ public PoolingHttpClientConnectionManager create(Apache5HttpClient.DefaultBuilde
739773 return builder .build ();
740774 }
741775
742- private SSLConnectionSocketFactory getPreferredSocketFactory (Apache5HttpClient .DefaultBuilder configuration ,
743- AttributeMap standardOptions ) {
744- return Optional .ofNullable (configuration .socketFactory )
745- .orElseGet (() -> new SdkTlsSocketFactory (getSslContext (standardOptions ),
746- getHostNameVerifier (standardOptions )));
776+ private TlsSocketStrategy getPreferredTlsStrategy (Apache5HttpClient .DefaultBuilder configuration ,
777+ AttributeMap standardOptions ) {
778+ // Use the effective strategy which handles both legacy and new approaches
779+ TlsSocketStrategy configuredStrategy = configuration .getEffectiveTlsStrategy ();
780+ if (configuredStrategy != null ) {
781+ return configuredStrategy ;
782+ }
783+ return new SdkTlsSocketFactory (getSslContext (standardOptions ),
784+ getHostNameVerifier (standardOptions ));
747785 }
748786
749787
@@ -815,6 +853,7 @@ private SocketConfig buildSocketConfig(AttributeMap standardOptions) {
815853 .build ();
816854 }
817855
856+
818857 }
819858
820859 private static class LocalAddressRoutePlanner extends DefaultRoutePlanner {
0 commit comments