Example usage for com.amazonaws AmazonServiceException getErrorCode

List of usage examples for com.amazonaws AmazonServiceException getErrorCode

Introduction

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

Prototype

public String getErrorCode() 

Source Link

Document

Returns the AWS error code represented by this exception.

Usage

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

License:Apache License

@Nullable
public static String getIdentity(@NotNull Throwable t) {
    if (t instanceof AWSException)
        return ((AWSException) t).getIdentity();
    if (t instanceof AmazonServiceException) {
        final AmazonServiceException ase = (AmazonServiceException) t;
        return ase.getServiceName() + ase.getErrorType().name() + String.valueOf(ase.getStatusCode())
                + ase.getErrorCode();
    }/*from  ww  w.  j a  v  a 2  s.  c  o m*/
    return null;
}

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 w w w . j  a v a 2  s.  c o m*/
    }
    return null;
}

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

License:Open Source License

protected DataAccessException processUpdateItemException(K key, AmazonClientException e) {
    final String format = "unable to update entity due to %s.";
    if (e instanceof ConditionalCheckFailedException) {
        if (null == findOne(key)) {
            return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e);
        }//from   w  w  w.  j a  va 2  s  .  c o  m
        return new OptimisticLockingFailureException(UPDATE_FAILED_NOT_FOUND_OR_BAD_VERSION, e);
    } else if (e instanceof ProvisionedThroughputExceededException) {
        throw new QueryTimeoutException(String.format(Locale.ENGLISH, format, "throttling"), e);
    } else if (e instanceof AmazonServiceException) {
        AmazonServiceException ase = (AmazonServiceException) e;
        if (VALIDATION_EXCEPTION.equals(ase.getErrorCode())) {
            if (EXPRESSION_REFERS_TO_NON_EXTANT_ATTRIBUTE.equals(ase.getErrorMessage())
                    && null == findOne(key)) {
                // if no locking and we get a specific message, then it also means the item does not exist
                return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e);
            }
            return new InvalidDataAccessResourceUsageException(
                    String.format(Locale.ENGLISH, format, "client error"), e);
        } else {
            return new DynamoDbServiceException(String.format(Locale.ENGLISH, format, "DynamoDB service error"),
                    ase);
        }
    } else {
        return new InvalidDataAccessResourceUsageException(
                String.format(Locale.ENGLISH, format, "client error"), e);
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupEgressTask.java

License:Apache License

@TaskAction
public void authorizeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }/*w ww. ja  v  a2  s  .  c  om*/
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.authorizeSecurityGroupEgress(new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupIngressTask.java

License:Apache License

@TaskAction
public void authorizeIngress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }//from ww w  .  ja  v a 2s.c o  m
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2CreateSecurityGroupTask.java

License:Apache License

@TaskAction
public void authorizeIngress() {
    // to enable conventionMappings feature
    String groupName = getGroupName();
    String groupDescription = getGroupDescription();

    if (groupName == null) {
        throw new GradleException("groupName is not specified");
    }//from w  w w .j  ava  2s.c om

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        createSecurityGroupResult = ec2.createSecurityGroup(
                new CreateSecurityGroupRequest().withGroupName(groupName).withDescription(groupDescription));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2DeleteSecurityGroupTask.java

License:Apache License

@TaskAction
public void authorizeIngress() {
    // to enable conventionMappings feature
    String groupName = getGroupName();
    String groupId = getGroupId();

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();// ww  w.  j  av  a 2  s  . com

    if (groupName == null && groupId == null) {
        throw new GradleException("groupName nor groupId is not specified");
    }

    try {
        ec2.deleteSecurityGroup(new DeleteSecurityGroupRequest().withGroupId(groupId).withGroupName(groupName));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java

License:Apache License

@TaskAction
public void revokeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }/*from w  ww. j a v a  2  s.c om*/
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupIngressTask.java

License:Apache License

@TaskAction
public void revokeIngress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }/*from www  . ja v a 2s . c om*/
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.revokeSecurityGroupIngress(new RevokeSecurityGroupIngressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

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

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*from  w  ww. j  a v  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());
    }
}