Example usage for com.amazonaws AmazonServiceException getRequestId

List of usage examples for com.amazonaws AmazonServiceException getRequestId

Introduction

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

Prototype

public String getRequestId() 

Source Link

Document

Returns the AWS request ID that uniquely identifies the service request the caller made.

Usage

From source file:ics.uci.edu.amazons3.S3Sample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*from w w w.  j a v a 2s. co  m*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     * 
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    final AmazonS3 s3 = new AmazonS3Client(
            new BasicAWSCredentials("AKIAJTW5BOY6EXOGV2YQ", "PDcnFYIf9Hdo9GsKTEjLXretZ3yEg4mRCDQKjxu6"));

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "MyObjectKey";

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon S3");
    System.out.println("===========================================\n");

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
         */
        System.out.println("Creating bucket " + bucketName + "\n");
        s3.createBucket(bucketName);

        /*
         * List the buckets in your account
         */
        System.out.println("Listing buckets");
        for (Bucket bucket : s3.listBuckets()) {
            System.out.println(" - " + bucket.getName());
        }
        System.out.println();

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
         */
        System.out.println("Uploading a new object to S3 from a file\n");
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
         */
        System.out.println("Downloading an object");
        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());

        /*
         * List objects in your bucket by prefix - There are many options for
         * listing the objects in your bucket.  Keep in mind that buckets with
         * many objects might truncate their results when listing their objects,
         * so be sure to check if the returned object listing is truncated, and
         * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
         * additional results.
         */
        System.out.println("Listing objects");
        ObjectListing objectListing = s3
                .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My"));
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(
                    " - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
        }
        System.out.println();

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
         */
        System.out.println("Deleting an object\n");
        s3.deleteObject(bucketName, key);

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
         */
        System.out.println("Deleting bucket " + bucketName + "\n");
        s3.deleteBucket(bucketName);
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:ie.peternagy.jcrypto.module.config.S3ConfigHandler.java

License:Open Source License

@Override
public void validateConfig(Map config) {
    AWSCredentials credentials = new BasicAWSCredentials((String) config.get("access-key"),
            (String) config.get("secret-key"));
    AmazonS3 s3client = new AmazonS3Client(credentials);
    try {/*  www  .ja  v  a 2 s.c  o  m*/
        System.out.println("S3 config validation...\n");
        s3client.doesBucketExist((String) config.get("bucket-name"));

        System.out.println("Valid configuration!\n");
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:iit.edu.supadyay.s3.S3upload.java

public static boolean upload(String bucketName, String uploadFileName, String keyName)
        throws IOException, InterruptedException {

    //access = "AKIAJ2YSLRUZR5B3F5HQ";
    //secret = "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";
    //AWSCredentials credentials = new BasicAWSCredentials(access, secret);
    //AmazonS3 s3client = new AmazonS3Client(getCredentials());
    AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
    try {/*from   www. jav a2 s  .c  o  m*/
        System.out.println("Uploading a new object to S3 from a file\n");
        File file = new File(uploadFileName);
        System.out.println("I am before here\n");
        s3client.createBucket(bucketName);
        System.out.println("I am here\n");

        s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
        s3client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicReadWrite);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
        return false;
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
        return false;
    }
    return true;
}

From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java

License:Open Source License

public static void main(String[] args) {
    init();//from w  ww.  ja  va  2  s.  c  o m

    try {
        String tableName = "water-safe-locations-table";
        config = new GeoDataManagerConfiguration(dynamoDB, tableName);
        geoDataManager = new GeoDataManager(config);
        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'name', which holds a string

            /*
             CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name").withAttributeType(ScalarAttributeType.S))
            .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
            TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest).getTableDescription();
             */
            //AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

            CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config);
            CreateTableResult createTableResult = dynamoDB.createTable(createTableRequest);
            System.out.println("Created Table: " + tableName);

            // Wait for it to become active
            System.out.println("Waiting for " + tableName + " to become ACTIVE...");
            Tables.waitForTableToBecomeActive(dynamoDB, tableName);
        }

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        Map<String, String> m = new HashMap<>();
        m.put("lat", "51.5034070");
        m.put("lng", "-0.1275920");
        m.put("violationCode", "47");

        // request = new JSONObject(m);
        //try {
        //    putPoint(request);
        //}catch(JSONException f){
        //    System.out.println("Bad JSON");
        //}
        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                .withAttributeValueList(new AttributeValue().withN("1985"));
        scanFilter.put("year", condition);
        ScanRequest scanRequest = new ScanRequest(tableName);//.withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        System.out.println("Result: " + scanResult);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//w  w  w .  j a v a  2  s .  c o  m
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */

    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

    AmazonSNS sns = new AmazonSNSClient(
            new PropertiesCredentials(SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties")));

    // AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Initializing Communication with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        /* TODO: Uncomment the services you wish to use. */
        // sample.starterAndroidAppNotification();
        // sample.starterKindleAppNotification();
        sample.starterAppleAppNotification();
        // sample.starterAppleSandboxAppNotification();
        // sample.starterBaiduAppNotification();
        // sample.starterWNSAppNotification();
        // sample.starterMPNSAppNotification();
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SNS, such as not "
                + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:jetbrains.buildServer.util.amazon.AWSException.java

License:Apache License

@Nullable
public static String getDetails(@NotNull Throwable t) {
    if (t instanceof AWSException)
        return ((AWSException) t).getDetails();
    if (t instanceof AmazonServiceException) {
        final AmazonServiceException ase = (AmazonServiceException) t;
        return "\n" + "Service:             " + ase.getServiceName() + "\n" + "HTTP Status Code:    "
                + ase.getStatusCode() + "\n" + "AWS Error Code:      " + ase.getErrorCode() + "\n"
                + "Error Type:          " + ase.getErrorType() + "\n" + "Request ID:          "
                + ase.getRequestId();
    }//from   ww  w  .j a  v a  2s.  c  o m
    return null;
}

From source file:jp.dqneo.amazons3.sample.S3Sample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*// w  w w  .j  av  a 2s  . c  om
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonS3 s3 = new AmazonS3Client(
            new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties")));

    s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com");

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "2/foo/bar";

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon S3");
    System.out.println("===========================================\n");

    try {

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
         */
        System.out.println("Uploading a new object to S3 from a file\n");
        PutObjectRequest p = new PutObjectRequest(bucketName, key, createSampleFile());
        s3.putObject(p);
        System.out.println("ok\n");

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:main.java.ddb.loader.DDBLoaderUtils.java

License:Apache License

static void createTable() throws Exception {
    try {/*w w w  .j av  a2s. c o m*/
        CreateTableRequest create_req = new CreateTableRequest().withTableName(DDBSampleLoader.TBL_NAME)
                .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(DDBSampleLoader.RCU)
                                .withWriteCapacityUnits(DDBSampleLoader.WCU));

        DDBSampleLoader.log.info("Creating a new table ...");
        TableUtils.createTableIfNotExists(DDBSampleLoader.ddb_client, create_req);

        DDBSampleLoader.log.info("Waiting for the table status to be 'ACTIVE' ...");
        TableUtils.waitUntilActive(DDBSampleLoader.ddb_client, DDBSampleLoader.TBL_NAME);

    } catch (AmazonServiceException e) {
        DDBSampleLoader.log.error("Caught an AmazonServiceException ...");
        DDBSampleLoader.log.error("Error Message:    " + e.getMessage());
        DDBSampleLoader.log.error("HTTP Status Code: " + e.getStatusCode());
        DDBSampleLoader.log.error("AWS Error Code:   " + e.getErrorCode());
        DDBSampleLoader.log.error("Error Type:       " + e.getErrorType());
        DDBSampleLoader.log.error("Request ID:       " + e.getRequestId());

    } catch (AmazonClientException e) {
        DDBSampleLoader.log.error("Caught an AmazonClientException ...");
        DDBSampleLoader.log.error("Error Message:    " + e.getMessage());
    }
}

From source file:modules.storage.AmazonS3Storage.java

License:Open Source License

private void logAmazonServiceException(AmazonServiceException ase) {
    logger.error("Caught an AmazonServiceException, which " + "means your request made it "
            + "to Amazon S3, but was rejected with an error response " + "for some reason." + " Error Message: "
            + ase.getMessage() + " HTTP Status Code: " + ase.getStatusCode() + " AWS Error Code: "
            + ase.getErrorCode() + " Error Type: " + ase.getErrorType() + " Request ID: " + ase.getRequestId(),
            ase);//  w w w  . j a  v  a  2s.co  m
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public Set<S3ObjectReference> listObjects(String prefix) throws IOException {
    AmazonS3 client = getClient();/*from w ww  .ja v a2  s . c o m*/
    Set<S3ObjectReference> result = new LinkedHashSet<>(100);
    try {
        final ListObjectsV2Request req = new ListObjectsV2Request();
        req.setBucketName(bucketName);
        req.setMaxKeys(maximumKeysPerRequest);
        req.setPrefix(prefix);
        ListObjectsV2Result listResult;
        do {
            listResult = client.listObjectsV2(req);

            for (S3ObjectSummary objectSummary : listResult.getObjectSummaries()) {
                result.add(new S3ObjectReference(objectSummary.getKey(), objectSummary.getSize(),
                        objectSummary.getLastModified()));
            }
            req.setContinuationToken(listResult.getNextContinuationToken());
        } while (listResult.isTruncated() == true);

    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error listing S3 objects at " + prefix, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
    return result;
}