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(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { for (HttpUnsuccessfulResponseHandler handler : unsuccessfulResponseHandlers) { if (handler.handleResponse(request, response, supportsRetry)) { return true; } } return false; } };
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { for (HttpUnsuccessfulResponseHandler handler : unsuccessfulResponseHandlers) { if (handler.handleResponse(request, response, supportsRetry)) { return true; } } return false; } };
/** * Returns a new {@link HttpUnsuccessfulResponseHandler} that runs all of * the given handlers in order until one of them returns {@code true}. * * @param handlers the handlers to run. Note that {@code null} values are * skipped. */ public HttpUnsuccessfulResponseHandler chain( HttpUnsuccessfulResponseHandler... handlers) { return (unsuccessfulRequest, response, supportsRetry) -> { boolean retry = false; for (int i = 0; i < handlers.length && !retry; i++) { if (handlers[i] != null) { retry = handlers[i].handleResponse( unsuccessfulRequest, response, supportsRetry); } } return retry; }; } }
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { boolean handled = originalUnsuccessfulHandler != null && originalUnsuccessfulHandler.handleResponse(request, response, supportsRetry); // TODO(peleyal): figure out what is best practice - call serverErrorCallback only if the // abnormal response was handled, or call it regardless if (handled && supportsRetry && response.getStatusCode() / 100 == 5) { try { uploader.serverErrorCallback(); } catch (IOException e) { LOGGER.log(Level.WARNING, "exception thrown while calling server callback", e); } } return handled; } }
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException { String event = logger.isLoggable(INFO) ? String.format( "%s %s for %s", response.getStatusCode(), response.getStatusMessage(), request.getUrl().buildRelativeUrl()) : null; if (supportsRetry) { logger.log(FINE, "Handling {0}", event); boolean retry = delegate.handleResponse(request, response, supportsRetry); logger.log(retry ? INFO : WARNING, retry ? "Retrying {0}" : "Not retrying {0}", event); return retry; } else { logger.log(WARNING, "Unable to retry {0}", event); return false; } } }
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, 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. logger.info("Retrying " + request.getUrl()); return true; } else { return false; } } });
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, 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. logger.info("Retrying " + request.getUrl()); return true; } else { return false; } } });
@Override public boolean handleResponse(HttpRequest request, HttpResponse response, 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. logger.info("Retrying " + request.getUrl()); return true; } else { return false; } } });
@Override public boolean handleResponse( HttpRequest httpRequest, HttpResponse httpResponse, boolean supportsRetry) throws IOException { if (responseCodesToLog.contains(httpResponse.getStatusCode())) { logger.atInfo().log( "Encountered status code %s when accessing URL %s. " + "Delegating to response handler for possible retry.", httpResponse.getStatusCode(), httpRequest.getUrl()); } return delegateResponseHandler.handleResponse(httpRequest, httpResponse, supportsRetry); }
@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; } } });
@Override public boolean handleResponse( HttpRequest httpRequest, HttpResponse httpResponse, boolean supportsRetry) throws IOException { if (responseCodesToLog.contains(httpResponse.getStatusCode())) { logger.atInfo().log( "Encountered status code %s when accessing URL %s. " + "Delegating to response handler for possible retry.", httpResponse.getStatusCode(), httpRequest.getUrl()); } return delegateResponseHandler.handleResponse(httpRequest, httpResponse, supportsRetry); }
if (delegateHandler.handleResponse(request, response, supportsRetry)) {
if (delegateHandler.handleResponse(request, response, supportsRetry)) {
boolean redirectRequest = false; if (unsuccessfulResponseHandler != null) { errorHandled = unsuccessfulResponseHandler.handleResponse( requestInfo.request, response, retrySupported);
/** 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)); } }