} catch (HttpResponseException ex) { exception = ex; code = ex.getStatusCode(); message = ex.getStatusMessage();
@Override @Nullable 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. if (httpResponseException.getContent() == null) { // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never // be null, even for HEAD requests. return null; } ErrorCodes errorCode = ErrorResponseUtil.getErrorCode(httpResponseException); if (errorCode == ErrorCodes.BLOB_UNKNOWN) { return null; } // BLOB_UNKNOWN was not found as a error response code. throw httpResponseException; }
private void innerTestCantCopyWithoutUserProject( boolean sourceNormal, boolean destNormal, Path source, Path dest) throws IOException { String sdesc = (sourceNormal ? "normal bucket" : "requester-pays bucket"); String ddesc = (destNormal ? "normal bucket" : "requester-pays bucket"); String description = "Copying from " + sdesc + " to " + ddesc; try { Files.copy(source, dest); Assert.fail("Shouldn't have been able to copy from " + sdesc + " to " + ddesc); // for some reason this throws "GoogleJsonResponseException" instead of "StorageException" // when going from requester pays bucket to requester pays bucket, but otherwise we get a // normal StorageException. } catch (HttpResponseException hex) { Assert.assertEquals(description, hex.getStatusCode(), 400); Assert.assertTrue( description, hex.getMessage() .contains("Bucket is requester pays bucket but no user project provided")); } catch (StorageException ex) { assertIsRequesterPaysException(description, ex); } }
@Override @Nullable 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, registryEndpointRequestProperties); } catch (RegistryAuthenticationFailedException ex) { throw new RegistryErrorExceptionBuilder(getActionDescription(), ex) .addReason("Failed get authentication method from 'WWW-Authenticate' header") .build(); } } }
if (httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST || httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND || httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_METHOD_NOT_ALLOWED) { httpResponseException.getContent(), ErrorResponseTemplate.class); RegistryErrorExceptionBuilder registryErrorExceptionBuilder = new RegistryErrorExceptionBuilder( } else if (httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN) { throw new RegistryUnauthorizedException( registryEndpointRequestProperties.getServerUrl(), httpResponseException); } else if (httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) { if (sendCredentials) { } else if (httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_TEMPORARY_REDIRECT || httpResponseException.getStatusCode() == HttpStatusCodes.STATUS_CODE_MOVED_PERMANENTLY || httpResponseException.getStatusCode() == STATUS_CODE_PERMANENT_REDIRECT) { URL redirectLocation = new URL(url, httpResponseException.getHeaders().getLocation()); return callWithAllowInsecureRegistryHandling(redirectLocation);
public static boolean isRetryable(Throwable t) { if (t instanceof HttpResponseException) { final HttpResponseException e = (HttpResponseException) t; return e.getStatusCode() == 429 || (e.getStatusCode() / 500 == 1); } return t instanceof IOException; } }
protected APIException getAPIException(HttpResponseException ex) { try { APIExceptionMessage exceptionMessage = fromJson(ex.getContent(), TypeReferenceFactory.getTypeRef(APIExceptionMessage.class)); return new APIException(ex.getStatusCode(), exceptionMessage.getMessage(), ex); } catch (APIException e) { return new APIException(ex.getStatusCode(), ex.getMessage()); } }
httpResponse = request.execute(); } catch (HttpResponseException e) { e.printStackTrace(); int statusCode = e.getStatusCode(); logger.error("StatusCode "+statusCode); logger.error("Query URL was "+url.toString());
int exceptionStatusCode = e.getStatusCode(); String range = e.getHeaders().getRange(); LOGGER.log(Level.FINE, "Upload request returned status code " + exceptionStatusCode + " and status message " + e.getStatusMessage()); if (exceptionStatusCode == 308) { resume = 0;
} catch (HttpResponseException e) { System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace();
System.err.println(e.getHeaders()); System.err.println(e.getMessage()); } catch (IOException e) {
throws HttpResponseException { String errorContent = httpResponseException.getContent(); if (errorContent == null) { throw httpResponseException;
} catch (HttpResponseException ex) { throw new APIException(String .format("Failed to acquire access token. Reason: %s", ex.getStatusMessage()), ex); } catch (IOException ex) { throw new APIException(String.format("Failed to acquire access token. Reason: %s", ex.getMessage()), ex);
@Test public void testReturnException() throws IOException { testService.addException(new Exception(RESPONSE_EXCEPTION_STRING)); try { HTTP_REQUEST_FACTORY .buildGetRequest(new GenericUrl("http://google.com/pet/rodent")) .execute(); fail(); } catch (HttpResponseException e) { assertFalse(e.isSuccessStatusCode()); assertTrue(e.getContent().contains(RESPONSE_EXCEPTION_STRING)); } }
private void deleteIfPresent(String bucket, String path) throws IOException { try { RetryUtils.retry( (RetryUtils.Task<Void>) () -> { storage.delete(bucket, path); return null; }, GoogleUtils::isRetryable, 1, 5 ); } catch (HttpResponseException e) { if (e.getStatusCode() != 404) { throw e; } LOG.debug("Already deleted: [%s] [%s]", bucket, path); } catch (IOException ioe) { throw ioe; } catch (Exception e) { throw new RE(e, "Failed to delete [%s] [%s]", bucket, path); } }
private static void appendResponse(HttpResponseException exception, StringBuilder b) { b.append(exception.getStatusCode()).append(" with "); Long contentLength = exception.getHeaders().getContentLength(); b.append(contentLength != null ? contentLength : Long.valueOf(0)); b.append(" bytes of content"); HttpHeaders headers = exception.getHeaders(); for (String name : headers.keySet()) { b.append('\n').append(name).append(": ").append(headers.get(name)); } b.append('\n').append(exception.getContent()).append('\n'); }
@Override @Nullable 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, registryEndpointRequestProperties); } catch (RegistryAuthenticationFailedException ex) { throw new RegistryErrorExceptionBuilder(getActionDescription(), ex) .addReason("Failed get authentication method from 'WWW-Authenticate' header") .build(); } } }
httpResponse = request.execute(); } catch (HttpResponseException e) { e.printStackTrace(); int statusCode = e.getStatusCode(); logger.error("StatusCode "+statusCode); logger.error("Query URL was "+url.toString());
logger.error(e.getMessage()); throw new IOException(e.getMessage());
throws HttpResponseException { String errorContent = httpResponseException.getContent(); if (errorContent == null) { throw httpResponseException;