Example usage for com.amazonaws ClientConfiguration ClientConfiguration

List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration ClientConfiguration.

Prototype

public ClientConfiguration() 

Source Link

Usage

From source file:cloudExplorer.Acl.java

License:Open Source License

String viewACL(String object, String access_key, String secret_key, String endpoint, String bucket) {
    String message = null;//w  ww  . j  a v a2  s.co m
    try {
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        message = s3Client.getObjectAcl(bucket, object).toString();
    } catch (Exception viewACL) {
        mainFrame.jTextArea1.append("\nException occurred in viewACL");
    }

    return object + ":     " + message;
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void setBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {//from w  w  w  .jav a 2  s. c o  m
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        BucketWebsiteConfiguration bucketWebsiteConfiguration = s3Client.getBucketWebsiteConfiguration(bucket);
        s3Client.setBucketAcl(bucket, CannedAccessControlList.PublicRead);
        s3Client.setBucketWebsiteConfiguration(bucket,
                new BucketWebsiteConfiguration("index.html", "error.html"));
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

void removeBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {/*from ww w.  java2  s  .c  om*/
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        s3Client.deleteBucketWebsiteConfiguration(bucket);
    } catch (Exception removeBUCKETwebsite) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:cloudExplorer.Acl.java

License:Open Source License

String setACLurl(String object, String access_key, String secret_key, String endpoint, String bucket) {
    String URL = null;//from w  w  w . j a  v a2s.c  o  m
    try {
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        java.util.Date expiration = new java.util.Date();
        long milliSeconds = expiration.getTime();
        milliSeconds += 1000 * 60 * 1000; // Add 1 hour.
        expiration.setTime(milliSeconds);
        GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket,
                object);
        generatePresignedUrlRequest.setMethod(HttpMethod.GET);
        generatePresignedUrlRequest.setExpiration(expiration);
        URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
        URL = ("Pre-Signed URL = " + url.toString());
        StringSelection stringSelection = new StringSelection(url.toString());
        Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
        clpbrd.setContents(stringSelection, null);
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occured in ACL");
    }
    return URL;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

Boolean VersioningStatus(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {//from   w ww . jav  a  2 s.c o m
    String message = null;
    boolean result = false;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        message = s3Client.getBucketVersioningConfiguration(bucket).getStatus().toString();
        if (message.contains("Enabled") || message.contains("Suspended")) {
            result = true;
        } else {
            result = false;
        }
    } catch (Exception versioning) {
    }

    return result;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

Boolean LifeCycleStatus(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {/*w ww .j  a  va2  s . c o  m*/
    String message = null;
    boolean result = false;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        message = s3Client.getBucketLifecycleConfiguration(bucket).getRules().toString();
        if (message == null) {
            result = false;
        } else {
            result = true;
        }
    } catch (Exception lifecyclestatus) {
    }

    return result;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String controlVersioning(String access_key, String secret_key, String bucket, String endpoint, String region,
        Boolean enable) {//from  w  ww .j a  v  a2 s  .c o  m

    String message = null;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        SetBucketVersioningConfigurationRequest request;
        if (enable) {
            request = new SetBucketVersioningConfigurationRequest(bucket,
                    new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED));
        } else {
            request = new SetBucketVersioningConfigurationRequest(bucket,
                    new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED));
        }
        s3Client.setBucketVersioningConfiguration(request);
        message = "\nBucket Versioning is:" + request.getVersioningConfiguration().getStatus();
    } catch (Exception versioning) {
        message = "\n" + versioning.getMessage();
    }
    if (message == null) {
        message = "\nVersioning failed.";
    }
    return message;

}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String makeBucket(String access_key, String secret_key, String bucket, String endpoint, String region) {
    String message = null;// w w w .  j  ava2 s . c o  m
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    try {
        if (endpoint.contains("amazon")) {
            s3Client.createBucket(new CreateBucketRequest(bucket));

        } else {
            s3Client.createBucket(new CreateBucketRequest(bucket, region));
        }

        message = ("\nAttempting to create the bucket. Please view the Bucket list window for an update.");
    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    }
    if (message == null) {
        message = "Failed to create bucket.";
    }
    return message;

}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String listBuckets(String access_key, String secret_key, String endpoint) {

    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);/*from   w w  w  .  j ava2 s. c om*/
    String[] array = new String[10];

    String bucketlist = null;

    int i = 0;
    try {

        for (Bucket bucket : s3Client.listBuckets()) {
            bucketlist = bucketlist + " " + bucket.getName();
        }

    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }

    } catch (Exception lsbuckets) {

        if (lsbuckets.getMessage().contains("peer not authenticated")
                || lsbuckets.getMessage().contains("hostname in certificate didn't match")) {
            if (NewJFrame.gui) {
                mainFrame.jTextArea1.append(
                        "\nError: This program does not support non-trusted SSL certificates\n\nor your SSL certificates are incorrect.");
            } else {
                System.out.print(
                        "\n\nError: This program does not support non-trusted SSL certificates\n\nor your SSL certificates are not correctly installed.");
            }
        }
    }
    String parse = null;

    if (bucketlist != null) {
        parse = bucketlist.replace("null", "");

    } else {
        parse = "no_bucket_found";
    }

    return parse;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String listBucketContents(String access_key, String secret_key, String bucket, String endpoint) {
    objectlist = null;/*from  w w  w.  j a  v  a2s.  c om*/

    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        ObjectListing current = s3Client.listObjects((bucket));

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket);
        ObjectListing objectListing;
        do {
            objectListing = s3Client.listObjects(listObjectsRequest);
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                objectlist = objectlist + "@@" + objectSummary.getKey();
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

    } catch (Exception listBucket) {
        mainFrame.jTextArea1.append("\n" + listBucket.getMessage());
    }

    String parse = null;
    if (objectlist != null) {
        parse = objectlist;
    } else {
        parse = "No objects_found.";
    }
    return parse;
}