Java Code Examples for com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler#setBackOffRequired()

The following examples show how to use com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler#setBackOffRequired() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleUtils.java    From kork with Apache License 2.0 5 votes vote down vote up
static HttpRequestInitializer setTimeoutsAndRetryBehavior(final GoogleCredentials credentials) {
  return new HttpCredentialsAdapter(credentials) {
    public void initialize(HttpRequest request) throws IOException {
      super.initialize(request);
      request.setConnectTimeout(CONNECT_TIMEOUT);
      request.setReadTimeout(READ_TIMEOUT);
      HttpBackOffUnsuccessfulResponseHandler unsuccessfulResponseHandler =
          new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff());
      unsuccessfulResponseHandler.setBackOffRequired(
          HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ON_SERVER_ERROR);
      request.setUnsuccessfulResponseHandler(unsuccessfulResponseHandler);
    }
  };
}
 
Example 2
Source File: RetryHttpInitializer.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
public CredentialOrBackoffResponseHandler() {
  HttpBackOffUnsuccessfulResponseHandler errorCodeHandler =
      new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff());
  errorCodeHandler.setBackOffRequired(
      response ->
          BASE_HTTP_BACKOFF_REQUIRED.isRequired(response)
              || response.getStatusCode() == HTTP_SC_TOO_MANY_REQUESTS);
  if (sleeperOverride != null) {
    errorCodeHandler.setSleeper(sleeperOverride);
  }
  this.delegateHandler = errorCodeHandler;
}
 
Example 3
Source File: HttpEventPublisher.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
/**
 * Executes a POST for the list of {@link SplunkEvent} objects into Splunk's Http Event Collector
 * endpoint.
 *
 * @param events List of {@link SplunkEvent}s
 * @return {@link HttpResponse} for the POST.
 */
public HttpResponse execute(List<SplunkEvent> events) throws IOException {

  HttpContent content = getContent(events);
  HttpRequest request = requestFactory().buildPostRequest(genericUrl(), content);

  HttpBackOffUnsuccessfulResponseHandler responseHandler =
      new HttpBackOffUnsuccessfulResponseHandler(getConfiguredBackOff());

  responseHandler.setBackOffRequired(BackOffRequired.ON_SERVER_ERROR);

  request.setUnsuccessfulResponseHandler(responseHandler);
  setHeaders(request, token());

  return request.execute();
}
 
Example 4
Source File: HttpEventPublisher.java    From beam with Apache License 2.0 4 votes vote down vote up
/**
 * Executes a POST for the list of {@link SplunkEvent} objects into Splunk's Http Event Collector
 * endpoint.
 *
 * @param events list of {@link SplunkEvent}s
 * @return {@link HttpResponse} for the POST
 */
HttpResponse execute(List<SplunkEvent> events) throws IOException {

  HttpContent content = getContent(events);
  HttpRequest request = requestFactory().buildPostRequest(genericUrl(), content);

  HttpBackOffUnsuccessfulResponseHandler responseHandler =
      new HttpBackOffUnsuccessfulResponseHandler(getConfiguredBackOff());

  responseHandler.setBackOffRequired(BackOffRequired.ON_SERVER_ERROR);

  request.setUnsuccessfulResponseHandler(responseHandler);
  setHeaders(request, token());

  return request.execute();
}