Skip to content

Commit 14a2ead

Browse files
committed
disableAutomaticRetries in Apache 5.x since SDK handles retries , also define Apache5 dependencies in .brazil.json
1 parent 8b83790 commit 14a2ead

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.brazil.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@
141141
"io.netty:netty-transport-classes-epoll": { "packageName": "Netty4", "packageVersion": "4.1" },
142142
"io.netty:netty-transport-native-unix-common": { "packageName": "Netty4", "packageVersion": "4.1" },
143143
"org.apache.httpcomponents:httpclient": { "packageName": "Apache-HttpComponents-HttpClient", "packageVersion": "4.5.x" },
144+
"org.apache.httpcomponents.client5:httpclient5": { "packageName": "Apache-HttpComponents-HttpClient5", "packageVersion": "5.0.x" },
144145
"org.apache.httpcomponents:httpcore": { "packageName": "Apache-HttpComponents-HttpCore", "packageVersion": "4.4.x" },
146+
"org.apache.httpcomponents.core5:httpcore5": { "packageName": "Apache-HttpComponents-HttpCore5", "packageVersion": "5.0.x" },
145147
"org.eclipse.jdt:org.eclipse.jdt.core": { "packageName": "AwsJavaSdk-Codegen-EclipseJdtDependencies", "packageVersion": "2.0" },
146148
"org.eclipse.text:org.eclipse.text": { "packageName": "AwsJavaSdk-Codegen-EclipseJdtDependencies", "packageVersion": "2.0" },
147149
"org.reactivestreams:reactive-streams": { "packageName": "Maven-org-reactivestreams_reactive-streams", "packageVersion": "1.x" },

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ private ConnectionManagerAwareHttpClient createClient(Apache5HttpClient.DefaultB
166166
.setUserAgent("") // SDK will set the user agent header in the pipeline. Don't let Apache waste time
167167
.setConnectionManager(ClientConnectionManagerFactory.wrap(cm))
168168
//This is done to keep backward compatibility with Apache 4.x
169-
.disableRedirectHandling();
169+
.disableRedirectHandling()
170+
// SDK handles retries , we do not need additional retries on Http clients.
171+
.disableAutomaticRetries();
170172

171173
addProxyConfig(builder, configuration);
172174

test/http-client-tests/src/main/java/software/amazon/awssdk/http/SdkHttpClientTestSuite.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static com.github.tomakehurst.wiremock.client.WireMock.any;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
2222
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
23+
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
24+
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
2325
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
2426
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2527
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
@@ -59,6 +61,7 @@ public abstract class SdkHttpClientTestSuite {
5961
private static final Logger LOG = Logger.loggerFor(SdkHttpClientTestSuite.class);
6062

6163
private static final ConnectionCountingTrafficListener CONNECTION_COUNTER = new ConnectionCountingTrafficListener();
64+
private static final int HTTP_TOO_MANY_REQUESTS = 429;
6265

6366
@Rule
6467
public WireMockRule mockServer = createWireMockRule();
@@ -218,6 +221,47 @@ public void testCustomTlsTrustManagerAndTrustAllFails() throws Exception {
218221
assertThatThrownBy(() -> createSdkHttpClient(httpClientOptions)).isInstanceOf(IllegalArgumentException.class);
219222
}
220223

224+
@Test
225+
public void doesNotRetryOn429StatusCode() throws Exception {
226+
SdkHttpClientOptions httpClientOptions = new SdkHttpClientOptions();
227+
httpClientOptions.trustAll(true);
228+
try (SdkHttpClient client = createSdkHttpClient(httpClientOptions)) {
229+
stubForMockRequest(HTTP_TOO_MANY_REQUESTS);
230+
SdkHttpFullRequest req = mockSdkRequest("http://localhost:" + mockServer.port(), SdkHttpMethod.POST);
231+
HttpExecuteResponse response = client.prepareRequest(HttpExecuteRequest.builder()
232+
.request(req)
233+
.contentStreamProvider(req.contentStreamProvider().orElse(null))
234+
.build())
235+
.call();
236+
// Drain the response body if present
237+
response.responseBody().ifPresent(IoUtils::drainInputStream);
238+
239+
// Verify the response has 429 status code
240+
assertThat(response.httpResponse().statusCode()).isEqualTo(429);
241+
242+
// Verify that the request was made exactly once (no retries)
243+
mockServer.verify(1, postRequestedFor(urlEqualTo("/"))
244+
.withHeader("Host", containing("localhost")));
245+
246+
// Reset and make another request to ensure it's not a connection issue
247+
mockServer.resetAll();
248+
stubForMockRequest(200);
249+
HttpExecuteResponse successResponse = client.prepareRequest(HttpExecuteRequest.builder()
250+
.request(req)
251+
.contentStreamProvider(req.contentStreamProvider().orElse(null))
252+
.build())
253+
.call();
254+
successResponse.responseBody().ifPresent(IoUtils::drainInputStream);
255+
256+
// Verify the second request succeeded
257+
assertThat(successResponse.httpResponse().statusCode()).isEqualTo(200);
258+
259+
// Verify only one request was made for each call (no retries)
260+
mockServer.verify(1, postRequestedFor(urlEqualTo("/")));
261+
}
262+
}
263+
264+
221265
protected void testForResponseCode(int returnCode) throws Exception {
222266
testForResponseCode(returnCode, SdkHttpMethod.POST);
223267
}

0 commit comments

Comments
 (0)