Example usage for com.amazonaws AmazonServiceException getMessage

List of usage examples for com.amazonaws AmazonServiceException getMessage

Introduction

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

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:org.springframework.cloud.aws.messaging.core.QueueMessageChannel.java

License:Apache License

@Override
protected boolean sendInternal(Message<?> message, long timeout) {
    try {//from   w w  w.j a  v a  2  s. c o  m
        SendMessageRequest sendMessageRequest = new SendMessageRequest(this.queueUrl,
                String.valueOf(message.getPayload())).withDelaySeconds(getDelaySeconds(timeout));
        Map<String, MessageAttributeValue> messageAttributes = getMessageAttributes(message);
        if (!messageAttributes.isEmpty()) {
            sendMessageRequest.withMessageAttributes(messageAttributes);
        }
        this.amazonSqs.sendMessage(sendMessageRequest);
    } catch (AmazonServiceException e) {
        throw new MessageDeliveryException(message, e.getMessage(), e);
    }

    return true;
}

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

License:Apache License

/**
 * Provide a list of objects from a given bucket w/prefix (folder).
 *
 * @param bucketName S3 bucket name/*from w w w .j a  va 2s.co m*/
 * @param prefix     S3 folder within the bucket
 * @return List of {@link S3ObjectSummary} sorted by date
 */
public List<S3ObjectSummary> getAllObjects(String bucketName, String prefix) {

    try {
        logger.debug("Listing S3 objects for s3://{}/{}", bucketName, prefix);
        final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName)
                .withPrefix(prefix);
        ListObjectsV2Result result;
        List<S3ObjectSummary> allObjects = new ArrayList<>();

        do {
            result = s3Client.listObjectsV2(req);

            allObjects.addAll(result.getObjectSummaries());

            req.setContinuationToken(result.getNextContinuationToken());
        } while (result.isTruncated());

        allObjects.sort(Comparator.comparing(S3ObjectSummary::getLastModified));

        return allObjects;
    } 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 null;
}

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

License:Apache License

public InputStream getObject(S3ObjectSummary objectSummary) {

    S3Object object = null;//  ww w .j a v  a 2s.  c om

    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 {/*www .j  a v a2  s.  c om*/
        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 {/*w  w w .  java2s  .com*/
        // 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  av  a2  s  .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
    */
    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.gradle.AwsPluginExtension.java

License:BSD License

public String getUserArn() {
    AmazonIdentityManagement iam = createClient(AmazonIdentityManagementClient.class, profileName);
    try {//from w w  w .  ja  va 2  s  .c  o  m
        GetUserResult getUserResult = iam.getUser();
        return getUserResult.getUser().getArn();
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("AccessDenied") == false) {
            throw e;
        }
        String msg = e.getMessage();
        int arnIdx = msg.indexOf("arn:aws");
        if (arnIdx == -1) {
            throw e;
        }
        int arnSpace = msg.indexOf(" ", arnIdx);
        return msg.substring(arnIdx, arnSpace);
    }
}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationCreateStackTask.java

License:BSD License

@TaskAction
public void createStack() throws InterruptedException {
    // to enable conventionMappings feature
    String stackName = getStackName();
    if (stackName == null)
        throw new GradleException("stackName is not specified");

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {//  www.j  a  v a  2s  .c om
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);
        throw new GradleException("Stack exists. invalid status for create: " + stack.getStackStatus());

    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().info("stack {} not found", stackName);
            createStack(cfn);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            // ignore
        } else {
            throw e;
        }
    }
}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java

License:BSD License

@TaskAction
public void createOrUpdateStack() throws InterruptedException {
    // to enable conventionMappings feature
    String stackName = getStackName();
    String templateBody = getTemplateBody();
    List<String> stableStatuses = getStableStatuses();

    if (stackName == null)
        throw new GradleException("stackName is not specified");

    if (templateBody == null && !usePreviousTemplate)
        throw new GradleException("templateBody is not specified");
    if (templateBody != null && usePreviousTemplate)
        throw new GradleException("templateBody cannot be specified with usePreviousTemplate");

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {/*from  w ww .j  ava 2 s . c o  m*/
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);
        if (stack.getStackStatus().equals("DELETE_COMPLETE")) {
            getLogger().warn("deleted stack {} already exists", stackName);
            deleteStack(cfn);
            createStack(cfn);
        } else if (stableStatuses.contains(stack.getStackStatus())) {
            updateStack(cfn);
        } else {
            throw new GradleException("invalid status for update: " + stack.getStackStatus());
        }
    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().warn("stack {} not found", stackName);
            createStack(cfn);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            // ignore
        } else {
            throw e;
        }
    }
}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationUpdateStackTask.java

License:BSD License

@TaskAction
public void updateStack() throws InterruptedException {
    // to enable conventionMappings feature
    String stackName = getStackName();
    String cfnTemplateUrl = getCfnTemplateUrl();
    // String cfnTemplateBody = getCnfTemplateBody();
    List<String> stableStatuses = getStableStatuses();

    if (stackName == null)
        throw new GradleException("stackName is not specified");

    if (templateBody == null && !usePreviousTemplate)
        throw new GradleException("templateBody is not specified");
    if (templateBody != null && usePreviousTemplate)
        throw new GradleException("templateBody cannot be specified with usePreviousTemplate");

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {//ww  w  .  j ava 2 s  .c  om
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);
        if (stack.getStackStatus().equals("DELETE_COMPLETE")) {
            getLogger().warn("deleted stack {} already exists - recreating", stackName);
            deleteStack(cfn);
            createStack(cfn);
        } else if (stableStatuses.contains(stack.getStackStatus())) {
            updateStack(cfn);
        } else {
            throw new GradleException("invalid status for update: " + stack.getStackStatus());
        }
    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().warn("stack {} not found", stackName);
            createStack(cfn);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            // ignore
        } else {
            throw e;
        }
    }
}