AWSClientErrorRetryHandler implements HttpRetryHandler { @Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getStatusCode() == 400 || response.getStatusCode() == 403 || response.getStatusCode() == 409) { if (response.getPayload() != null) { closeClientButKeepContentStream(response); AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response); if (error != null) { return shouldRetryRequestOnError(command, response, error); } } } return false; } @Inject  AWSClientErrorRetryHandler(AWSUtils utils, BackoffLimitedRetryHandler backoffLimitedRetryHandler,
         @ClientError Set<String> retryableCodes); @Override boolean shouldRetryRequest(HttpCommand command, HttpResponse response);  }
@Test public void test401DoesNotRetry() { AWSUtils utils = createMock(AWSUtils.class); BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class); HttpCommand command = createMock(HttpCommand.class); replay(utils, backoffLimitedRetryHandler, command); AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, ImmutableSet.<String> of()); assert !retry.shouldRetryRequest(command, HttpResponse.builder().statusCode(UNAUTHORIZED.getStatusCode()).build()); verify(utils, backoffLimitedRetryHandler, command); }
@Test(dataProvider = "codes") public void test409DoesBackoffAndRetryForCode(String code) { AWSUtils utils = createMock(AWSUtils.class); BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class); HttpCommand command = createMock(HttpCommand.class); HttpRequest putBucket = HttpRequest.builder().method(PUT) .endpoint("https: HttpResponse operationAborted = HttpResponse.builder().statusCode(CONFLICT.getStatusCode()) .payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build(); expect(command.getCurrentRequest()).andReturn(putBucket); AWSError error = new AWSError(); error.setCode(code); expect(utils.parseAWSErrorFromContent(putBucket, operationAborted)).andReturn(error); expect(backoffLimitedRetryHandler.shouldRetryRequest(command, operationAborted)).andReturn(Boolean.TRUE); replay(utils, backoffLimitedRetryHandler, command); AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, ImmutableSet.<String> of("RequestTimeout", "OperationAborted", "SignatureDoesNotMatch")); assert retry.shouldRetryRequest(command, operationAborted); verify(utils, backoffLimitedRetryHandler, command); }