Skip to content

Commit 3cc94bb

Browse files
authored
Clean up unused APIs and add test to make sure it can be handled with alternatives (#6211)
* Clean up unused APIs and add test to make sure it can be handled with alternatives * Added NTCredentials to keep backward compatibilty with Apache4.x
1 parent e188995 commit 3cc94bb

File tree

12 files changed

+417
-260
lines changed

12 files changed

+417
-260
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package software.amazon.awssdk.http.apache;
16+
17+
import java.net.InetAddress;
18+
import java.time.Duration;
19+
import org.junit.jupiter.api.DisplayName;
20+
import software.amazon.awssdk.http.SdkHttpClient;
21+
import software.amazon.awssdk.http.SdkHttpClientLocalAddressFunctionalTestSuite;
22+
23+
@DisplayName("Apache HTTP Client - Local Address Functional Tests")
24+
class ApacheHttpClientLocalAddressFunctionalTest extends SdkHttpClientLocalAddressFunctionalTestSuite {
25+
26+
@Override
27+
protected SdkHttpClient createHttpClient(InetAddress localAddress, Duration connectionTimeout) {
28+
return ApacheHttpClient.builder()
29+
.localAddress(localAddress)
30+
.connectionTimeout(connectionTimeout)
31+
.build();
32+
}
33+
}

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.io.ByteArrayInputStream;
2727
import java.io.IOException;
28-
import java.net.InetAddress;
2928
import java.security.KeyManagementException;
3029
import java.security.NoSuchAlgorithmException;
3130
import java.security.cert.CertificateException;
@@ -338,7 +337,6 @@ private Apache5HttpRequestConfig createRequestConfig(DefaultBuilder builder,
338337
.connectionAcquireTimeout(
339338
resolvedOptions.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT))
340339
.proxyConfiguration(builder.proxyConfiguration)
341-
.localAddress(Optional.ofNullable(builder.localAddress).orElse(null))
342340
.expectContinueEnabled(Optional.ofNullable(builder.expectContinueEnabled)
343341
.orElse(DefaultConfiguration.EXPECT_CONTINUE_ENABLED))
344342
.build();
@@ -406,11 +404,6 @@ public interface Builder extends SdkHttpClient.Builder<Apache5HttpClient.Builder
406404
*/
407405
Builder proxyConfiguration(ProxyConfiguration proxyConfiguration);
408406

409-
/**
410-
* Configure the local address that the HTTP client should use for communication.
411-
*/
412-
Builder localAddress(InetAddress localAddress);
413-
414407
/**
415408
* Configure whether the client should send an HTTP expect-continue handshake before each request.
416409
*/
@@ -498,7 +491,6 @@ private static final class DefaultBuilder implements Builder {
498491
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
499492
private Registry<AuthSchemeFactory> authSchemeRegistry;
500493
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
501-
private InetAddress localAddress;
502494
private Boolean expectContinueEnabled;
503495
private HttpRoutePlanner httpRoutePlanner;
504496
private CredentialsProvider credentialsProvider;
@@ -564,16 +556,6 @@ public void setProxyConfiguration(ProxyConfiguration proxyConfiguration) {
564556
proxyConfiguration(proxyConfiguration);
565557
}
566558

567-
@Override
568-
public Builder localAddress(InetAddress localAddress) {
569-
this.localAddress = localAddress;
570-
return this;
571-
}
572-
573-
public void setLocalAddress(InetAddress localAddress) {
574-
localAddress(localAddress);
575-
}
576-
577559
@Override
578560
public Builder expectContinueEnabled(Boolean expectContinueEnabled) {
579561
this.expectContinueEnabled = expectContinueEnabled;

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/Apache5HttpRequestConfig.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package software.amazon.awssdk.http.apache5.internal;
1717

18-
import java.net.InetAddress;
1918
import java.time.Duration;
2019
import software.amazon.awssdk.annotations.SdkInternalApi;
2120
import software.amazon.awssdk.http.apache5.ProxyConfiguration;
@@ -30,15 +29,13 @@ public final class Apache5HttpRequestConfig {
3029
private final Duration socketTimeout;
3130
private final Duration connectionTimeout;
3231
private final Duration connectionAcquireTimeout;
33-
private final InetAddress localAddress;
3432
private final boolean expectContinueEnabled;
3533
private final ProxyConfiguration proxyConfiguration;
3634

3735
private Apache5HttpRequestConfig(Builder builder) {
3836
this.socketTimeout = builder.socketTimeout;
3937
this.connectionTimeout = builder.connectionTimeout;
4038
this.connectionAcquireTimeout = builder.connectionAcquireTimeout;
41-
this.localAddress = builder.localAddress;
4239
this.expectContinueEnabled = builder.expectContinueEnabled;
4340
this.proxyConfiguration = builder.proxyConfiguration;
4441
}
@@ -55,10 +52,6 @@ public Duration connectionAcquireTimeout() {
5552
return connectionAcquireTimeout;
5653
}
5754

58-
public InetAddress localAddress() {
59-
return localAddress;
60-
}
61-
6255
public boolean expectContinueEnabled() {
6356
return expectContinueEnabled;
6457
}
@@ -82,7 +75,6 @@ public static final class Builder {
8275
private Duration socketTimeout;
8376
private Duration connectionTimeout;
8477
private Duration connectionAcquireTimeout;
85-
private InetAddress localAddress;
8678
private boolean expectContinueEnabled;
8779
private ProxyConfiguration proxyConfiguration;
8880

@@ -104,11 +96,6 @@ public Builder connectionAcquireTimeout(Duration connectionAcquireTimeout) {
10496
return this;
10597
}
10698

107-
public Builder localAddress(InetAddress localAddress) {
108-
this.localAddress = localAddress;
109-
return this;
110-
}
111-
11299
public Builder expectContinueEnabled(boolean expectContinueEnabled) {
113100
this.expectContinueEnabled = expectContinueEnabled;
114101
return this;

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/conn/SdkTlsSocketFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.apache.hc.core5.http.protocol.HttpContext;
2828
import org.apache.hc.core5.util.TimeValue;
2929
import software.amazon.awssdk.annotations.SdkInternalApi;
30-
import software.amazon.awssdk.http.apache5.internal.net.InputShutdownCheckingSslSocket;
3130
import software.amazon.awssdk.http.apache5.internal.net.SdkSocket;
32-
import software.amazon.awssdk.http.apache5.internal.net.SdkSslSocket;
3331
import software.amazon.awssdk.utils.Logger;
3432

3533
@SdkInternalApi
@@ -62,9 +60,6 @@ public Socket connectSocket(TimeValue connectTimeout,
6260
log.trace(() -> String.format("Connecting to %s:%s", remoteAddress.getAddress(), remoteAddress.getPort()));
6361

6462
Socket connectSocket = super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
65-
if (connectSocket instanceof SSLSocket) {
66-
return new InputShutdownCheckingSslSocket(new SdkSslSocket((SSLSocket) connectSocket));
67-
}
6863
return new SdkSocket(connectSocket);
6964
}
7065
}

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/impl/Apache5HttpRequestFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ private void addRequestConfig(HttpUriRequestBase base,
9898
.setConnectionRequestTimeout(connectAcquireTimeout, TimeUnit.MILLISECONDS)
9999
.setConnectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
100100
.setResponseTimeout(saturatedCast(requestConfig.socketTimeout().toMillis()), TimeUnit.MILLISECONDS);
101-
// TODO as part of removed API : .setLocalAddress(requestConfig.localAddress());
102101

103102
/*
104103
* Enable 100-continue support for PUT operations, since this is

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/net/InputShutdownCheckingSslSocket.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/utils/Apache5Utils.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import java.io.IOException;
1919
import java.io.UncheckedIOException;
2020
import org.apache.hc.client5.http.auth.AuthCache;
21+
import org.apache.hc.client5.http.auth.AuthScope;
22+
import org.apache.hc.client5.http.auth.Credentials;
2123
import org.apache.hc.client5.http.auth.CredentialsProvider;
24+
import org.apache.hc.client5.http.auth.NTCredentials;
2225
import org.apache.hc.client5.http.config.RequestConfig;
2326
import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
2427
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
@@ -37,8 +40,7 @@ private Apache5Utils() {
3740
}
3841

3942
/**
40-
* Utility function for creating a new BufferedEntity and wrapping any errors
41-
* as a SdkClientException.
43+
* Utility function for creating a new BufferedEntity and wrapping any errors as a SdkClientException.
4244
*
4345
* @param entity The HTTP entity to wrap with a buffered HTTP entity.
4446
* @return A new BufferedHttpEntity wrapping the specified entity.
@@ -69,27 +71,29 @@ public static HttpClientContext newClientContext(ProxyConfiguration proxyConfigu
6971
*/
7072
public static CredentialsProvider newProxyCredentialsProvider(ProxyConfiguration proxyConfiguration) {
7173
BasicCredentialsProvider provider = new BasicCredentialsProvider();
72-
// TODO : NTCredentials is deprecated.
73-
// provider.setCredentials(newAuthScope(proxyConfiguration), newNtCredentials(proxyConfiguration));
74+
provider.setCredentials(newAuthScope(proxyConfiguration), newNtCredentials(proxyConfiguration));
7475
return provider;
7576
}
7677

77-
// /**
78-
// * Returns a new instance of NTCredentials used for proxy authentication.
79-
// */
80-
// private static Credentials newNtCredentials(ProxyConfiguration proxyConfiguration) {
81-
// return new NTCredentials(proxyConfiguration.username(),
82-
// proxyConfiguration.password(),
83-
// proxyConfiguration.ntlmWorkstation(),
84-
// proxyConfiguration.ntlmDomain());
85-
// }
78+
/**
79+
* Returns a new instance of NTCredentials used for proxy authentication.
80+
*/
81+
private static Credentials newNtCredentials(ProxyConfiguration proxyConfiguration) {
82+
return new NTCredentials(
83+
proxyConfiguration.username(),
84+
proxyConfiguration.password().toCharArray(),
85+
proxyConfiguration.ntlmWorkstation(),
86+
proxyConfiguration.ntlmDomain()
87+
);
88+
}
89+
90+
/**
91+
* Returns a new instance of AuthScope used for proxy authentication.
92+
*/
93+
private static AuthScope newAuthScope(ProxyConfiguration proxyConfiguration) {
94+
return new AuthScope(proxyConfiguration.host(), proxyConfiguration.port());
95+
}
8696

87-
// /**
88-
// * Returns a new instance of AuthScope used for proxy authentication.
89-
// */
90-
// private static AuthScope newAuthScope(ProxyConfiguration proxyConfiguration) {
91-
// return new AuthScope(proxyConfiguration.host(), proxyConfiguration.port());
92-
// }
9397

9498
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext,
9599
ProxyConfiguration proxyConfiguration) {
@@ -107,5 +111,4 @@ private static void addPreemptiveAuthenticationProxy(HttpClientContext clientCon
107111
clientContext.setAuthCache(authCache);
108112
}
109113
}
110-
111114
}

0 commit comments

Comments
 (0)