Search in sources :

Example 1 with BucketWebsiteConfiguration

use of com.amazonaws.services.s3.model.BucketWebsiteConfiguration in project aws-doc-sdk-examples by awsdocs.

the class GetWebsiteConfiguration method getWebsiteConfig.

public static void getWebsiteConfig(String bucket_name) {
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        BucketWebsiteConfiguration config = s3.getBucketWebsiteConfiguration(bucket_name);
        if (config == null) {
            System.out.println("No website configuration found!");
        } else {
            System.out.format("Index document: %s\n", config.getIndexDocumentSuffix());
            System.out.format("Error document: %s\n", config.getErrorDocument());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.out.println("Failed to get website configuration!");
        System.exit(1);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) BucketWebsiteConfiguration(com.amazonaws.services.s3.model.BucketWebsiteConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 2 with BucketWebsiteConfiguration

use of com.amazonaws.services.s3.model.BucketWebsiteConfiguration in project aws-doc-sdk-examples by awsdocs.

the class SetWebsiteConfiguration method setWebsiteConfig.

public static void setWebsiteConfig(String bucket_name, String index_doc, String error_doc) {
    BucketWebsiteConfiguration website_config = null;
    if (index_doc == null) {
        website_config = new BucketWebsiteConfiguration();
    } else if (error_doc == null) {
        website_config = new BucketWebsiteConfiguration(index_doc);
    } else {
        website_config = new BucketWebsiteConfiguration(index_doc, error_doc);
    }
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        s3.setBucketWebsiteConfiguration(bucket_name, website_config);
    } catch (AmazonServiceException e) {
        System.out.format("Failed to set website configuration for bucket '%s'!\n", bucket_name);
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : BucketWebsiteConfiguration(com.amazonaws.services.s3.model.BucketWebsiteConfiguration) AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonServiceException(com.amazonaws.AmazonServiceException)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 BucketWebsiteConfiguration (com.amazonaws.services.s3.model.BucketWebsiteConfiguration)2