Search in sources :

Example 1 with HttpRequest

use of org.jclouds.http.HttpRequest in project legacy-jclouds-examples by jclouds.

the class GenerateTempURL method generateDeleteTempURL.

private void generateDeleteTempURL() throws IOException {
    System.out.println("Generate DELETE Temp URL");
    HttpRequest request = storageContext.getSigner().signRemoveBlob(Constants.CONTAINER, FILENAME);
    System.out.println("  " + request.getMethod() + " " + request.getEndpoint());
    // DELETE the file using jclouds
    HttpResponse response = storageContext.utils().http().invoke(request);
    int statusCode = response.getStatusCode();
    if (statusCode >= 200 && statusCode < 299) {
        System.out.println("  DELETE Success (" + statusCode + ")");
    } else {
        throw new HttpResponseException(null, response);
    }
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) HttpResponse(org.jclouds.http.HttpResponse) HttpResponseException(org.jclouds.http.HttpResponseException)

Example 2 with HttpRequest

use of org.jclouds.http.HttpRequest in project legacy-jclouds-examples by jclouds.

the class GenerateTempURL method generatePutTempURL.

private void generatePutTempURL() throws IOException {
    System.out.println("Generate PUT Temp URL");
    String payload = "This object will be public for 10 minutes.";
    Blob blob = storage.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
    HttpRequest request = storageContext.getSigner().signPutBlob(Constants.CONTAINER, blob, TEN_MINUTES);
    System.out.println("  " + request.getMethod() + " " + request.getEndpoint());
    // PUT the file using jclouds
    HttpResponse response = storageContext.utils().http().invoke(request);
    int statusCode = response.getStatusCode();
    if (statusCode >= 200 && statusCode < 299) {
        System.out.println("  PUT Success (" + statusCode + ")");
    } else {
        throw new HttpResponseException(null, response);
    }
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) Blob(org.jclouds.blobstore.domain.Blob) HttpResponse(org.jclouds.http.HttpResponse) HttpResponseException(org.jclouds.http.HttpResponseException)

Example 3 with HttpRequest

use of org.jclouds.http.HttpRequest in project dhis2-core by dhis2.

the class JCloudsAppStorageService method getSignedGetContentUri.

public URI getSignedGetContentUri(String key) {
    BlobRequestSigner signer = blobStoreContext.getSigner();
    if (!requestSigningSupported(signer)) {
        return null;
    }
    HttpRequest httpRequest;
    try {
        httpRequest = signer.signGetBlob(config.container, key, FIVE_MINUTES_IN_SECONDS);
    } catch (UnsupportedOperationException uoe) {
        return null;
    }
    return httpRequest.getEndpoint();
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) LocalBlobRequestSigner(org.jclouds.blobstore.LocalBlobRequestSigner) BlobRequestSigner(org.jclouds.blobstore.BlobRequestSigner)

Example 4 with HttpRequest

use of org.jclouds.http.HttpRequest in project dhis2-core by dhis2.

the class JCloudsFileResourceContentStore method getSignedGetContentUri.

@Override
public URI getSignedGetContentUri(String key) {
    BlobRequestSigner signer = blobStoreContext.getSigner();
    if (!requestSigningSupported(signer)) {
        return null;
    }
    HttpRequest httpRequest;
    try {
        httpRequest = signer.signGetBlob(config.container, key, FIVE_MINUTES_IN_SECONDS);
    } catch (UnsupportedOperationException uoe) {
        return null;
    }
    return httpRequest.getEndpoint();
}
Also used : HttpRequest(org.jclouds.http.HttpRequest)

Example 5 with HttpRequest

use of org.jclouds.http.HttpRequest in project whirr by apache.

the class BlobCacheTest method testBlobCacheUpload.

private void testBlobCacheUpload(String payload, ClusterSpec spec) throws Exception {
    File tempFile = createTemporaryFile(payload);
    BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
    try {
        cache.putIfAbsent(tempFile);
        HttpRequest req = cache.getSignedRequest(tempFile.getName());
        assertThat(readContent(req), is(payload));
        /* render download statement for visual test inspection */
        LOG.info(cache.getAsSaveToStatement("/tmp", tempFile.getName()).render(OsFamily.UNIX));
    } finally {
        BlobCache.dropAndCloseAll();
    }
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) BlobCache(org.apache.whirr.util.BlobCache) File(java.io.File)

Aggregations

HttpRequest (org.jclouds.http.HttpRequest)6 File (java.io.File)2 HttpResponse (org.jclouds.http.HttpResponse)2 HttpResponseException (org.jclouds.http.HttpResponseException)2 BlobCache (org.apache.whirr.util.BlobCache)1 BlobRequestSigner (org.jclouds.blobstore.BlobRequestSigner)1 LocalBlobRequestSigner (org.jclouds.blobstore.LocalBlobRequestSigner)1 Blob (org.jclouds.blobstore.domain.Blob)1