Example usage for com.google.common.net HttpHeaders RETRY_AFTER

List of usage examples for com.google.common.net HttpHeaders RETRY_AFTER

Introduction

In this page you can find the example usage for com.google.common.net HttpHeaders RETRY_AFTER.

Prototype

String RETRY_AFTER

To view the source code for com.google.common.net HttpHeaders RETRY_AFTER.

Click Source Link

Document

The HTTP Retry-After header field name.

Usage

From source file:org.apache.jclouds.profitbricks.rest.handlers.ProfitBricksRateLimitRetryHandler.java

@Override
protected Optional<Long> millisToNextAvailableRequest(HttpCommand command, HttpResponse response) {
    String secondsToNextAvailableRequest = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER);
    return secondsToNextAvailableRequest != null
            ? Optional.of(Long.valueOf(secondsToNextAvailableRequest) * 1000)
            : Optional.<Long>absent();
}

From source file:org.jclouds.azurecompute.arm.handlers.AzureRateLimitRetryHandler.java

public static boolean isRateLimitError(HttpResponse response) {
    return response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER) != null;
}

From source file:org.jclouds.azurecompute.arm.handlers.AzureRateLimitRetryHandler.java

@Override
protected Optional<Long> millisToNextAvailableRequest(HttpCommand command, HttpResponse response) {
    String secondsToNextAvailableRequest = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER);
    return secondsToNextAvailableRequest != null
            ? Optional.of(Long.parseLong(secondsToNextAvailableRequest) * 1000)
            : Optional.<Long>absent();
}

From source file:org.jclouds.http.functions.HeaderToRetryAfterException.java

@Override
public Void apply(Throwable in) {
    if (!(in instanceof HttpResponseException))
        return null;
    HttpResponse response = HttpResponseException.class.cast(in).getResponse();
    if (response == null)
        return null;

    // https://tools.ietf.org/html/rfc2616#section-14.37
    String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER);
    if (retryAfter != null) {
        Optional<RetryAfterException> retryException = tryCreateRetryAfterException(in, retryAfter);
        if (retryException.isPresent())
            throw retryException.get();
    }/*  ww w.j  ava 2s.  c o  m*/

    return null;
}

From source file:com.squid.kraken.v4.api.core.ExceptionsMapper.java

public Response toResponse(Throwable ex) {
    APIException apiException;//from   w  w w . j a  v a  2 s.  c  om
    if (ex instanceof WebApplicationException) {
        WebApplicationException wex = ((WebApplicationException) ex);
        if (!(wex.getCause() instanceof APIException)) {
            logger.warn("WebApplicationException", ex);
            return wex.getResponse();
        } else {
            apiException = (APIException) wex.getCause();
        }
    }

    if (ex instanceof APIException) {
        apiException = ((APIException) ex);
        if (apiException.getCode() == 500) {
            logger.warn("API Exception", ex);
        }
    } else {
        apiException = new APIException(ex.getMessage(), ex.getCause(), false);
        logger.warn("System error", ex);
    }

    ResponseBuilder builder = Response.status(apiException.getCode()).entity(apiException)
            .type(MediaType.APPLICATION_JSON);

    // make sure CORS is handled
    builder.header(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS, "false");
    builder.header(CorsHeaderConstants.HEADER_AC_ALLOW_ORIGIN, "*");

    // check if retry-after header should be honored
    if (apiException instanceof ComputingInProgressAPIException) {
        Integer retryAfter = ((ComputingInProgressAPIException) apiException).getRetryAfter();
        if (retryAfter != null) {
            builder.header(HttpHeaders.RETRY_AFTER, retryAfter);
        }
    }

    return builder.build();
}

From source file:org.jclouds.fallbacks.HeaderToRetryAfterException.java

@Override
public ListenableFuture<Object> create(Throwable t) {
    if (!(t instanceof HttpResponseException))
        throw propagate(t);
    HttpResponse response = HttpResponseException.class.cast(t).getResponse();
    if (response == null)
        return immediateFuture(null);

    // https://tools.ietf.org/html/rfc2616#section-14.37
    String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER);
    if (retryAfter != null) {
        Optional<RetryAfterException> retryException = tryCreateRetryAfterException(t, retryAfter);
        if (retryException.isPresent())
            throw retryException.get();
    }/*from ww w  . ja  v  a2s. c  om*/

    return immediateFuture(null);
}