本文整理匯總了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);
}
示例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);
}
示例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
}
}
示例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);
}
}
示例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());
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
}
示例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);
}
示例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;
}
}
}
示例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;
}
示例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();
}
}
}