com.google.api.client.http.HttpRequest.setUnsuccessfulResponseHandler()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中com.google.api.client.http.HttpRequest.setUnsuccessfulResponseHandler()方法的一些代码示例,展示了HttpRequest.setUnsuccessfulResponseHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.setUnsuccessfulResponseHandler()方法的具体详情如下:
包路径:com.google.api.client.http.HttpRequest
类名称:HttpRequest
方法名:setUnsuccessfulResponseHandler

HttpRequest.setUnsuccessfulResponseHandler介绍

暂无

代码示例

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()).setSleeper(sleeper);
request.setInterceptor(wrappedCredential);
request.setUnsuccessfulResponseHandler(
  new HttpUnsuccessfulResponseHandler() {
   public boolean handleResponse(

代码示例来源:origin: com.google.oauth-client/google-oauth-client-servlet

public void initialize(HttpRequest request) throws IOException {
 authorizer.initialize(request);
 request.setUnsuccessfulResponseHandler(this);
}

代码示例来源:origin: com.google.oauth-client/google-oauth-client-extensions

public void initialize(HttpRequest request) throws IOException {
 authorizer.initialize(request);
 request.setUnsuccessfulResponseHandler(this);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core

@Override
public void initialize(HttpRequest httpRequest) throws IOException {
 httpRequest.setUnsuccessfulResponseHandler(new NullCredentialHttpUnsuccessfulResponseHandler());
}

代码示例来源:origin: com.google.oauth-client/google-oauth-client-extensions

public void initialize(HttpRequest request) throws IOException {
 request.setInterceptor(authInterceptor);
 request.setUnsuccessfulResponseHandler(authInterceptor);
}

代码示例来源:origin: com.google.oauth-client/google-oauth-client-extensions

public void initialize(HttpRequest request) throws IOException {
 checkIntializationStatus();
 request.setInterceptor(authInterceptor);
 request.setUnsuccessfulResponseHandler(authInterceptor);
}

代码示例来源:origin: com.google.oauth-client/google-oauth-client-extensions

public void initialize(HttpRequest request) throws IOException {
 checkIntializationStatus();
 request.setInterceptor(authInterceptor);
 request.setUnsuccessfulResponseHandler(authInterceptor);
}

代码示例来源:origin: com.google.api-client/google-api-client-android

@Override
public void initialize(HttpRequest request) {
 RequestHandler handler = new RequestHandler();
 request.setInterceptor(handler);
 request.setUnsuccessfulResponseHandler(handler);
}

代码示例来源:origin: spinnaker/halyard

public static HttpRequestInitializer retryRequestInitializer() {
 return request -> {
  request.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(2));
  request.setReadTimeout((int) TimeUnit.MINUTES.toMillis(2));
  request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
 };
}

代码示例来源:origin: spinnaker/halyard

public static HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
  return request -> {
   requestInitializer.initialize(request);
   request.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(2));
   request.setReadTimeout((int) TimeUnit.MINUTES.toMillis(2));
   request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
  };
 }
}

代码示例来源:origin: com.google.api-client/google-api-client

/**
 * Constructs a new instance from {@link MediaHttpUploader} and {@link HttpRequest}.
 */
public MediaUploadErrorHandler(MediaHttpUploader uploader, HttpRequest request) {
 this.uploader = Preconditions.checkNotNull(uploader);
 originalIOExceptionHandler = request.getIOExceptionHandler();
 originalUnsuccessfulHandler = request.getUnsuccessfulResponseHandler();
 request.setIOExceptionHandler(this);
 request.setUnsuccessfulResponseHandler(this);
}

代码示例来源:origin: com.google.enterprise.cloudsearch/google-cloudsearch-connector-sdk

/** Initialize {@link HttpRequest} to setup exponential back off and automatic retries. */
 @Override
 public void initialize(HttpRequest request) throws IOException {
  BackOff backOff = new ExponentialBackOff();
  request.setUnsuccessfulResponseHandler(new LoggingResponseHandler(retryPolicy, backOff));
  request.setIOExceptionHandler(new LoggingIOExceptionHandler(backOff));
 }
}

代码示例来源:origin: googleapis/google-auth-library-java

/**
 * {@inheritDoc}
 *
 * Initialize the HTTP request prior to execution.
 *
 * @param request HTTP request
 */
@Override
public void initialize(HttpRequest request) throws IOException {
 request.setUnsuccessfulResponseHandler(this);
 if (!credentials.hasRequestMetadata()) {
  return;
 }
 HttpHeaders requestHeaders = request.getHeaders();
 URI uri = null;
 if (request.getUrl() != null) {
  uri = request.getUrl().toURI();
 }
 Map<String, List<String>> credentialHeaders = credentials.getRequestMetadata(uri);
 if (credentialHeaders == null) {
  return;
 }
 for (Map.Entry<String, List<String>> entry : credentialHeaders.entrySet()) {
  String headerName = entry.getKey();
  List<String> requestValues = new ArrayList<>();
  requestValues.addAll(entry.getValue());
  requestHeaders.put(headerName, requestValues);
 }
}

代码示例来源:origin: com.google.auth/google-auth-library-oauth2-http

/**
 * {@inheritDoc}
 *
 * Initialize the HTTP request prior to execution.
 *
 * @param request HTTP request
 */
@Override
public void initialize(HttpRequest request) throws IOException {
 request.setUnsuccessfulResponseHandler(this);
 if (!credentials.hasRequestMetadata()) {
  return;
 }
 HttpHeaders requestHeaders = request.getHeaders();
 URI uri = null;
 if (request.getUrl() != null) {
  uri = request.getUrl().toURI();
 }
 Map<String, List<String>> credentialHeaders = credentials.getRequestMetadata(uri);
 if (credentialHeaders == null) {
  return;
 }
 for (Map.Entry<String, List<String>> entry : credentialHeaders.entrySet()) {
  String headerName = entry.getKey();
  List<String> requestValues = new ArrayList<>();
  requestValues.addAll(entry.getValue());
  requestHeaders.put(headerName, requestValues);
 }
}

代码示例来源:origin: com.google.cloud.bigdataoss/util

@Override
 public void initialize(HttpRequest httpRequest) throws IOException {
  httpRequest.setIOExceptionHandler(
    new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
  httpRequest.setUnsuccessfulResponseHandler(
    new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
 }
}

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

@Override
 public void initialize(HttpRequest httpRequest) throws IOException {
  httpRequest.setIOExceptionHandler(
    new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
  httpRequest.setUnsuccessfulResponseHandler(
    new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
 }
}

代码示例来源:origin: codice/ddf

private HttpRequest generateHttpRequest(
  PropertyResolver propertyResolver, HttpTransport httpTransport) throws IOException {
 HttpRequest httpRequest =
   httpTransport
     .createRequestFactory()
     .buildGetRequest(new GenericUrl(propertyResolver.getResolvedString()));
 httpRequest.setUnsuccessfulResponseHandler(
   new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff())
     .setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS));
 httpRequest.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
 return httpRequest;
}

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

exceptionHandler,
    ImmutableSet.of(HttpStatus.SC_GONE, HttpStatus.SC_SERVICE_UNAVAILABLE));
request.setUnsuccessfulResponseHandler(loggingResponseHandler);
request.setIOExceptionHandler(loggingResponseHandler);

代码示例来源:origin: org.apache.beam/beam-examples-java

/** 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));
 }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core

@Override
public void initialize(HttpRequest request) throws IOException {
 // Set a timeout for hanging-gets.
 // TODO: Do this exclusively for work requests.
 request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000);
 request.setWriteTimeout(this.writeTimeout);
 LoggingHttpBackOffHandler loggingHttpBackOffHandler =
   new LoggingHttpBackOffHandler(
     sleeper,
     // Back off on retryable http errors and IOExceptions.
     // A back-off multiplier of 2 raises the maximum request retrying time
     // to approximately 5 minutes (keeping other back-off parameters to
     // their default values).
     new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
     new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
     ignoredResponseCodes);
 request.setUnsuccessfulResponseHandler(loggingHttpBackOffHandler);
 request.setIOExceptionHandler(loggingHttpBackOffHandler);
 // Set response initializer
 if (responseInterceptor != null) {
  request.setResponseInterceptor(responseInterceptor);
 }
}

相关文章