Search in sources :

Example 1 with HttpResponseException

use of org.jclouds.http.HttpResponseException 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 HttpResponseException

use of org.jclouds.http.HttpResponseException 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 HttpResponseException

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

the class JCloudsFileResourceContentStore method init.

// -------------------------------------------------------------------------
// Life cycle management
// -------------------------------------------------------------------------
@PostConstruct
public void init() {
    // ---------------------------------------------------------------------
    // Bootstrap config
    // ---------------------------------------------------------------------
    config = new BlobStoreProperties(configurationProvider.getProperty(ConfigurationKey.FILESTORE_PROVIDER), configurationProvider.getProperty(ConfigurationKey.FILESTORE_LOCATION), configurationProvider.getProperty(ConfigurationKey.FILESTORE_CONTAINER));
    Pair<Credentials, Properties> providerConfig = configureForProvider(config.provider, configurationProvider.getProperty(ConfigurationKey.FILESTORE_IDENTITY), configurationProvider.getProperty(ConfigurationKey.FILESTORE_SECRET));
    // ---------------------------------------------------------------------
    // Set up JClouds context
    // ---------------------------------------------------------------------
    blobStoreContext = ContextBuilder.newBuilder(config.provider).credentials(providerConfig.getLeft().identity, providerConfig.getLeft().credential).overrides(providerConfig.getRight()).build(BlobStoreContext.class);
    blobStore = blobStoreContext.getBlobStore();
    Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(config.provider).description(config.provider).build();
    try {
        blobStore.createContainerInLocation(createRegionLocation(config, provider), config.container);
        log.info(String.format("File store configured with provider: '%s', container: '%s' and location: '%s'.", config.provider, config.container, config.location));
    } catch (HttpResponseException ex) {
        log.error(String.format("Could not configure file store with provider '%s' and container '%s'.\n" + "File storage will not be available.", config.provider, config.container), ex);
    } catch (AuthorizationException ex) {
        log.error(String.format("Could not authenticate with file store provider '%s' and container '%s'. " + "File storage will not be available.", config.provider, config.location), ex);
    }
}
Also used : LocationBuilder(org.jclouds.domain.LocationBuilder) AuthorizationException(org.jclouds.rest.AuthorizationException) HttpResponseException(org.jclouds.http.HttpResponseException) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location) PostConstruct(javax.annotation.PostConstruct)

Example 4 with HttpResponseException

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

the class JCloudsAppStorageService method init.

@PostConstruct
public void init() {
    // ---------------------------------------------------------------------
    // Bootstrap config
    // ---------------------------------------------------------------------
    config = new BlobStoreProperties(configurationProvider.getProperty(ConfigurationKey.FILESTORE_PROVIDER), configurationProvider.getProperty(ConfigurationKey.FILESTORE_LOCATION), configurationProvider.getProperty(ConfigurationKey.FILESTORE_CONTAINER));
    Pair<Credentials, Properties> providerConfig = configureForProvider(config.provider, configurationProvider.getProperty(ConfigurationKey.FILESTORE_IDENTITY), configurationProvider.getProperty(ConfigurationKey.FILESTORE_SECRET));
    // ---------------------------------------------------------------------
    // Set up JClouds context
    // ---------------------------------------------------------------------
    blobStoreContext = ContextBuilder.newBuilder(config.provider).credentials(providerConfig.getLeft().identity, providerConfig.getLeft().credential).overrides(providerConfig.getRight()).build(BlobStoreContext.class);
    blobStore = blobStoreContext.getBlobStore();
    Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(config.provider).description(config.provider).build();
    try {
        blobStore.createContainerInLocation(createRegionLocation(config, provider), config.container);
        log.info(String.format("File store configured with provider: '%s', container: '%s' and location: '%s'.", config.provider, config.container, config.location));
    } catch (HttpResponseException ex) {
        log.error(String.format("Could not configure file store with provider '%s' and container '%s'.\n" + "File storage will not be available.", config.provider, config.container), ex);
    } catch (AuthorizationException ex) {
        log.error(String.format("Could not authenticate with file store provider '%s' and container '%s'. " + "File storage will not be available.", config.provider, config.location), ex);
    }
}
Also used : LocationBuilder(org.jclouds.domain.LocationBuilder) AuthorizationException(org.jclouds.rest.AuthorizationException) HttpResponseException(org.jclouds.http.HttpResponseException) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Properties(java.util.Properties) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location) PostConstruct(javax.annotation.PostConstruct)

Aggregations

HttpResponseException (org.jclouds.http.HttpResponseException)4 PostConstruct (javax.annotation.PostConstruct)2 Credentials (org.jclouds.domain.Credentials)2 Location (org.jclouds.domain.Location)2 LocationBuilder (org.jclouds.domain.LocationBuilder)2 HttpRequest (org.jclouds.http.HttpRequest)2 HttpResponse (org.jclouds.http.HttpResponse)2 AuthorizationException (org.jclouds.rest.AuthorizationException)2 Properties (java.util.Properties)1 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)1 Blob (org.jclouds.blobstore.domain.Blob)1