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:org.symphonyoss.vb.util.AwsS3Client.java

License:Apache License

public InputStream getObject(S3ObjectSummary objectSummary) {

    S3Object object = null;/* ww  w.j  ava  2 s. co  m*/

    try {
        logger.info("Retrieving object inputstream for s3://{}/{}", objectSummary.getBucketName(),
                objectSummary.getKey());
        object = s3Client
                .getObject(new GetObjectRequest(objectSummary.getBucketName(), objectSummary.getKey()));

    } catch (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.");
        logger.error("Error Message:    " + ase.getMessage());
        logger.error("HTTP Status Code: " + ase.getStatusCode());
        logger.error("AWS Error Code:   " + ase.getErrorCode());
        logger.error("Error Type:       " + ase.getErrorType());
        logger.error("Request ID:       " + ase.getRequestId());

    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    }
    return object == null ? null : object.getObjectContent();
}

From source file:org.symphonyoss.vb.util.AwsS3Client.java

License:Apache License

public void putObject(String destBucket, String key, InputStream inputStream, ObjectMetadata metaData) {

    try {// w w w .j  a v a2s.co m
        logger.info("Put object for s3://{}/{}", destBucket, key);
        byte[] bytes = IOUtils.toByteArray(inputStream);

        if (metaData == null)
            metaData = new ObjectMetadata();

        metaData.setContentLength(bytes.length);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

        s3Client.putObject(new PutObjectRequest(destBucket, key, byteArrayInputStream, metaData));

    } catch (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.");
        logger.error("Error Message:    " + ase.getMessage());
        logger.error("HTTP Status Code: " + ase.getStatusCode());
        logger.error("AWS Error Code:   " + ase.getErrorCode());
        logger.error("Error Type:       " + ase.getErrorType());
        logger.error("Request ID:       " + ase.getRequestId());

    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    } catch (IOException e) {
        logger.error("Obtaining length", e);
    }

}

From source file:org.symphonyoss.vb.util.AwsS3Client.java

License:Apache License

public void moveObject(S3ObjectSummary objectSummary, String destBucket, String destKey) {
    try {// ww  w  .ja va2 s. c  o  m
        // Copying object
        CopyObjectRequest copyObjRequest = new CopyObjectRequest(objectSummary.getBucketName(),
                objectSummary.getKey(), destBucket, destKey);

        s3Client.copyObject(copyObjRequest);

        DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(objectSummary.getBucketName(),
                objectSummary.getKey());

        s3Client.deleteObject(deleteObjectRequest);
    } catch (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.");
        logger.error("Error Message:    " + ase.getMessage());
        logger.error("HTTP Status Code: " + ase.getStatusCode());
        logger.error("AWS Error Code:   " + ase.getErrorCode());
        logger.error("Error Type:       " + ase.getErrorType());
        logger.error("Request ID:       " + ase.getRequestId());

    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    }
}

From source file:org.terracotta.TerracottaCloudFormationSample.java

License:Open Source License

@org.junit.BeforeClass
public static void createStack() throws Exception {

    /*//from  w  w  w .  j  a  va2 s . c o  m
    * 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
    */
    amazonCloudFormationClient = new AmazonCloudFormationClient(new PropertiesCredentials(
            TerracottaCloudFormationSample.class.getResourceAsStream("/AwsCredentials.properties")));

    System.out.println("================================");
    System.out.println("Terracotta CloudFormation Sample");
    System.out.println("================================\n");

    try {
        // Create a stack
        CreateStackRequest createRequest = new CreateStackRequest();
        createRequest.setStackName(stackName);
        createRequest.setTemplateBody(convertStreamToString(
                TerracottaCloudFormationSample.class.getResourceAsStream("/TerracottaServerArray.template")));

        Parameter parameter = new Parameter();
        parameter.setParameterKey("KeyName");
        parameter.setParameterValue(keyChainName);
        List parameters = new ArrayList();
        parameters.add(parameter);
        createRequest.setParameters(parameters);
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        amazonCloudFormationClient.createStack(createRequest);

        // Wait for stack to be created
        // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(amazonCloudFormationClient, stackName));

        // Show all the stacks for this account along with the resources for each stack
        for (Stack stack : amazonCloudFormationClient.describeStacks(new DescribeStacksRequest()).getStacks()) {
            System.out.println(
                    "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]");

            DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest();
            stackResourceRequest.setStackName(stack.getStackName());
            for (StackResource resource : amazonCloudFormationClient
                    .describeStackResources(stackResourceRequest).getStackResources()) {
                System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                        resource.getLogicalResourceId(), resource.getPhysicalResourceId());
            }
        }

        // Lookup a resource by its logical name
        DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest();
        logicalNameResourceRequest.setStackName(stackName);
        logicalNameResourceRequest.setLogicalResourceId(logicalResourceName);
        System.out.format("Looking up resource name %1$s from stack %2$s\n",
                logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName());
        for (StackResource resource : amazonCloudFormationClient
                .describeStackResources(logicalNameResourceRequest).getStackResources()) {
            System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                    resource.getLogicalResourceId(), resource.getPhysicalResourceId());
        }

        //deleteStack

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, 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 CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:org.xmlsh.aws.util.AWSCommand.java

License:BSD License

protected int handleException(AmazonServiceException e)
        throws InvalidArgumentException, XMLStreamException, SaxonApiException, CoreException, IOException {
    startResult();//w ww.ja va  2s .c  o m
    startElement("service-exception");
    attribute("error-code", e.getErrorCode());
    attribute("error-message", e.getErrorMessage());
    attribute("service-name", e.getServiceName());
    attribute("request-id", e.getRequestId());
    attribute("status-code", e.getStatusCode());
    endElement();
    endResult();
    return e.getStatusCode();
}

From source file:org.zalando.stups.fullstop.plugin.SaveSecurityGroupsPlugin.java

License:Apache License

private List<String> listS3Objects(String bucketName, String prefix) {
    final List<String> commonPrefixes = Lists.newArrayList();

    AmazonS3Client s3client = new AmazonS3Client();

    try {/*  ww  w  .j a  va  2 s.  c  o  m*/
        System.out.println("Listing objects");

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withDelimiter("/")
                .withBucketName(bucketName).withPrefix(prefix);

        ObjectListing objectListing;

        do {
            objectListing = s3client.listObjects(listObjectsRequest);
            commonPrefixes.addAll(objectListing.getCommonPrefixes());
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                System.out.println(
                        " - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

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

    return commonPrefixes;
}

From source file:org.zalando.stups.fullstop.s3.S3Writer.java

License:Apache License

public void putObjectToS3(String bucket, String fileName, String keyName, ObjectMetadata metadata,
        InputStream stream) {/*from w w w  .  ja v  a  2s  .co  m*/
    AmazonS3 s3client = new AmazonS3Client();
    try {
        logger.info("Uploading a new object to S3 from a file");

        s3client.putObject(
                new PutObjectRequest(bucket, Paths.get(keyName, fileName).toString(), stream, metadata));

    } catch (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.");
        logger.error("Error Message:    " + ase.getMessage());
        logger.error("HTTP Status Code: " + ase.getStatusCode());
        logger.error("AWS Error Code:   " + ase.getErrorCode());
        logger.error("Error Type:       " + ase.getErrorType());
        logger.error("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    }
}

From source file:oulib.aws.s3.S3TiffMetadataProcessorThread.java

@Override
public void run() {

    String sourceBucketName = bookInfo.getBucketSourceName();
    String targetBucketName = bookInfo.getBucketTargetName();
    String bookName = bookInfo.getBookName();

    String bucketFolder = S3Util.S3_TIFF_METADATA_PROCESS_OUTPUT + File.separator + sourceBucketName;
    File bucketFolderFile = new File(bucketFolder);
    if (!bucketFolderFile.exists() || !bucketFolderFile.isDirectory()) {
        bucketFolderFile.mkdirs();//from  w w  w  .j  a  v  a 2s  .c o  m
    }

    String bookPath = bucketFolder + File.separator + bookName;
    File bookFile = new File(bookPath);
    if (!bookFile.exists()) {
        bookFile.mkdir();
    }

    try {

        // Every book has a folder in the target bucket:
        Map targetBucketKeyMap = S3Util.getBucketObjectKeyMap(targetBucketName, bookName, s3client);
        if (!S3Util.folderExitsts(bookName, targetBucketKeyMap)) {
            S3Util.createFolder(targetBucketName, bookName, s3client);
        }

        for (String key : tiffList) {
            if (key.contains(".tif") && matchS3ObjKeyWithFilter(key, filter)
                    && targetBucketKeyMap.containsKey(key)
                    && !targetBucketKeyMap.containsKey(key.split(".tif")[0] + "-copied.tif")) {
                S3Object objectSource = s3client.getObject(new GetObjectRequest(sourceBucketName, key));
                S3Object objectTarget = s3client.getObject(new GetObjectRequest(targetBucketName, key));
                output += ("Start to copy metadata from the source object " + sourceBucketName + "/" + key
                        + " to target object " + targetBucketName + "/" + key + "\n");
                System.out.println("Start to copy metadata from the source object " + sourceBucketName + "/"
                        + key + " to target object " + targetBucketName + "/" + key + "\n");
                S3Util.copyS3ObjectTiffMetadata(s3client, objectSource, objectTarget);
                System.out.println("Finished copy metadata for the object with key=" + key + "\n");
                output += "Finished copy metadata for the object with key=" + key + "\n";
                try {
                    objectSource.close();
                    objectTarget.close();
                } catch (IOException ex) {
                    Logger.getLogger(S3TiffProcessorThread.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        System.out.println(Thread.currentThread().getName() + "'s job is done!");

    } catch (AmazonServiceException ase) {
        output += "Caught an AmazonServiceException, which means your request made it to Amazon S3, but was rejected with an error response for some reason.\n";
        output += "Error Message:    " + ase.getMessage();
        output += "HTTP Status Code: " + ase.getStatusCode();
        output += "AWS Error Code:   " + ase.getErrorCode();
        output += "Error Type:       " + ase.getErrorType();
        output += "Request ID:       " + ase.getRequestId();
        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.\n");
        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) {
        output += "Caught an AmazonClientException, which means the client encountered an internal error while trying to communicate with S3, \nsuch as not being able to access the network.\n";
        output += "Error Message: " + ace.getMessage();
        System.out.println(
                "Caught an AmazonClientException, which means the client encountered an internal error while trying to communicate with S3, \nsuch as not being able to access the network.\n");
        System.out.println("Error Message: " + ace.getMessage());
    } finally {
        outputToFile(bookPath + File.separator + filter + ".txt");
    }
}

From source file:oulib.aws.s3.S3TiffProcessor.java

/**
* 
* @param bookInfo : contains the information of the source bucket name, target bucket name, and the name of the book
* @param context : lambda function runtime context
* @return :/*from  www . j av  a2 s  .c  o m*/
* 
*/
@Override
public String handleRequest(S3BookInfo bookInfo, Context context) {

    AmazonS3 s3client = new AmazonS3Client();
    Region usEast = Region.getRegion(Regions.US_EAST_1);
    s3client.setRegion(usEast);

    try {
        String sourceBucketName = bookInfo.getBucketSourceName();
        String targetBucketName = bookInfo.getBucketTargetName();
        String bookName = bookInfo.getBookName();

        // Every book has a folder in the target bucket:
        Map targetBucketKeyMap = S3Util.getBucketObjectKeyMap(targetBucketName, bookName, s3client);
        if (!S3Util.folderExitsts(bookName, targetBucketKeyMap)) {
            S3Util.createFolder(targetBucketName, bookName, s3client);
        }

        final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(sourceBucketName)
                .withPrefix(bookName + "/data/");
        ListObjectsV2Result result;

        do {
            result = s3client.listObjectsV2(req);

            for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
                String key = objectSummary.getKey();
                if (key.endsWith(".tif") && !targetBucketKeyMap.containsKey(key + ".tif")) {
                    S3Object object = s3client.getObject(new GetObjectRequest(sourceBucketName, key));
                    System.out.println("Start to generate smaller tif image for the object " + key);
                    S3Util.generateSmallTiffWithTargetSize(s3client, object, targetBucketName,
                            bookInfo.getCompressionSize());
                    //                       S3Util.copyS3ObjectTiffMetadata(s3client, object, s3client.getObject(new GetObjectRequest(targetBucketName, key)), targetBucketName, key+".tif");
                    System.out.println("Finished to generate smaller tif image for the object " + key + ".tif");
                    //                       break;
                }
            }
            System.out.println("Next Continuation Token : " + result.getNextContinuationToken());
            req.setContinuationToken(result.getNextContinuationToken());
        } while (result.isTruncated() == true);

    } 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, \nsuch as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
    return null;
}

From source file:oulib.aws.s3.S3TiffProcessorThread.java

@Override
public void run() {

    String sourceBucketName = bookInfo.getBucketSourceName();
    String targetBucketName = bookInfo.getBucketTargetName();
    String bookName = bookInfo.getBookName();

    String bucketFolder = S3Util.S3_SMALL_DERIVATIVE_OUTPUT + File.separator + sourceBucketName;
    File bucketFolderFile = new File(bucketFolder);
    if (!bucketFolderFile.exists() || !bucketFolderFile.isDirectory()) {
        bucketFolderFile.mkdirs();/*from w  ww  . j  a va  2  s.c om*/
    }

    String bookPath = bucketFolder + File.separator + bookName;
    File bookFile = new File(bookPath);
    if (!bookFile.exists()) {
        bookFile.mkdir();
    }

    try {

        // Every book has a folder in the target bucket:
        Map targetBucketKeyMap = S3Util.getBucketObjectKeyMap(targetBucketName, bookName, s3client);
        if (!S3Util.folderExitsts(bookName, targetBucketKeyMap)) {
            S3Util.createFolder(targetBucketName, bookName, s3client);
        }

        //            final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(sourceBucketName).withPrefix(bookName + "/data/");
        //            ListObjectsV2Result result;

        //            do {               
        //                result = s3client.listObjectsV2(req);

        for (String key : tiffList) {
            //                    String key = objectSummary.getKey();
            //                    if(key.contains(".tif") && key.contains(filter) && !targetBucketKeyMap.containsKey(key+".tif")){
            if (key.contains(".tif") && matchS3ObjKeyWithFilter(key, filter)
                    && !targetBucketKeyMap.containsKey(key + ".tif")) {
                S3Object object = s3client.getObject(new GetObjectRequest(sourceBucketName, key));
                output += ("Start to generate smaller tif image for the object " + key + "\n");
                System.out.println("Start to generate smaller tif image for the object " + key + "\n");
                //                        System.out.println("Working on the object "+key);
                S3Util.generateSmallTiffWithTargetSize(s3client, object, targetBucketName,
                        bookInfo.getCompressionSize());
                //                   S3Util.copyS3ObjectTiffMetadata(s3client, object, s3client.getObject(new GetObjectRequest(targetBucketName, key)), targetBucketName, key+".tif");
                System.out.println("Finished to generate smaller tif image for the object " + key + "\n");
                output += "Finished to generate smaller tif image for the object " + key + "\n";
                try {
                    object.close();
                } catch (IOException ex) {
                    Logger.getLogger(S3TiffProcessorThread.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        //                output += "Next Continuation Token : " + result.getNextContinuationToken();
        System.out.println(Thread.currentThread().getName() + "'s job is done!");
        //                req.setContinuationToken(result.getNextContinuationToken());
        //            } while(result.isTruncated() == true ); 

    } catch (AmazonServiceException ase) {
        output += "Caught an AmazonServiceException, which means your request made it to Amazon S3, but was rejected with an error response for some reason.\n";
        output += "Error Message:    " + ase.getMessage();
        output += "HTTP Status Code: " + ase.getStatusCode();
        output += "AWS Error Code:   " + ase.getErrorCode();
        output += "Error Type:       " + ase.getErrorType();
        output += "Request ID:       " + ase.getRequestId();
        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.\n");
        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) {
        output += "Caught an AmazonClientException, which means the client encountered an internal error while trying to communicate with S3, \nsuch as not being able to access the network.\n";
        output += "Error Message: " + ace.getMessage();
        System.out.println(
                "Caught an AmazonClientException, which means the client encountered an internal error while trying to communicate with S3, \nsuch as not being able to access the network.\n");
        System.out.println("Error Message: " + ace.getMessage());
    } finally {
        outputToFile(bookPath + File.separator + filter + ".txt");
    }
}