org.jclouds.http.HttpResponseException Java Examples

The following examples show how to use org.jclouds.http.HttpResponseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenerateTempURL.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void generatePutTempURL() throws IOException {
   System.out.format("Generate PUT Temp URL%n");

   // Create the Payload
   String data = "This object will be public for 10 minutes.";
   ByteSource source = ByteSource.wrap(data.getBytes());
   Payload payload = Payloads.newByteSourcePayload(source);

   // Create the Blob
   Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
   HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);

   System.out.format("  %s %s%n", request.getMethod(), request.getEndpoint());

   // PUT the file using jclouds
   HttpResponse response = blobStoreContext.utils().http().invoke(request);
   int statusCode = response.getStatusCode();

   if (statusCode >= 200 && statusCode < 299) {
      System.out.format("  PUT Success (%s)%n", statusCode);
   }
   else {
      throw new HttpResponseException(null, response);
   }
}
 
Example #2
Source File: GenerateTempURL.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void generateDeleteTempURL() throws IOException {
   System.out.format("Generate DELETE Temp URL%n");

   HttpRequest request = blobStoreContext.getSigner(REGION).signRemoveBlob(CONTAINER, FILENAME);

   System.out.format("  %s %s%n", request.getMethod(), request.getEndpoint());

   // DELETE the file using jclouds
   HttpResponse response = blobStoreContext.utils().http().invoke(request);
   int statusCode = response.getStatusCode();

   if (statusCode >= 200 && statusCode < 299) {
      System.out.format("  DELETE Success (%s)%n", statusCode);
   }
   else {
      throw new HttpResponseException(null, response);
   }
}
 
Example #3
Source File: ObjectStoreFileStorage.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private void putBlobWithRetries(Blob blob, int retries) {
    for (int i = 1; i <= retries; i++) {
        try {
            blobStore.putBlob(container, blob, PutOptions.Builder.multipart());
            return;
        } catch (HttpResponseException e) {
            LOGGER.warn(MessageFormat.format(Messages.ATTEMPT_TO_UPLOAD_BLOB_FAILED, i, retries, e.getMessage()), e);
            if (i == retries) {
                throw e;
            }
        }
        MiscUtil.sleep(i * getRetryWaitTime());
    }
}
 
Example #4
Source File: StreamCompatibleBlobPutter.java    From james-project with Apache License 2.0 5 votes vote down vote up
private boolean needToCreateBucket(Throwable throwable, ObjectStorageBucketName bucketName) {
    return Optional.of(throwable)
        .filter(t -> t instanceof HttpResponseException || t instanceof KeyNotFoundException)
        .flatMap(this::extractHttpException)
        .map(ex -> isPutMethod(ex) && !bucketExists(bucketName))
        .orElse(false);
}
 
Example #5
Source File: StreamCompatibleBlobPutter.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Optional<HttpResponseException> extractHttpException(Throwable throwable) {
    if (throwable instanceof HttpResponseException) {
        return Optional.of((HttpResponseException) throwable);
    } else if (throwable.getCause() instanceof HttpResponseException) {
        return Optional.of((HttpResponseException) throwable.getCause());
    }

    return Optional.empty();
}
 
Example #6
Source File: StreamCompatibleBlobPutter.java    From james-project with Apache License 2.0 4 votes vote down vote up
private boolean isPutMethod(Throwable throwable) {
    return throwable instanceof HttpResponseException
        && isPutMethod((HttpResponseException) throwable);
}
 
Example #7
Source File: StreamCompatibleBlobPutter.java    From james-project with Apache License 2.0 4 votes vote down vote up
private boolean isPutMethod(HttpResponseException ex) {
    return ex.getCommand()
        .getCurrentRequest()
        .getMethod()
        .equals("PUT");
}