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.BucketClass.java

License:Open Source License

String getObjectInfo(String key, String access_key, String secret_key, String bucket, String endpoint,
        String process) {// www.  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);
    objectlist = null;

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

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket);
        ObjectListing objectListing;
        do {
            objectListing = s3Client.listObjects(listObjectsRequest);

            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {

                if (process.contains("objectsize")) {
                    if (objectSummary.getKey().contains(key)) {
                        objectlist = String.valueOf(objectSummary.getSize());
                        break;
                    }
                }

                if (process.contains("objectdate")) {
                    if (objectSummary.getKey().contains(key)) {
                        objectlist = String.valueOf(objectSummary.getLastModified());
                        break;
                    }

                }
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

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

    return objectlist;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String deleteBucket(String access_key, String secret_key, String bucket, String endpoint, String region) {
    String message = null;/*from   w  w  w .j a v  a  2 s .co  m*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    message = ("\nDeleting bucket: " + bucket);
    try {
        s3Client.deleteBucket(new DeleteBucketRequest(bucket));
    } catch (Exception Delete) {
        if (terminal) {
            System.out.print("\n\n\n" + Delete.getMessage() + "\n\n\n");
        } else {
            message = message + "\n" + Delete.getMessage();
        }
    }

    if (message == null) {
        message = "\nDelete operation failed.";
    }

    return message;
}

From source file:cloudExplorer.BucketMigration.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);// w ww .  jav  a2  s.c om

    String[] array = new String[10];

    String bucketlist = null;

    try {

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

    } catch (Exception listBucket) {
        mainFrame.jTextArea1.append("\n\nAn error has occurred in listBucket.");
        mainFrame.jTextArea1.append("\n\nError Message:    " + listBucket.getMessage());
    }
    String parse = null;

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

    } else {
        parse = "no_bucket_found";
    }

    return parse;
}

From source file:cloudExplorer.BucketTransition.java

License:Open Source License

public void run() {
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);/*  w w  w. j a  v a 2 s .co m*/
    int converted_days = 0;
    if (!disabled) {
        converted_days = Integer.parseInt(days);
    }
    BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = null;
    if (!disabled) {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule().withPrefix(prefix)
                .withExpirationInDays(converted_days)
                .withStatus(BucketLifecycleConfiguration.ENABLED.toString());
    } else {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule().withPrefix(prefix)
                .withExpirationInDays(100).withStatus(BucketLifecycleConfiguration.DISABLED.toString());
    }
    List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();
    rules.add(ruleArchiveAndExpire);

    try {
        BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration().withRules(rules);
        s3Client.setBucketLifecycleConfiguration(bucket, configuration);
    } catch (Exception get) {
        mainFrame.jTextArea1.append("\n" + get.getMessage());
    }
    if (!disabled) {
        mainFrame.jTextArea1.append("\nSent request to change bucket life cycle to " + converted_days
                + " day(s). Please observe for any errors.");
    } else {
        mainFrame.jTextArea1
                .append("\nSent request to disable the bucket life cycle. Please observe for any errors.");
    }
    calibrate();
    mainFrame.jPanel9.setVisible(true);
}

From source file:cloudExplorer.BucketTransitionGlacier.java

License:Open Source License

public void run() {
    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  a v  a2s. c o  m*/
    int converted_days = 0;
    if (!disabled) {
        converted_days = Integer.parseInt(days);
    }

    Transition transToArchive = new Transition().withDays(converted_days)
            .withStorageClass(StorageClass.Glacier);

    BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = null;
    if (!disabled) {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule().withPrefix(prefix)
                .withTransition(transToArchive)
                // .withExpirationInDays(converted_days + 1)
                .withStatus(BucketLifecycleConfiguration.ENABLED.toString());
    } else {
        ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule().withPrefix(prefix)
                .withTransition(transToArchive)
                //.withExpirationInDays(100)
                .withStatus(BucketLifecycleConfiguration.DISABLED.toString());
    }
    List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();
    rules.add(ruleArchiveAndExpire);

    try {
        BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration().withRules(rules);
        s3Client.setBucketLifecycleConfiguration(bucket, configuration);
    } catch (Exception get) {
        mainFrame.jTextArea1.append("\n" + get.getMessage());
    }
    if (!disabled) {
        mainFrame.jTextArea1.append("\nSent request to set bucket life cycle to tier to Glacier after: "
                + converted_days + " day(s). Please observe for any errors.");
    } else {
        mainFrame.jTextArea1
                .append("\nSent request to disable the bucket life cycle. Please observe for any errors.");
    }
    calibrate();
}

From source file:cloudExplorer.Delete.java

License:Open Source License

public void run() {
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);/*  w  ww . java  2s .  c o m*/

    try {

        if (version != null) {
            s3Client.deleteVersion(new DeleteVersionRequest(bucket, what, version));
        } else {
            s3Client.deleteObject(new DeleteObjectRequest(bucket, what));
        }
        if (!debug) {
            NewJFrame.jTextArea1.append("\nDeleted object: " + what);
        }
        calibrate();
    } 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 delete) {
    }
}

From source file:cloudExplorer.Get.java

License:Open Source License

public void run() {
    String message = null;/*from w  w w  . j  av a2s . c  o  m*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        long t1 = System.currentTimeMillis();
        S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, what, version));
        InputStream objectData = s3object.getObjectContent();
        this.writeFile(objectData, destination);
        long t2 = System.currentTimeMillis();
        long diff = t2 - t1;

        if (!mainFrame.perf) {
            if (terminal) {
                System.out.print("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).\n");
            } else {
                mainFrame.jTextArea1.append("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).");
                mainFrame.calibrateTextArea();
            }
        }

    } 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 get) {
    }
    calibrate();
}

From source file:cloudExplorer.Put.java

License:Open Source License

public void run() {
    try {//from w w  w.j a  v a2s  .com
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        TransferManager tx = new TransferManager(s3Client);
        File file = new File(what);
        PutObjectRequest putRequest;
        if (!rrs) {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file);
        } else {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file)
                    .withStorageClass(StorageClass.ReducedRedundancy);
        }
        MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
        String mimeType = mimeTypesMap.getContentType(file);
        mimeType = mimeTypesMap.getContentType(file);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        if (encrypt) {
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        }
        if ((ObjectKey.contains(".html")) || ObjectKey.contains(".txt")) {
            objectMetadata.setContentType("text/html");
        } else {
            objectMetadata.setContentType(mimeType);
        }
        long t1 = System.currentTimeMillis();
        putRequest.setMetadata(objectMetadata);
        Upload myUpload = tx.upload(putRequest);
        myUpload.waitForCompletion();
        tx.shutdownNow();
        long t2 = System.currentTimeMillis();
        long diff = t2 - t1;

        if (!mainFrame.perf) {
            if (terminal) {
                System.out.print("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).\n");
            } else {
                mainFrame.jTextArea1
                        .append("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).");
            }
        }
    } 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 put) {
    }

    calibrate();
}

From source file:cloudExplorer.RestoreObject.java

License:Open Source License

public void run() {
    String message = null;/*from   www .j  a  v a  2 s  .  co m*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        GetObjectMetadataRequest request = new GetObjectMetadataRequest(bucket, what);
        ObjectMetadata response = s3Client.getObjectMetadata(request);
        response.getOngoingRestore();

        mainFrame.jTextArea1.append("\nRestored operation ran for Object: " + what
                + ". Please examiene this window for any errors.");
        mainFrame.calibrateTextArea();

    } catch (Exception get) {
        //  mainFrame.jTextArea1.append("\n\nError Message: " + get.getMessage());
    }

    calibrate();
}

From source file:cloudExplorer.Versioning.java

License:Open Source License

void getVersions(String key, String access_key, String secret_key, String bucket, String endpoint) {
    String results = null;/* w ww  .  j  a  v  a 2s  . c o  m*/
    Boolean check_finished = false;

    try {
        mainFrame.jTextArea1.append("\nPlease wait, loading versions.");
        mainFrame.calibrateTextArea();
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);

        VersionListing vListing;
        if (key == null) {
            vListing = s3Client.listVersions(bucket, null);
        } else {
            vListing = s3Client.listVersions(bucket, key);
        }

        List<S3VersionSummary> summary = vListing.getVersionSummaries();

        if (summary.size() == 0) {
            check_finished = true;
        } else {
            check_finished = false;
        }

        for (S3VersionSummary object : summary) {
            if (!Versioning.delete) {
                mainFrame.versioning_date.add(object.getLastModified().toString());
            }
            mainFrame.versioning_id.add(object.getVersionId());
            mainFrame.versioning_name.add(object.getKey());
            System.gc();
        }

        if (Versioning.delete) {
            int i = 0;
            for (String delVer : mainFrame.versioning_name) {
                del = new Delete(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(),
                        mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(),
                        mainFrame.versioning_id.get(i));
                del.startc(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(),
                        mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(),
                        mainFrame.versioning_id.get(i));
                i++;
            }
            if (!check_finished) {
                getVersions(key, access_key, secret_key, bucket, endpoint);
            }
        }

        if (Versioning.delete) {
            mainFrame.jTextArea1.append(
                    "\nCompleted deleting every object. Please observe this window for any tasks that are still running.");
        } else {
            mainFrame.jTextArea1
                    .append("\nDone gathering Versions. If files are found, the first 1000 will be displayed.");
        }
        mainFrame.calibrateTextArea();
    } catch (Exception getVersions) {

    }
    if (Versioning.delete) {
        Versioning.delete = false;
        mainFrame.reloadObjects(false);
    }

}