Skip to content

Commit faf0ded

Browse files
dagnirjoviegas
andauthored
Make apache5-client the default sync HTTP client (#6732)
* Swap apache-client with apache5-client This commit swaps the default apache-client dependency of service modules with apache5-client. Applications just relying on the default HTTP client will now use `Apache5HttpClient` as a result. * Fix CloudFrontUtilitiesIntegrationTest * Fix S3 tests * Update version in changelog entry * Revert to 4.x for test Expect100ContinueHeaderTest tests 4.x specific behavior (default 100-continue). * Add apache-client to aws-sdk-java module to prevent NoClassDefFoundError for customers using ApacheHttpClient in environments that bundle the whole SDK (e.g., EMR) after apache5-client default switch (#6964) * fix(integ-test): Fix Integ test issue after making Apache5 as default (#6974) * fix(dynamodb): Add TCP keep-alive permissions to SecurityManager test policy for Apache 5 compatibility. Apache 5.6 sets TCP_KEEPIDLE/INTERVAL/COUNT by default which requires jdk.net.NetworkPermission. * Fix ResponseInputStreamTimeoutIntegrationTest to update it to Apache5 exception assertion * Remove apache5-client test scope from s3/pom.xml to restore runtime transitivity. The test scope override prevented downstream modules like s3-transfer-manager from discovering the HTTP client via SPI * Dumy commit to trigger integ test * because we use org.apache.hc.core5.http.ConnectionRequestTimeoutException in ResponseInputStreamTimeoutIntegrationTest * Removing Apache5 specific execption from ResponseInputStreamTimeoutIntegrationTest and asserting just on error message * remove apache 5 as test dependency since it present as runtime * Updated change logs to have notable changes in the change logs * Upgrade httpcomponents.client5 to 5.6.1 --------- Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com> Co-authored-by: John Viegas <joviegas@amazon.com>
1 parent 361529d commit faf0ded

16 files changed

Lines changed: 73 additions & 59 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "This update replaces the default `apache-client` runtime dependency of service clients with the new `apache5-client`. This means that service clients will now use the `Apache5HttpClient` by default if no HTTP client is explicitly configured on the service client builder.\\n Notable changes:\\n - Apache 5 uses different logger names than Apache 4\\n - Expect: 100-Continue is disabled by default\\n - TCP keep-alive socket options require `jdk.net.NetworkPermission` when SecurityManager is active"
6+
}

aws-sdk-java/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,11 @@ Amazon AutoScaling, etc).</description>
21882188
<artifactId>resiliencehubv2</artifactId>
21892189
<version>${awsjavasdk.version}</version>
21902190
</dependency>
2191+
<dependency>
2192+
<groupId>software.amazon.awssdk</groupId>
2193+
<artifactId>apache-client</artifactId>
2194+
<version>${awsjavasdk.version}</version>
2195+
</dependency>
21912196
</dependencies>
21922197
<build>
21932198
<finalName>${project.artifactId}-${project.version}</finalName>

services/cloudfront/src/test/java/software/amazon/awssdk/services/cloudfront/CloudFrontUtilitiesIntegrationTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import software.amazon.awssdk.http.SdkHttpClient;
5151
import software.amazon.awssdk.http.SdkHttpMethod;
5252
import software.amazon.awssdk.http.SdkHttpRequest;
53-
import software.amazon.awssdk.http.apache.ApacheHttpClient;
53+
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
5454
import software.amazon.awssdk.services.cloudfront.cookie.CookiesForCannedPolicy;
5555
import software.amazon.awssdk.services.cloudfront.cookie.CookiesForCustomPolicy;
5656
import software.amazon.awssdk.services.cloudfront.internal.utils.SigningUtils;
@@ -142,7 +142,7 @@ static Stream<KeyTestCase> keyCases() throws Exception {
142142

143143
@Test
144144
void unsignedUrl_shouldReturn403Response() throws Exception {
145-
SdkHttpClient client = ApacheHttpClient.create();
145+
SdkHttpClient client = Apache5HttpClient.create();
146146
HttpExecuteResponse response =
147147
client.prepareRequest(HttpExecuteRequest.builder()
148148
.request(SdkHttpRequest.builder()
@@ -167,7 +167,7 @@ void getSignedUrlWithCannedPolicy_producesValidUrl(KeyTestCase testCase) throws
167167
.keyPairId(testCase.keyPairId)
168168
.expirationDate(expirationDate).build();
169169
SignedUrl signedUrl = cloudFrontUtilities.getSignedUrlWithCannedPolicy(request);
170-
SdkHttpClient client = ApacheHttpClient.create();
170+
SdkHttpClient client = Apache5HttpClient.create();
171171
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
172172
.request(signedUrl.createHttpGetRequest())
173173
.build()).call();
@@ -186,7 +186,7 @@ void getSignedUrlWithCannedPolicy_withExpiredDate_shouldReturn403Response(KeyTes
186186
.privateKey(testCase.privateKey)
187187
.keyPairId(testCase.keyPairId)
188188
.expirationDate(expirationDate));
189-
SdkHttpClient client = ApacheHttpClient.create();
189+
SdkHttpClient client = Apache5HttpClient.create();
190190
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
191191
.request(signedUrl.createHttpGetRequest())
192192
.build()).call();
@@ -207,7 +207,7 @@ void getSignedUrlWithCustomPolicy_producesValidUrl(KeyTestCase testCase) throws
207207
.expirationDate(expirationDate)
208208
.activeDate(activeDate).build();
209209
SignedUrl signedUrl = cloudFrontUtilities.getSignedUrlWithCustomPolicy(request);
210-
SdkHttpClient client = ApacheHttpClient.create();
210+
SdkHttpClient client = Apache5HttpClient.create();
211211
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
212212
.request(signedUrl.createHttpGetRequest())
213213
.build()).call();
@@ -227,7 +227,7 @@ void getSignedUrlWithCustomPolicy_withFutureActiveDate_shouldReturn403Response()
227227
.keyPairId(rsaKeyPairId)
228228
.expirationDate(expirationDate)
229229
.activeDate(activeDate));
230-
SdkHttpClient client = ApacheHttpClient.create();
230+
SdkHttpClient client = Apache5HttpClient.create();
231231
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
232232
.request(signedUrl.createHttpGetRequest())
233233
.build()).call();
@@ -245,7 +245,7 @@ void getCookiesForCannedPolicy_producesValidCookies(KeyTestCase testCase) throws
245245
.keyPairId(testCase.keyPairId)
246246
.expirationDate(expirationDate));
247247

248-
SdkHttpClient client = ApacheHttpClient.create();
248+
SdkHttpClient client = Apache5HttpClient.create();
249249
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
250250
.request(cookies.createHttpGetRequest())
251251
.build()).call();
@@ -266,7 +266,7 @@ void getCookiesForCannedPolicy_withExpiredDate_shouldReturn403Response() throws
266266
.expirationDate(expirationDate).build();
267267
CookiesForCannedPolicy cookies = cloudFrontUtilities.getCookiesForCannedPolicy(request);
268268

269-
SdkHttpClient client = ApacheHttpClient.create();
269+
SdkHttpClient client = Apache5HttpClient.create();
270270
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
271271
.request(cookies.createHttpGetRequest())
272272
.build()).call();
@@ -286,7 +286,7 @@ void getCookiesForCustomPolicy_producesValidCookies(KeyTestCase testCase) throws
286286
.expirationDate(expirationDate)
287287
.activeDate(activeDate));
288288

289-
SdkHttpClient client = ApacheHttpClient.create();
289+
SdkHttpClient client = Apache5HttpClient.create();
290290
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
291291
.request(cookies.createHttpGetRequest())
292292
.build()).call();
@@ -309,7 +309,7 @@ void getCookiesForCustomPolicy_withFutureActiveDate_shouldReturn403Response() th
309309
.activeDate(activeDate).build();
310310
CookiesForCustomPolicy cookies = cloudFrontUtilities.getCookiesForCustomPolicy(request);
311311

312-
SdkHttpClient client = ApacheHttpClient.create();
312+
SdkHttpClient client = Apache5HttpClient.create();
313313
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
314314
.request(cookies.createHttpGetRequest())
315315
.build()).call();
@@ -337,7 +337,7 @@ void getCookiesForCustomPolicy_shouldAllowQueryParametersWhenUsingWildcard(KeyTe
337337

338338
// Request the same resource with an additional query parameter - should still be allowed by the wildcard policy
339339
URI uri = URI.create(resourceUrl + "?foo=bar");
340-
SdkHttpClient client = ApacheHttpClient.create();
340+
SdkHttpClient client = Apache5HttpClient.create();
341341
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
342342
.request(SdkHttpRequest.builder()
343343
.uri(uri)
@@ -372,7 +372,7 @@ void getCookiesForCustomPolicy_wildCardPath(KeyTestCase testCase) throws Excepti
372372

373373
// Use the cookies to access a different file under the same wildcard path
374374
URI otherFileUri = URI.create(resourceUri + "/foo/other-file");
375-
SdkHttpClient client = ApacheHttpClient.create();
375+
SdkHttpClient client = Apache5HttpClient.create();
376376
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
377377
.request(SdkHttpRequest.builder()
378378
.uri(otherFileUri)
@@ -406,7 +406,7 @@ void getCookiesForCustomPolicy_wildCardPolicyResource_allowsAnyPath(KeyTestCase
406406

407407
// Use the cookies to access a completely different path - the "*" pattern should allow any path
408408
URI differentPathUri = URI.create(resourceUrl.replace("/s3ObjectKey", "/foo/other-file"));
409-
SdkHttpClient client = ApacheHttpClient.create();
409+
SdkHttpClient client = Apache5HttpClient.create();
410410
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
411411
.request(SdkHttpRequest.builder()
412412
.uri(differentPathUri)
@@ -445,7 +445,7 @@ void getSignedUrlWithCustomPolicy_shouldAllowQueryParametersWhenUsingWildcard(Ke
445445
URI modifiedUri = URI.create(urlWithDynamicParam);
446446

447447

448-
SdkHttpClient client = ApacheHttpClient.create();
448+
SdkHttpClient client = Apache5HttpClient.create();
449449
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
450450
.request(SdkHttpRequest.builder()
451451
.encodedPath(modifiedUri.getRawPath() + "?" + modifiedUri.getRawQuery())
@@ -482,7 +482,7 @@ void getSignedUrlWithCustomPolicy_wildCardPath(KeyTestCase testCase) throws Exce
482482

483483

484484
URI modifiedUri = URI.create(signedUrl.url().replace("/specific-file","/other-file"));
485-
SdkHttpClient client = ApacheHttpClient.create();
485+
SdkHttpClient client = Apache5HttpClient.create();
486486
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
487487
.request(SdkHttpRequest.builder()
488488
.encodedPath(modifiedUri.getRawPath() + "?" + modifiedUri.getRawQuery())
@@ -518,7 +518,7 @@ void getSignedUrlWithCustomPolicy_wildCardPolicyResource_allowsAnyPath(KeyTestCa
518518

519519

520520
URI modifiedUri = URI.create(signedUrl.url().replace("/s3ObjectKey","/foo/other-file"));
521-
SdkHttpClient client = ApacheHttpClient.create();
521+
SdkHttpClient client = Apache5HttpClient.create();
522522
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
523523
.request(SdkHttpRequest.builder()
524524
.encodedPath(modifiedUri.getRawPath() + "?" + modifiedUri.getRawQuery())

services/dynamodb/src/it/java/software/amazon/awssdk/services/dynamodb/SignersIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import software.amazon.awssdk.http.SdkHttpClient;
3838
import software.amazon.awssdk.http.SdkHttpFullRequest;
3939
import software.amazon.awssdk.http.SdkHttpMethod;
40-
import software.amazon.awssdk.http.apache.ApacheHttpClient;
40+
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
4141
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
4242
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
4343
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
@@ -132,7 +132,7 @@ public void sign_WithoutUsingSdkClient_ThroughExecutionAttributes() throws Excep
132132
// sign the request
133133
SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructExecutionAttributes());
134134

135-
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
135+
SdkHttpClient httpClient = Apache5HttpClient.builder().build();
136136

137137
HttpExecuteRequest request = HttpExecuteRequest.builder()
138138
.request(signedRequest)
@@ -156,7 +156,7 @@ public void test_SignMethod_WithModeledParam_And_WithoutUsingSdkClient() throws
156156
// sign the request
157157
SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructSignerParams());
158158

159-
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
159+
SdkHttpClient httpClient = Apache5HttpClient.builder().build();
160160

161161
HttpExecuteRequest request = HttpExecuteRequest.builder()
162162
.request(signedRequest)

services/dynamodb/src/test/resources/software/amazon/awssdk/services/dynamodb/security-manager-integ-test.policy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ grant {
66
permission "javax.net.ssl.SSLPermission" "setDefaultSSLContext";
77
permission "java.net.SocketPermission" "*", "connect,resolve";
88

9+
// Needed for Apache5 HTTP Client TCP keep-alive socket options
10+
permission jdk.net.NetworkPermission "setOption.TCP_KEEPIDLE";
11+
permission jdk.net.NetworkPermission "setOption.TCP_KEEPINTERVAL";
12+
permission jdk.net.NetworkPermission "setOption.TCP_KEEPCOUNT";
13+
914
// Needed for test to remove the security manager
1015
permission java.lang.RuntimePermission "setSecurityManager";
1116

services/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
<version>${awsjavasdk.version}</version>
533533
</dependency>
534534
<dependency>
535-
<artifactId>apache-client</artifactId>
535+
<artifactId>apache5-client</artifactId>
536536
<groupId>software.amazon.awssdk</groupId>
537537
<version>${awsjavasdk.version}</version>
538538
<scope>runtime</scope>

services/s3/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@
203203
<version>${awsjavasdk.version}</version>
204204
<scope>test</scope>
205205
</dependency>
206+
<dependency>
207+
<groupId>software.amazon.awssdk</groupId>
208+
<artifactId>apache-client</artifactId>
209+
<version>${awsjavasdk.version}</version>
210+
<scope>test</scope>
211+
</dependency>
206212
<dependency>
207213
<groupId>io.netty</groupId>
208214
<artifactId>netty-transport</artifactId>

services/s3/src/it/java/software/amazon/awssdk/services/s3/ResponseInputStreamTimeoutIntegrationTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121

2222
import java.io.IOException;
2323
import java.time.Duration;
24-
import org.apache.http.conn.ConnectionPoolTimeoutException;
2524
import org.junit.AfterClass;
2625
import org.junit.Before;
2726
import org.junit.BeforeClass;
2827
import org.junit.Test;
2928
import software.amazon.awssdk.core.ResponseInputStream;
3029
import software.amazon.awssdk.core.sync.RequestBody;
3130
import software.amazon.awssdk.core.sync.ResponseTransformer;
32-
import software.amazon.awssdk.http.apache.ApacheHttpClient;
31+
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
3332
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
3433
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
3534
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
@@ -48,7 +47,7 @@ public class ResponseInputStreamTimeoutIntegrationTest extends S3IntegrationTest
4847
@Before
4948
public void init() {
5049
s3Client = s3ClientBuilder()
51-
.httpClientBuilder(ApacheHttpClient.builder().maxConnections(1))
50+
.httpClientBuilder(Apache5HttpClient.builder().maxConnections(1))
5251
.overrideConfiguration(o -> o.retryStrategy(r -> r.maxAttempts(1)))
5352
.build();
5453
}
@@ -74,8 +73,7 @@ public void defaultTimeout_firstStreamNotConsumed_secondRequestTimesOut() {
7473
s3Client.getObject(getObjectRequest);
7574

7675
assertThatThrownBy(() -> s3Client.getObject(getObjectRequest))
77-
.hasRootCauseInstanceOf(ConnectionPoolTimeoutException.class)
78-
.hasMessageContaining("Timeout waiting for connection from pool");
76+
.hasMessageContaining("Timeout deadline");
7977
}
8078

8179
@Test

0 commit comments

Comments
 (0)