Skip to content

Commit 1b1caa0

Browse files
committed
Handled Surface API review comments
1 parent a21356a commit 1b1caa0

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

.brazil.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"modules": {
55
"annotations": { "packageName": "AwsJavaSdk-Core-Annotations" },
66
"apache-client": { "packageName": "AwsJavaSdk-HttpClient-ApacheClient" },
7-
"apache5-client": { "packageName": "AwsJavaSdk-HttpClient-Apache5Client-preview" },
7+
"apache5-client": { "packageName": "AwsJavaSdk-HttpClient-Apache5Client-Preview" },
88
"arns": { "packageName": "AwsJavaSdk-Core-Arns" },
99
"auth": { "packageName": "AwsJavaSdk-Core-Auth" },
1010
"auth-crt": { "packageName": "AwsJavaSdk-Core-AuthCrt" },

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.ByteArrayInputStream;
2727
import java.io.IOException;
28+
import java.net.InetAddress;
2829
import java.security.KeyManagementException;
2930
import java.security.NoSuchAlgorithmException;
3031
import java.security.cert.CertificateException;
@@ -48,6 +49,7 @@
4849
import org.apache.hc.client5.http.impl.classic.HttpClients;
4950
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
5051
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
52+
import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
5153
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
5254
import org.apache.hc.client5.http.protocol.HttpClientContext;
5355
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
@@ -57,10 +59,13 @@
5759
import org.apache.hc.core5.http.ClassicHttpResponse;
5860
import org.apache.hc.core5.http.Header;
5961
import org.apache.hc.core5.http.HttpEntity;
62+
import org.apache.hc.core5.http.HttpException;
63+
import org.apache.hc.core5.http.HttpHost;
6064
import org.apache.hc.core5.http.HttpResponse;
6165
import org.apache.hc.core5.http.config.Registry;
6266
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
6367
import org.apache.hc.core5.http.io.SocketConfig;
68+
import org.apache.hc.core5.http.protocol.HttpContext;
6469
import org.apache.hc.core5.io.CloseMode;
6570
import org.apache.hc.core5.pool.PoolStats;
6671
import org.apache.hc.core5.ssl.SSLInitializationException;
@@ -108,7 +113,7 @@
108113
@SdkPublicApi
109114
public final class Apache5HttpClient implements SdkHttpClient {
110115

111-
public static final String CLIENT_NAME = "Apache5";
116+
public static final String CLIENT_NAME = "Apache5Preview";
112117

113118
private static final Logger log = Logger.loggerFor(Apache5HttpClient.class);
114119
private static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = new DefaultHostnameVerifier();
@@ -206,7 +211,12 @@ private void addProxyConfig(HttpClientBuilder builder,
206211
}
207212

208213
if (routePlanner != null) {
214+
if (configuration.localAddress != null) {
215+
log.debug(() -> "localAddress configuration was ignored since Route planner was explicitly provided");
216+
}
209217
builder.setRoutePlanner(routePlanner);
218+
} else if (configuration.localAddress != null) {
219+
builder.setRoutePlanner(new LocalAddressRoutePlanner(configuration.localAddress));
210220
}
211221

212222
if (credentialsProvider != null) {
@@ -404,6 +414,11 @@ public interface Builder extends SdkHttpClient.Builder<Apache5HttpClient.Builder
404414
*/
405415
Builder proxyConfiguration(ProxyConfiguration proxyConfiguration);
406416

417+
/**
418+
* Configure the local address that the HTTP client should use for communication.
419+
*/
420+
Builder localAddress(InetAddress localAddress);
421+
407422
/**
408423
* Configure whether the client should send an HTTP expect-continue handshake before each request.
409424
*/
@@ -495,6 +510,7 @@ private static final class DefaultBuilder implements Builder {
495510
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
496511
private Registry<AuthSchemeFactory> authSchemeRegistry;
497512
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
513+
private InetAddress localAddress;
498514
private Boolean expectContinueEnabled;
499515
private HttpRoutePlanner httpRoutePlanner;
500516
private CredentialsProvider credentialsProvider;
@@ -560,6 +576,16 @@ public void setProxyConfiguration(ProxyConfiguration proxyConfiguration) {
560576
proxyConfiguration(proxyConfiguration);
561577
}
562578

579+
@Override
580+
public Builder localAddress(InetAddress localAddress) {
581+
this.localAddress = localAddress;
582+
return this;
583+
}
584+
585+
public void setLocalAddress(InetAddress localAddress) {
586+
localAddress(localAddress);
587+
}
588+
563589
@Override
564590
public Builder expectContinueEnabled(Boolean expectContinueEnabled) {
565591
this.expectContinueEnabled = expectContinueEnabled;
@@ -794,4 +820,18 @@ private SocketConfig buildSocketConfig(AttributeMap standardOptions) {
794820
}
795821

796822
}
823+
824+
private static class LocalAddressRoutePlanner extends DefaultRoutePlanner {
825+
private final InetAddress localAddress;
826+
827+
LocalAddressRoutePlanner(InetAddress localAddress) {
828+
super(DefaultSchemePortResolver.INSTANCE);
829+
this.localAddress = localAddress;
830+
}
831+
832+
@Override
833+
protected InetAddress determineLocalAddress(HttpHost firstHop, HttpContext context) throws HttpException {
834+
return localAddress;
835+
}
836+
}
797837
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
16+
package software.amazon.awssdk.http.apache5;
17+
18+
import java.net.InetAddress;
19+
import java.time.Duration;
20+
import org.junit.jupiter.api.DisplayName;
21+
import software.amazon.awssdk.http.SdkHttpClient;
22+
import software.amazon.awssdk.http.SdkHttpClientLocalAddressFunctionalTestSuite;
23+
24+
@DisplayName("Apache5 HTTP Client - Local Address Functional Tests")
25+
class Apache5HttpClientLocalAddressOnBuilderFunctionalTest extends SdkHttpClientLocalAddressFunctionalTestSuite {
26+
27+
@Override
28+
protected SdkHttpClient createHttpClient(InetAddress localAddress, Duration connectionTimeout) {
29+
30+
return Apache5HttpClient.builder()
31+
.localAddress(localAddress)
32+
.connectionTimeout(connectionTimeout)
33+
.build();
34+
}
35+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import software.amazon.awssdk.http.SdkHttpClientLocalAddressFunctionalTestSuite;
2929

3030
@DisplayName("Apache5 HTTP Client - Local Address Functional Tests")
31-
class Apache5HttpClientLocalAddressFunctionalTest extends SdkHttpClientLocalAddressFunctionalTestSuite {
31+
class Apache5HttpClientLocalAddressRoutePlannerFunctionalTest extends SdkHttpClientLocalAddressFunctionalTestSuite {
3232

3333
@Override
3434
protected SdkHttpClient createHttpClient(InetAddress localAddress, Duration connectionTimeout) {

http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/MetricReportingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void prepareRequest_callableCalled_metricsReported() throws IOException {
8181

8282
client.prepareRequest(executeRequest).call();
8383
MetricCollection collected = collector.collect();
84-
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache5");
84+
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache5Preview");
8585
assertThat(collected.metricValues(LEASED_CONCURRENCY)).containsExactly(1);
8686
assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).containsExactly(2);
8787
assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).containsExactly(3);
@@ -99,7 +99,7 @@ public void prepareRequest_connectionManagerNotPooling_callableCalled_metricsRep
9999

100100
MetricCollection collected = collector.collect();
101101

102-
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache5");
102+
assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache5Preview");
103103
assertThat(collected.metricValues(LEASED_CONCURRENCY)).isEmpty();
104104
assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).isEmpty();
105105
assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).isEmpty();

0 commit comments

Comments
 (0)