com.amazonaws.services.s3.model.HeadBucketRequest Java Examples

The following examples show how to use com.amazonaws.services.s3.model.HeadBucketRequest. 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: S3.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
/** Test whether the bucket exists and is accessible. */
public static boolean bucketExists(AmazonS3 client, String bucketName) {
    try {
        HeadBucketRequest request = new HeadBucketRequest(bucketName);
        HeadBucketResult result = client.headBucket(request);
        return true;
    }
    catch (AmazonServiceException awsEx) {
        switch (awsEx.getStatusCode()) {
            case HttpSC.NOT_FOUND_404 :
                return false;
            case HttpSC.FORBIDDEN_403 :
                break;
            case HttpSC.MOVED_PERMANENTLY_301 : { // Moved permanently.
                System.err.println("301 Location: " + awsEx.getHttpHeaders().get(HttpNames.hLocation));
                break;
            }
        }
        throw awsEx;
    }
}
 
Example #2
Source File: AwsSdkTest.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerExists() throws Exception {
    client.headBucket(new HeadBucketRequest(containerName));
    try {
        client.headBucket(new HeadBucketRequest(
                createRandomContainerName()));
        Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
    } catch (AmazonS3Exception e) {
        assertThat(e.getErrorCode()).isEqualTo("404 Not Found");
    }
}
 
Example #3
Source File: AwsSdkTest.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainerDelete() throws Exception {
    client.headBucket(new HeadBucketRequest(containerName));
    client.deleteBucket(containerName);
    try {
        client.headBucket(new HeadBucketRequest(containerName));
        Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class);
    } catch (AmazonS3Exception e) {
        assertThat(e.getErrorCode()).isEqualTo("404 Not Found");
    }
}
 
Example #4
Source File: S3Utils.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {

    client.createBucket(bucketName);

    HeadBucketRequest request = new HeadBucketRequest(bucketName);
    Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists();
    Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler());
    future.get(1, TimeUnit.MINUTES);
}
 
Example #5
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public HeadBucketResult headBucket(HeadBucketRequest headBucketReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}