public boolean handleResponse( final HttpRequest request, final HttpResponse response, final boolean supportsRetry) throws IOException { if (wrappedCredential.handleResponse(request, response, supportsRetry)) { // If credential decides it can handle it, the return code or message indicated // something specific to authentication, and no backoff is desired. return true; } else if (backoffHandler.handleResponse(request, response, supportsRetry)) { // Otherwise, we defer to the judgement of our internal backoff handler. LOG.info("Retrying " + request.getUrl().toString()); return true; } else { return false; } } });
@Override public boolean handleResponse( final HttpRequest request, final HttpResponse response, final boolean supportsRetry) throws IOException { if (wrappedCredential.handleResponse( request, response, supportsRetry)) { // If credential decides it can handle it, // the return code or message indicated // something specific to authentication, // and no backoff is desired. return true; } else if (backoffHandler.handleResponse( request, response, supportsRetry)) { // Otherwise, we defer to the judgement of // our internal backoff handler. LOG.info("Retrying " + request.getUrl().toString()); return true; } else { return false; } } });
.thenReturn(code) .thenReturn(200); when(mockCredential.handleResponse(eq(req), any(HttpResponse.class), eq(true))) .thenReturn(false); verify(mockLowLevelRequest, times(2)).execute(); verify(mockLowLevelResponse, times(2)).getStatusCode(); verify(mockCredential).handleResponse(eq(req), any(HttpResponse.class), eq(true)); verify(mockSleeper).sleep(any(Long.class));
.thenReturn(403) .thenReturn(200); when(mockCredential.handleResponse(eq(req), any(HttpResponse.class), eq(true))) .thenReturn(true); verify(mockLowLevelRequest, times(2)).execute(); verify(mockLowLevelResponse, times(2)).getStatusCode(); verify(mockCredential).handleResponse(eq(req), any(HttpResponse.class), eq(true));
when(mockLowLevelResponse.getStatusCode()) .thenReturn(200); when(mockCredential.handleResponse(eq(req), any(HttpResponse.class), eq(true))) .thenReturn(false);
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { if (credential.handleResponse(request, response, supportsRetry)) {
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { if (credential.handleResponse(request, response, supportsRetry)) {
/** Initializes the given request. */ @Override public final void initialize(final HttpRequest request) { request.setReadTimeout(2 * ONEMINITUES); // 2 minutes read timeout final HttpUnsuccessfulResponseHandler backoffHandler = new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()).setSleeper(sleeper); request.setInterceptor(wrappedCredential); request.setUnsuccessfulResponseHandler( (request1, response, supportsRetry) -> { if (wrappedCredential.handleResponse(request1, response, supportsRetry)) { // If credential decides it can handle it, the return code or message indicated // something specific to authentication, and no backoff is desired. return true; } else if (backoffHandler.handleResponse(request1, response, supportsRetry)) { // Otherwise, we defer to the judgement of our internal backoff handler. LOG.info("Retrying " + request1.getUrl().toString()); return true; } else { return false; } }); request.setIOExceptionHandler( new HttpBackOffIOExceptionHandler(new ExponentialBackOff()).setSleeper(sleeper)); } }