当前位置: 首页>>代码示例>>Java>>正文


Java HttpBackOffUnsuccessfulResponseHandler类代码示例

本文整理汇总了Java中com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler的典型用法代码示例。如果您正苦于以下问题:Java HttpBackOffUnsuccessfulResponseHandler类的具体用法?Java HttpBackOffUnsuccessfulResponseHandler怎么用?Java HttpBackOffUnsuccessfulResponseHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpBackOffUnsuccessfulResponseHandler类属于com.google.api.client.http包,在下文中一共展示了HttpBackOffUnsuccessfulResponseHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
private <U, T extends ResponseEnvelope<U>> U execute(final HttpRequest httpRequest, final Class<T> responseType) throws IOException {
   httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
   if (authToken != null) {
      HttpHeaders headers = httpRequest.getHeaders();
      headers.set("X-Auth-Token", authToken);
   }

   HttpResponse httpResponse = httpRequest.execute();
   T response = httpResponse.parseAs(responseType);

   // Update authToken, if necessary
   if (response.getAuthToken() != null) {
      authToken = response.getAuthToken();
   }

   return response.getData();
}
 
开发者ID:scratch-wireless,项目名称:kazoo-client,代码行数:18,代码来源:KazooConnection.java

示例2: CredentialOrBackoffResponseHandler

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
public CredentialOrBackoffResponseHandler() {
  HttpBackOffUnsuccessfulResponseHandler errorCodeHandler =
      new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff());
  errorCodeHandler.setBackOffRequired(
      new HttpBackOffUnsuccessfulResponseHandler.BackOffRequired() {
        @Override
        public boolean isRequired(HttpResponse response) {
          return BASE_HTTP_BACKOFF_REQUIRED.isRequired(response)
              || response.getStatusCode() == STATUS_CODE_TOO_MANY_REQUESTS;
        }
      });
  if (sleeperOverride != null) {
    errorCodeHandler.setSleeper(sleeperOverride);
  }
  this.delegateHandler = errorCodeHandler;
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:17,代码来源:RetryHttpInitializer.java

示例3: setHttpBackoffTimeout

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
private static HttpRequestInitializer setHttpBackoffTimeout(final HttpRequestInitializer requestInitializer,
                                                            final int connectTimeoutMs, final int readTimeoutMs) {
    return new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
            requestInitializer.initialize(httpRequest);

            // Configure exponential backoff on error
            // https://developers.google.com/api-client-library/java/google-http-java-client/backoff
            ExponentialBackOff backoff = new ExponentialBackOff();
            HttpUnsuccessfulResponseHandler backoffHandler = new HttpBackOffUnsuccessfulResponseHandler(backoff)
                    .setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS);
            httpRequest.setUnsuccessfulResponseHandler(backoffHandler);

            httpRequest.setConnectTimeout(connectTimeoutMs);
            httpRequest.setReadTimeout(readTimeoutMs);
        }
    };
}
 
开发者ID:pinterest,项目名称:secor,代码行数:20,代码来源:GsUploadManager.java

示例4: DefaultHttpRequestInitializer

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
DefaultHttpRequestInitializer(GoogleCredential credential, TimeValue connectTimeout, TimeValue readTimeout) {
    this.credential = credential;
    this.connectTimeout = connectTimeout;
    this.readTimeout = readTimeout;
    this.handler = new HttpBackOffUnsuccessfulResponseHandler(newBackOff());
    this.ioHandler = new HttpBackOffIOExceptionHandler(newBackOff());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:GoogleCloudStorageService.java

示例5: sendGCMSync

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
public static boolean sendGCMSync(String userId, String senderId) {
    if(Constants.GCM_API_KEY == null) {
        log.info("GCM not set up, see readme for how to configure");
        return false;
    }
    try {
        GCMMessage message = new GCMMessage(userId);
        log.info("message:" + message);
        log.info("gson:" + gson.toJson(message));
        GenericData body = new GenericData();
        GenericData data = new GenericData();
        body.put("to", "/topics/" + userId);
        if(senderId != null) {
            data.put("senderId",senderId);
            body.put("data", data);
        }

        //why does this only take a generic map?
        HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(GCM_HOST),
                new JsonHttpContent(gsonFactory, body))
                .setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()))
                .setHeaders(new HttpHeaders().setAuthorization("key=" + Constants.GCM_API_KEY));
        request.getContent().writeTo(System.out);
        HttpResponse response = request.execute();
        log.info("response" + response);
        return true;
    } catch(IOException e) {
        log.info("could not send http message:");
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:saucenet,项目名称:sync,代码行数:33,代码来源:Networker.java

示例6: retryRequestInitializer

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
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()));
  };
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:8,代码来源:GoogleCredentials.java

示例7: setHttpTimeout

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
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()));
  };
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:9,代码来源:GoogleCredentials.java

示例8: initialize

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest request) throws IOException {
	request.setInterceptor(credential);

	// Exponential Back-off for 5xx response and 403 rate limit exceeded
	// error
	HttpBackOffUnsuccessfulResponseHandler backOffHandler = getHttpBackOffUnsuccessfulResponseHandler();

	request.setUnsuccessfulResponseHandler(
			new CompositeHttpUnsuccessfulResponseHandler(credential, backOffHandler));

	// Back-off for socket connection error
	request.setIOExceptionHandler(getHttpBackOffIOExceptionHandler());
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:15,代码来源:GDriveBackOffHttpRequestInitializer.java

示例9: getHttpBackOffUnsuccessfulResponseHandler

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
private HttpBackOffUnsuccessfulResponseHandler getHttpBackOffUnsuccessfulResponseHandler() {
	HttpBackOffUnsuccessfulResponseHandler backOffHandler = new HttpBackOffUnsuccessfulResponseHandler(
			new ExponentialBackOff.Builder().setInitialIntervalMillis(200).setMaxElapsedTimeMillis(60000).build());
	backOffHandler.setBackOffRequired(
			(HttpResponse response) -> response.getStatusCode() / 100 == 5 || isRateLimitExceeded(response));
	return backOffHandler;
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:8,代码来源:GDriveBackOffHttpRequestInitializer.java

示例10: getServiceWithRetries

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
Gmail getServiceWithRetries() {
  HttpRequestInitializer httpRequestInitializer =
      request -> {
        credential.initialize(request);
        new UnsuccessfulResponseHandlerChainer().chain(
            request.getUnsuccessfulResponseHandler(),
            new HttpBackOffUnsuccessfulResponseHandler(
                backOffProvider.get()));
      };

  return new Gmail.Builder(httpTransport, jsonFactory, httpRequestInitializer)
      .setApplicationName(GmailServiceModule.APP_NAME)
      .build();
}
 
开发者ID:google,项目名称:mail-importer,代码行数:15,代码来源:GmailService.java

示例11: initialize

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
  httpRequest.setIOExceptionHandler(
      new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
  httpRequest.setUnsuccessfulResponseHandler(
      new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:8,代码来源:CredentialFactory.java

示例12: initialize

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest httpRequest) {
    final HttpUnsuccessfulResponseHandler backoffHandler =
            new HttpBackOffUnsuccessfulResponseHandler(
                    new ExponentialBackOff.Builder()
                            .setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
                            .build())
                    .setSleeper(sleeper);

    httpRequest.setInterceptor(wrappedCredential);
    httpRequest.setUnsuccessfulResponseHandler(
            new HttpUnsuccessfulResponseHandler() {
                int retry = 0;

                @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.debug("Retrying [{}] times : [{}]", retry, request.getUrl());
                        return true;
                    } else {
                        return false;
                    }
                }
            });
    httpRequest.setIOExceptionHandler(
            new HttpBackOffIOExceptionHandler(
                    new ExponentialBackOff.Builder()
                            .setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
                            .build())
                    .setSleeper(sleeper)
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:43,代码来源:RetryHttpInitializerWrapper.java

示例13: main

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	if (args.length != 3) {
		System.out.println("UploadDirs accountname folderid folder");
		return;
	}
	String folderid = args[1];
	String account = args[0];
	String folder = args[2];
	java.io.File jdrivedir = new java.io.File(
			new java.io.File(new java.io.File(
					System.getProperty("user.home")), ".gyingpan"), account);
	jdrivedir.mkdirs();
	HttpTransport httpTransport = new NetHttpTransport();
	JsonFactory jsonFactory = new JacksonFactory();

	GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
			httpTransport, jsonFactory, GDrive.CLIENT_ID,
			GDrive.CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE))
			.setAccessType("offline")
			.setApprovalPrompt("auto")
			.setDataStoreFactory(
					new FileDataStoreFactory(new java.io.File(jdrivedir,
							"driveauth"))).build();
	Credential credential = flow.loadCredential(args[0]);
	Drive service = new Drive.Builder(httpTransport, jsonFactory,
			credential).setHttpRequestInitializer(
			new HttpRequestInitializer() {
				@Override
				public void initialize(HttpRequest request)
						throws IOException {
					credential.initialize(request);
					request.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(
							new ExponentialBackOff()));
					request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(
							new ExponentialBackOff()));
				}
			}).build();
	HashMap<String, File> gfilelist = getGDriveFileList(service, folderid);
	uploadDir(service, gfilelist, folderid,
			new java.io.File(folder).toPath());
}
 
开发者ID:tbutter,项目名称:gyingpan,代码行数:42,代码来源:UploadDir.java

示例14: getConfig

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
/** Publish an event or state message using Cloud IoT Core via the HTTP API. */
public static void getConfig(String urlPath, String token, String projectId,
    String cloudRegion, String registryId, String deviceId, String version)
    throws UnsupportedEncodingException, IOException, JSONException, ProtocolException {
  // Build the resource path of the device that is going to be authenticated.
  String devicePath =
      String.format(
          "projects/%s/locations/%s/registries/%s/devices/%s",
          projectId, cloudRegion, registryId, deviceId);
  urlPath = urlPath + devicePath + "/config?local_version=" + version;

  HttpRequestFactory requestFactory =
      HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest request) {
          request.setParser(new JsonObjectParser(JSON_FACTORY));
        }
      });

  final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl(urlPath));
  HttpHeaders heads = new HttpHeaders();

  heads.setAuthorization(String.format("Bearer %s", token));
  heads.setContentType("application/json; charset=UTF-8");
  heads.setCacheControl("no-cache");

  req.setHeaders(heads);
  ExponentialBackOff backoff = new ExponentialBackOff.Builder()
      .setInitialIntervalMillis(500)
      .setMaxElapsedTimeMillis(900000)
      .setMaxIntervalMillis(6000)
      .setMultiplier(1.5)
      .setRandomizationFactor(0.5)
      .build();
  req.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));
  HttpResponse res = req.execute();
  System.out.println(res.getStatusCode());
  System.out.println(res.getStatusMessage());
  InputStream in = res.getContent();

  System.out.println(CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:43,代码来源:HttpExample.java

示例15: publishMessage

import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; //导入依赖的package包/类
/** Publish an event or state message using Cloud IoT Core via the HTTP API. */
public static void publishMessage(String payload, String urlPath, String messageType,
    String token, String projectId, String cloudRegion, String registryId, String deviceId)
    throws UnsupportedEncodingException, IOException, JSONException, ProtocolException {
  // Build the resource path of the device that is going to be authenticated.
  String devicePath =
      String.format(
          "projects/%s/locations/%s/registries/%s/devices/%s",
          projectId, cloudRegion, registryId, deviceId);
  String urlSuffix = messageType.equals("event") ? "publishEvent" : "setState";

  // Data sent through the wire has to be base64 encoded.
  Base64.Encoder encoder = Base64.getEncoder();

  String encPayload = encoder.encodeToString(payload.getBytes("UTF-8"));

  urlPath = urlPath + devicePath + ":" + urlSuffix;


  final HttpRequestFactory requestFactory =
      HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest request) {
          request.setParser(new JsonObjectParser(JSON_FACTORY));
        }
      });

  HttpHeaders heads = new HttpHeaders();
  heads.setAuthorization(String.format("Bearer %s", token));
  heads.setContentType("application/json; charset=UTF-8");
  heads.setCacheControl("no-cache");

  // Add post data. The data sent depends on whether we're updating state or publishing events.
  JSONObject data = new JSONObject();
  if (messageType.equals("event")) {
    data.put("binary_data", encPayload);
  } else {
    JSONObject state = new JSONObject();
    state.put("binary_data", encPayload);
    data.put("state", state);
  }

  ByteArrayContent content = new ByteArrayContent(
      "application/json", data.toString().getBytes("UTF-8"));

  final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl(urlPath));
  req.setHeaders(heads);
  req.setContent(content);
  req.setRequestMethod("POST");
  ExponentialBackOff backoff = new ExponentialBackOff.Builder()
      .setInitialIntervalMillis(500)
      .setMaxElapsedTimeMillis(900000)
      .setMaxIntervalMillis(6000)
      .setMultiplier(1.5)
      .setRandomizationFactor(0.5)
      .build();
  req.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(backoff));

  HttpResponse res = req.execute();
  System.out.println(res.getStatusCode());
  System.out.println(res.getStatusMessage());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:63,代码来源:HttpExample.java


注:本文中的com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。