當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponseException.getStatusCode方法代碼示例

本文整理匯總了Java中com.google.api.client.http.HttpResponseException.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponseException.getStatusCode方法的具體用法?Java HttpResponseException.getStatusCode怎麽用?Java HttpResponseException.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.http.HttpResponseException的用法示例。


在下文中一共展示了HttpResponseException.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * @deprecated As of xero-java-sdk version 0.6.0, to be removed
 * in favour of {@link XeroExceptionHandler#convertException(IOException)}
 */
protected RuntimeException convertException(IOException ioe) {
    if (ioe instanceof HttpResponseException) {
        HttpResponseException googleException = (HttpResponseException) ioe;

        if (googleException.getStatusCode() == 400 ||
            googleException.getStatusCode() == 401 ||
            googleException.getStatusCode() == 404 ||
            googleException.getStatusCode() == 500 ||
            googleException.getStatusCode() == 503) {
            return newApiException(googleException);
        } else {
            return newApiException(googleException);
        }
    }
    return new RuntimeException(ioe);
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:21,代碼來源:XeroClient.java

示例2: convertException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * For backwards comparability with xero-java-sdk version 0.6.0 keep the old way of handling exceptions
 *
 * @param ioe exception to convert
 * @return the converted exception
 */
public XeroApiException convertException(IOException ioe) {
    if (ioe instanceof HttpResponseException) {
        HttpResponseException httpResponseException = (HttpResponseException) ioe;
        if (httpResponseException.getStatusCode() == 400) {
            return handleBadRequest(httpResponseException);
        } else if (httpResponseException.getStatusCode() == 401 ||
            httpResponseException.getStatusCode() == 404 ||
            httpResponseException.getStatusCode() == 500 ||
            httpResponseException.getStatusCode() == 503) {
            return newApiException(httpResponseException);
        } else {
            return newApiException(httpResponseException);
        }
    }
    throw new XeroClientException(ioe.getMessage(), ioe);
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:23,代碼來源:XeroExceptionHandler.java

示例3: handleException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
private synchronized void handleException(IOException e) throws IOException {
    Timber.e(e, e.getMessage());
    if (e instanceof HttpResponseException) {
        HttpResponseException h = (HttpResponseException) e;
        int statusCode = h.getStatusCode();
        if (statusCode == 401 || statusCode == 403) {
            accountManager.clearToken(credential);
        } else if (statusCode == 400 || statusCode == 500) {
            throw h;
        } else if (statusCode == 404) {
            throw new HttpNotFoundException(h);
        } else {
            Timber.e(e, "%s: %s", statusCode, h.getStatusMessage());
        }
        // 503 errors are generally either 1) quota limit reached or 2) problems on Google's end
    }
}
 
開發者ID:andyCano,項目名稱:TaskApp,代碼行數:18,代碼來源:GtasksInvoker.java

示例4: mapException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
public static AsanaError mapException(HttpResponseException exception) throws AsanaError {
    switch (exception.getStatusCode()) {
        case ForbiddenError.STATUS:
            return new ForbiddenError(exception);
        case InvalidRequestError.STATUS:
            return new InvalidRequestError(exception);
        case InvalidTokenError.STATUS:
            return new InvalidTokenError(exception);
        case NoAuthorizationError.STATUS:
            return new NoAuthorizationError(exception);
        case NotFoundError.STATUS:
            return new NotFoundError(exception);
        case RateLimitEnforcedError.STATUS:
            return new RateLimitEnforcedError(exception);
        case ServerError.STATUS:
            return new ServerError(exception);
        default:
            return new AsanaError(exception.getStatusMessage(), exception.getStatusCode(), exception);
    }
}
 
開發者ID:Asana,項目名稱:java-asana,代碼行數:21,代碼來源:AsanaError.java

示例5: performRequestWithReinitCredentials

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * Keeps performing actions until credentials expire. When they do, calls
 * initCredentials() and continues. It relies on the RepeatOperation to keep
 * any state required to start where it left off.
 *
 * HttpResponseException with the code Unauthorized is caught. Any other
 * exceptions are passed through.
 *
 * @param a Operation to execute
 * @param retries How many times to attempt to refresh credentials if there is
 * no progress. (Every time an action successfully completes, the retry budget
 * is reset)
 * @param <Ex> An action-specific exception that might be throwns.
 */
public static <Ex extends Throwable> void
performRequestWithReinitCredentials(RepeatOperation<Ex> a, int retries)
    throws IOException, InterruptedException, ExecutorException, Ex {
  int budget = retries;
  do {
    a.initCredentials();
    try {
      while (a.moreWork()) {
        a.act();
        budget = retries;
      }
    } catch (HttpResponseException e) {
      if (budget > 0 && e.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
        logger.fine("Remote credentials expired, retrying.");
        budget--;
      } else {
        throw new IOException(Messages.AbstractUpload_ExceptionFileUpload(),
            e);
      }
    }
    // Other exceptions are raised further for the client to deal with
  } while (a.moreWork());
}
 
開發者ID:jenkinsci,項目名稱:google-storage-plugin,代碼行數:38,代碼來源:RetryStorageOperation.java

示例6: handleResourceException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
private void handleResourceException(HttpResponseException e) throws ServiceFailedException {
	if (isDevelopmentMode) {
		System.out.printf("Status: %s %s", e.getStatusCode(), 
				e.getStatusMessage());
		System.out.println();
	}
	
	if (e.getStatusCode() >= 500) {
		log.severe(e.getStatusCode() + " - " + e.getStatusMessage());
	}
	else {
		log.warning(e.getStatusCode() + " - " + e.getStatusMessage());
	}
	
	throw new ServiceFailedException(e.getStatusCode());
}
 
開發者ID:Rise-Vision,項目名稱:rva,代碼行數:17,代碼來源:RiseRemoteServiceServlet.java

示例7: handleHttpResponseException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@Override
public BlobDescriptor handleHttpResponseException(HttpResponseException httpResponseException)
    throws RegistryErrorException, HttpResponseException {
  if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
    throw httpResponseException;
  }

  // Finds a BLOB_UNKNOWN error response code.
  String errorContent = httpResponseException.getContent();
  if (errorContent == null) {
    // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never be null, even for HEAD requests.
    return null;
  } else {
    try {
      ErrorResponseTemplate errorResponse =
          JsonTemplateMapper.readJson(errorContent, ErrorResponseTemplate.class);
      List<ErrorEntryTemplate> errors = errorResponse.getErrors();
      if (errors.size() == 1) {
        ErrorCodes errorCode = ErrorCodes.valueOf(errors.get(0).getCode());
        if (errorCode.equals(ErrorCodes.BLOB_UNKNOWN)) {
          return null;
        }
      }

    } catch (IOException ex) {
      throw new RegistryErrorExceptionBuilder(getActionDescription(), ex)
          .addReason("Failed to parse registry error response body")
          .build();
    }
  }

  // BLOB_UNKNOWN was not found as a error response code.
  throw httpResponseException;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:35,代碼來源:BlobChecker.java

示例8: handleHttpResponseException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@Override
public RegistryAuthenticator handleHttpResponseException(
    HttpResponseException httpResponseException)
    throws HttpResponseException, RegistryErrorException {
  // Only valid for status code of '401 Unauthorized'.
  if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) {
    throw httpResponseException;
  }

  // Checks if the 'WWW-Authenticate' header is present.
  String authenticationMethod = httpResponseException.getHeaders().getAuthenticate();
  if (authenticationMethod == null) {
    throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException)
        .addReason("'WWW-Authenticate' header not found")
        .build();
  }

  // Parses the header to retrieve the components.
  try {
    return RegistryAuthenticator.fromAuthenticationMethod(
        authenticationMethod, registryEndpointProperties.getImageName());

  } catch (RegistryAuthenticationFailedException | MalformedURLException ex) {
    throw new RegistryErrorExceptionBuilder(getActionDescription(), ex)
        .addReason("Failed get authentication method from 'WWW-Authenticate' header")
        .build();
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:29,代碼來源:AuthenticationMethodRetriever.java

示例9: newApiException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * @deprecated As of xero-java-sdk version 0.6.0, to be removed
 * in favour of {@link XeroExceptionHandler#newApiException(HttpResponseException)}
 */
protected XeroApiException newApiException(HttpResponseException googleException) {
    Matcher matcher = MESSAGE_PATTERN.matcher(googleException.getContent());
    StringBuilder messages = new StringBuilder();
    while (matcher.find()) {
        if (messages.length() > 0) {
            messages.append(", ");
        }
        messages.append(matcher.group(1));
    }

    if (messages.length() > 0) {
        throw new XeroApiException(googleException.getStatusCode(), messages.toString());
    }
    if (googleException.getContent().contains("=")) {
        try {
            String value = URLDecoder.decode(googleException.getContent(), "UTF-8");
            String[] keyValuePairs = value.split("&");

            Map<String, String> errorMap = new HashMap<>();
            for (String pair : keyValuePairs) {
                String[] entry = pair.split("=");
                errorMap.put(entry[0].trim(), entry[1].trim());
            }
            throw new XeroApiException(googleException.getStatusCode(), errorMap);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    throw new XeroApiException(googleException.getStatusCode(), googleException.getContent());
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:36,代碼來源:XeroClient.java

示例10: newApiException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * For backwards comparability with xero-java-sdk version 0.6.0 keep the old way of handling exceptions
 *
 * @param httpResponseException exception to handle
 * @return XeroApiException
 */
public XeroApiException newApiException(HttpResponseException httpResponseException) {
    Matcher matcher = MESSAGE_PATTERN.matcher(httpResponseException.getContent());
    StringBuilder messages = new StringBuilder();
    while (matcher.find()) {
        if (messages.length() > 0) {
            messages.append(", ");
        }
        messages.append(matcher.group(1));
    }

    if (messages.length() > 0) {
        return new XeroApiException(httpResponseException.getStatusCode(), messages.toString());
    }
    if (httpResponseException.getContent().contains("=")) {
        try {
            String value = URLDecoder.decode(httpResponseException.getContent(), "UTF-8");
            String[] keyValuePairs = value.split("&");

            Map<String, String> errorMap = new HashMap<>();
            for (String pair : keyValuePairs) {
                String[] entry = pair.split("=");
                errorMap.put(entry[0].trim(), entry[1].trim());
            }
            return new XeroApiException(httpResponseException.getStatusCode(), errorMap);

        } catch (UnsupportedEncodingException e) {
            LOGGER.severe(e.getMessage());
            throw new XeroClientException(e.getMessage(), e);
        }
    }

    return new XeroApiException(httpResponseException.getStatusCode(), httpResponseException.getContent());
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:40,代碼來源:XeroExceptionHandler.java

示例11: transformException

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
 * Transform an HttpResponseException into a DnsimpleException.
 *
 * @param e The HttpResponseException
 * @return The DnsimpleException
 */
public static DnsimpleException transformException(HttpResponseException e) {
  switch(e.getStatusCode()) {
    case 404:
      return new ResourceNotFoundException("Failed to retreive domain: " + e.getMessage(), null, e.getStatusCode(), e);
    default:
      return new DnsimpleException(e.getMessage(), null, e.getStatusCode(), e);
  }
}
 
開發者ID:dnsimple,項目名稱:dnsimple-java,代碼行數:15,代碼來源:DnsimpleException.java

示例12: execute

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T execute(Type responseType, HttpRequest httpRequest)
    throws IOException, GerritApiException {
  HttpResponse response;
  try {
    response = httpRequest.execute();
  } catch (HttpResponseException e) {
    throw new GerritApiException(e.getStatusCode(), e.getContent());
  }
  return (T) response.parseAs(responseType);
}
 
開發者ID:google,項目名稱:copybara,代碼行數:12,代碼來源:GerritApiTransportImpl.java

示例13: deleteFile

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@Override
protected void deleteFile(String objectName) throws Exception {
    try {
        client.deleteObject(bucketName, objectName);
    } catch (HttpResponseException e) {
        if (e.getStatusCode() != HTTP_NOT_FOUND) {
            throw e;
        }
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:11,代碼來源:GcsPseudoLock.java

示例14: shouldRetry

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@Override
public boolean shouldRetry(IOException e) {
  if (e instanceof HttpResponseException) {
    HttpResponseException httpException = (HttpResponseException) e;
    // TODO: Find what we should do for 500 codes that are not always transient.
    return httpException.getStatusCode() / 100 == 5;
  }
  return false;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:10,代碼來源:RetryDeterminer.java

示例15: readMetadata

import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public String readMetadata(String metadataPath)
    throws IOException, ExecutorException {
  HttpRequest request = requestFactory.buildGetRequest(
      new GenericUrl(METADATA_SERVER + metadataPath));

  // GCE v1 requires requests to the metadata service to specify
  // this header in order to get anything back.
  request.getHeaders().set("X-Google-Metadata-Request", true);

  HttpResponse response;
  try {
    response = request.execute();
  } catch (HttpResponseException e) {
    switch (e.getStatusCode()) {
      case STATUS_CODE_UNAUTHORIZED:
      case STATUS_CODE_FORBIDDEN:
        throw new ForbiddenException(e);
      case STATUS_CODE_NOT_FOUND:
        throw new NotFoundException(e);
      default:
        throw e;
    }
  }

  InputStreamReader inChars = null;
  try {
    inChars = new InputStreamReader(
        checkNotNull(response.getContent()), Charsets.UTF_8);
    StringWriter output = new StringWriter();
    copy(inChars, output);
    return output.toString();
  } finally {
    if (inChars != null) {
      inChars.close();
    }
  }
}
 
開發者ID:jenkinsci,項目名稱:google-oauth-plugin,代碼行數:40,代碼來源:MetadataReader.java


注:本文中的com.google.api.client.http.HttpResponseException.getStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。