Search in sources :

Example 1 with HeadBucketResultHandler

use of com.amazonaws.services.s3.model.transform.HeadBucketResultHandler in project aws-sdk-android by aws-amplify.

the class AmazonS3Client method getBucketRegionViaHeadRequest.

/**
 * Retrieves the region of the bucket by making a HeadBucket request to
 * us-west-1 region. Currently S3 doesn't return region in a HEAD Bucket
 * request if the bucket owner has enabled bucket to accept only SigV4
 * requests via bucket policies.
 */
private String getBucketRegionViaHeadRequest(String bucketName) {
    String bucketRegion = null;
    try {
        final String endpoint = "https://s3-us-west-1.amazonaws.com";
        final Request<HeadBucketRequest> request = createRequest(bucketName, null, new HeadBucketRequest(bucketName), HttpMethodName.HEAD, new URI(endpoint));
        final HeadBucketResult result = invoke(request, new HeadBucketResultHandler(), bucketName, null);
        bucketRegion = result.getBucketRegion();
    } catch (final AmazonS3Exception exception) {
        if (exception.getAdditionalDetails() != null) {
            bucketRegion = exception.getAdditionalDetails().get(Headers.S3_BUCKET_REGION);
        }
    } catch (final URISyntaxException e) {
        log.warn("Error while creating URI");
    }
    if (bucketRegion == null && log.isDebugEnabled()) {
        log.debug("Not able to derive region of the " + bucketName + " from the HEAD Bucket requests.");
    }
    return bucketRegion;
}
Also used : HeadBucketResultHandler(com.amazonaws.services.s3.model.transform.HeadBucketResultHandler) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with HeadBucketResultHandler

use of com.amazonaws.services.s3.model.transform.HeadBucketResultHandler in project aws-sdk-android by aws-amplify.

the class AmazonS3Client method headBucket.

@Override
public HeadBucketResult headBucket(HeadBucketRequest headBucketRequest) throws AmazonClientException, AmazonServiceException {
    final String bucketName = headBucketRequest.getBucketName();
    assertParameterNotNull(bucketName, "The bucketName parameter must be specified.");
    final Request<HeadBucketRequest> request = createRequest(bucketName, null, headBucketRequest, HttpMethodName.HEAD);
    return invoke(request, new HeadBucketResultHandler(), bucketName, null);
}
Also used : HeadBucketResultHandler(com.amazonaws.services.s3.model.transform.HeadBucketResultHandler)

Aggregations

HeadBucketResultHandler (com.amazonaws.services.s3.model.transform.HeadBucketResultHandler)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1