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

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

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

HttpResponse.isSuccessStatusCode介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-druid

public boolean exists(final String bucket, final String path)
{
 try {
  return storage.objects().get(bucket, path).executeUsingHead().isSuccessStatusCode();
 }
 catch (Exception e) {
  return false;
 }
}

代码示例来源:origin: stackoverflow.com

File mediaFile = new File("/tmp/Test.jpg");
InputStreamContent mediaContent =
  new InputStreamContent("image/jpeg",
    new BufferedInputStream(new FileInputStream(mediaFile)));
mediaContent.setLength(mediaFile.length());

MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, transport, httpRequestInitializer);
uploader.setProgressListener(new CustomProgressListener());
HttpResponse response = uploader.upload(requestUrl);
if (!response.isSuccessStatusCode()) {
 throw GoogleJsonResponseException(jsonFactory, response);
}

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

@Override
 public boolean handleResponse(
   HttpRequest httpRequest, HttpResponse httpResponse, boolean supportsRetry)
   throws IOException {
  if (!httpResponse.isSuccessStatusCode() && httpResponse.getStatusCode() == ACCESS_DENIED) {
   throwNullCredentialException();
  }
  return supportsRetry;
 }
}

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

public void interceptResponse(HttpResponse response) throws IOException {
  if (responseInterceptor != null) {
   responseInterceptor.interceptResponse(response);
  }
  if (!response.isSuccessStatusCode() && httpRequest.getThrowExceptionOnExecuteError()) {
   throw newExceptionOnError(response);
  }
 }
});

代码示例来源:origin: siom79/jdrivesync

private Range requestStatus(HttpRequestFactory requestFactory, GenericUrl uploadUri, File fileToUpload) throws IOException {
  HttpRequest httpRequest = createHttpRequest(requestFactory, HttpMethods.PUT, uploadUri, new EmptyContent());
  httpRequest.getHeaders().setContentRange("*/" + fileToUpload.length());
  LOGGER.log(Level.FINE, "Executing status request.");
  HttpResponse httpResponse = executeHttpRequest(httpRequest);
  if(!httpResponse.isSuccessStatusCode()) {
    throw new IOException("Status request was not successful. Status-Code: " + httpResponse.getStatusCode());
  }
  String range = httpResponse.getHeaders().getRange();
  return Range.valueOf(range);
}

代码示例来源:origin: com.google.apis/google-api-services-datastore-protobuf

/**
 * Clears all data in the Datastore.
 *
 * @throws LocalDevelopmentDatastoreException
 */
public void clear() throws LocalDevelopmentDatastoreException {
 HttpRequestFactory client = remoteRpc.getHttpRequestFactory();
 try {
  Map<String, String> params = new HashMap<String, String>();
  params.put("action", "Clear Datastore");
  UrlEncodedContent content = new UrlEncodedContent(params);
  GenericUrl url = new GenericUrl(host + "/_ah/admin/datastore");
  HttpResponse httpResponse = client.buildPostRequest(url, content).execute();
  if (!httpResponse.isSuccessStatusCode()) {
   throw new LocalDevelopmentDatastoreException(
     "Clear Datastore returned http status " + httpResponse.getStatusCode());
  }
 } catch (IOException e) {
  throw new LocalDevelopmentDatastoreException(
    "Exception trying to clear the dev datastore", e);
 }
}

代码示例来源:origin: com.google.cloud.datastore/datastore-v1beta3-proto-client

/**
 * Clears all data in the Datastore.
 *
 * @throws LocalDevelopmentDatastoreException
 */
public void clear() throws LocalDevelopmentDatastoreException {
 HttpRequestFactory client = remoteRpc.getHttpRequestFactory();
 try {
  Map<String, String> params = new HashMap<String, String>();
  params.put("action", "Clear Datastore");
  UrlEncodedContent content = new UrlEncodedContent(params);
  GenericUrl url = new GenericUrl(host + "/_ah/admin/datastore");
  HttpResponse httpResponse = client.buildPostRequest(url, content).execute();
  if (!httpResponse.isSuccessStatusCode()) {
   throw new LocalDevelopmentDatastoreException(
     "Clear Datastore returned http status " + httpResponse.getStatusCode());
  }
 } catch (IOException e) {
  throw new LocalDevelopmentDatastoreException(
    "Exception trying to clear the dev datastore", e);
 }
}

代码示例来源:origin: siom79/jdrivesync

private String requestUploadLocation(java.io.File fileToUpload, String mimeType, HttpRequestFactory requestFactory, com.google.api.services.drive.model.File remoteFile) throws IOException {
  GenericUrl initializationUrl = new GenericUrl("https://www.googleapis.com/upload/drive/v2/files");
  initializationUrl.put("uploadType", "resumable");
  HttpRequest httpRequest = createHttpRequest(requestFactory, HttpMethods.POST, initializationUrl, new JsonHttpContent(DriveFactory.getJsonFactory(), remoteFile));
  HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.put("X-Upload-Content-Type", mimeType);
  httpHeaders.put("X-Upload-Content-Length", fileToUpload.length());
  httpRequest.getHeaders().putAll(httpHeaders);
  LOGGER.log(Level.FINE, "Executing initial upload location request.");
  HttpResponse httpResponse = executeHttpRequest(httpRequest);
  if(!httpResponse.isSuccessStatusCode()) {
    throw new IOException("Request for upload location was not successful. Status-Code: " + httpResponse.getStatusCode());
  }
  String location = httpResponse.getHeaders().getLocation();
  LOGGER.log(Level.FINE, "URL for resumable upload: " + location);
  return location;
}

代码示例来源:origin: com.google.cloud.datastore/datastore-v1beta3-proto-client

void stopDatastoreInternal() throws LocalDevelopmentDatastoreException {
 // No need to kill the process we started, this function will take care of it.
 HttpRequestFactory client = remoteRpc.getHttpRequestFactory();
 Map<String, String> params = new HashMap<String, String>();
 UrlEncodedContent content = new UrlEncodedContent(params);
 GenericUrl url = new GenericUrl(host + "/_ah/admin/quit");
 try {
  HttpResponse httpResponse = client.buildPostRequest(url, content).execute();
  if (!httpResponse.isSuccessStatusCode()) {
   throw new LocalDevelopmentDatastoreException(
     "Request to shutdown local datastore returned http error code "
     + httpResponse.getStatusCode());
  }
 } catch (IOException e) {
  throw new LocalDevelopmentDatastoreException(
    "Exception trying to stop the dev datastore", e);
 }
}

代码示例来源:origin: deric/gitlab-ci-mesos

@Override
public void registerRunner() throws IOException {
  Registration reg = new Registration();
  reg.token = config.getNextToken();
  reg.publicKey = config.getPublicKey();
  JsonHttpContent content = new JsonHttpContent(JSON_FACTORY, reg);
  HttpRequest request = requestFactory.buildPostRequest(registerUrl, content);
  logger.log(Level.INFO, "trying to register runner at {0}", registerUrl.toString());
  RegistrationToken regToken = null;
  try {
    HttpResponse response = request.execute();
    if (response.isSuccessStatusCode()) {
      //content(response);
      regToken = response.parseAs(RegistrationToken.class);
    } else {
      logger.log(Level.SEVERE, "failed to register as gilab runner at {0}", registerUrl.toString());
    }
  } catch (HttpResponseException ex) {
    logger.log(Level.SEVERE, "failed to register gilab runner  with token = '{2}' at {0}, "
        + "because of {1}", new Object[]{registerUrl.toString(), ex.getMessage(), reg.token});
  }
  if (regToken == null || regToken.id == 0) {
    throw new IOException("failed to register gilab runner");
  }
  config.setToken(regToken.token);
  logger.log(Level.INFO, "registered runner with ID = {0}", regToken.id);
  config.saveConfig();
}

代码示例来源:origin: com.google.apis/google-api-services-datastore-protobuf

void stopDatastoreInternal() throws LocalDevelopmentDatastoreException {
 // No need to kill the process we started, this function will take care of it.
 HttpRequestFactory client = remoteRpc.getHttpRequestFactory();
 Map<String, String> params = new HashMap<String, String>();
 UrlEncodedContent content = new UrlEncodedContent(params);
 GenericUrl url = new GenericUrl(host + "/_ah/admin/quit");
 try {
  HttpResponse httpResponse = client.buildPostRequest(url, content).execute();
  if (!httpResponse.isSuccessStatusCode()) {
   throw new LocalDevelopmentDatastoreException(
     "Request to shutdown local datastore returned http error code "
     + httpResponse.getStatusCode());
  }
 } catch (IOException e) {
  throw new LocalDevelopmentDatastoreException(
    "Exception trying to stop the dev datastore", e);
 }
}

代码示例来源:origin: com.google.cloud.datastore/datastore-v1beta3-proto-client

if (!httpResponse.isSuccessStatusCode()) {
 throw makeException(url, methodName, httpResponse.getContent(),
   httpResponse.getContentType(), httpResponse.getContentCharset(), null,

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

if (!originalThrowExceptionOnExecuteError || response.isSuccessStatusCode()) {
 return response;

代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client

if (!httpResponse.isSuccessStatusCode()) {
 try (InputStream content = GzipFixingInputStream.maybeWrap(httpResponse.getContent())) {
  throw makeException(url, methodName, content,

代码示例来源:origin: GoogleCloudPlatform/google-cloud-datastore

if (!httpResponse.isSuccessStatusCode()) {
 try (InputStream content = GzipFixingInputStream.maybeWrap(httpResponse.getContent())) {
  throw makeException(url, methodName, content,

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

String detailString = null;
try {
 if (!response.isSuccessStatusCode()
   && HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, response.getContentType())
   && response.getContent() != null) {

代码示例来源:origin: siom79/jdrivesync

try {
  httpResponse = executeHttpRequest(httpRequest);
  if (!httpResponse.isSuccessStatusCode()) {
    Range rangeResponse = executeWithRetry(options, () -> requestStatus(requestFactory, uploadUrl, fileToUpload));
    Range range = new Range(rangeResponse.getEnd() + 1, rangeResponse.getEnd() + DEFAULT_CHUNK_SIZE, fileLength);

代码示例来源:origin: googleapis/gax-java

@Override
public void run() {
 try {
  HttpRequest httpRequest = createHttpRequest();
  HttpResponse httpResponse = httpRequest.execute();
  if (!httpResponse.isSuccessStatusCode()) {
   ApiExceptionFactory.createException(
     null,
     HttpJsonStatusCode.of(httpResponse.getStatusCode(), httpResponse.getStatusMessage()),
     false);
  }
  if (getApiMethodDescriptor().getResponseParser() != null) {
   ResponseT response =
     getApiMethodDescriptor().getResponseParser().parse(httpResponse.getContent());
   getResponseFuture().set(response);
  } else {
   getResponseFuture().set(null);
  }
 } catch (Exception e) {
  getResponseFuture().setException(e);
 }
}

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

@Override
public void run() {
 try {
  HttpRequest httpRequest = createHttpRequest();
  HttpResponse httpResponse = httpRequest.execute();
  if (!httpResponse.isSuccessStatusCode()) {
   ApiExceptionFactory.createException(
     null,
     HttpJsonStatusCode.of(httpResponse.getStatusCode(), httpResponse.getStatusMessage()),
     false);
  }
  if (getApiMethodDescriptor().getResponseParser() != null) {
   ResponseT response =
     getApiMethodDescriptor().getResponseParser().parse(httpResponse.getContent());
   getResponseFuture().set(response);
  } else {
   getResponseFuture().set(null);
  }
 } catch (Exception e) {
  getResponseFuture().setException(e);
 }
}

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

/**
 * Sends the metadata request using the given request method to the server and returns the raw
 * metadata {@link HttpResponse}.
 */
private HttpResponse executeUnparsed(boolean usingHead) throws IOException {
 HttpResponse response;
 if (uploader == null) {
  // normal request (not upload)
  response = buildHttpRequest(usingHead).execute();
 } else {
  // upload request
  GenericUrl httpRequestUrl = buildHttpRequestUrl();
  HttpRequest httpRequest = getAbstractGoogleClient()
    .getRequestFactory().buildRequest(requestMethod, httpRequestUrl, httpContent);
  boolean throwExceptionOnExecuteError = httpRequest.getThrowExceptionOnExecuteError();
  response = uploader.setInitiationHeaders(requestHeaders)
    .setDisableGZipContent(disableGZipContent).upload(httpRequestUrl);
  response.getRequest().setParser(getAbstractGoogleClient().getObjectParser());
  // process any error
  if (throwExceptionOnExecuteError && !response.isSuccessStatusCode()) {
   throw newExceptionOnError(response);
  }
 }
 // process response
 lastResponseHeaders = response.getHeaders();
 lastStatusCode = response.getStatusCode();
 lastStatusMessage = response.getStatusMessage();
 return response;
}

相关文章