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:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean deleteEntity(String bucketName, String keyName) {
    LOG.info("Deletes the specified object " + keyName + " in the specified bucket " + bucketName);
    try {//from   w w w.  j a va 2s . c o  m
        amazonS3Client.deleteObject(bucketName, keyName);
        return true;
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean deleteEntities(String bucketName) {
    LOG.info("Deletes multiple objects in a bucket " + bucketName + " from Amazon S3");
    List<S3ObjectSummary> s3ObjectSummaries = findEntityByBucket(bucketName);
    if (s3ObjectSummaries == null || s3ObjectSummaries.isEmpty()) {
        return false;
    }/* w ww  .j a  v  a  2  s. c  om*/

    // Provide a list of object keys and versions.
    List<KeyVersion> keyVersions = new ArrayList<KeyVersion>();
    for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries) {
        keyVersions.add(new KeyVersion(s3ObjectSummary.getKey()));
    }

    try {
        DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keyVersions);
        DeleteObjectsResult deleteObjectsResult = amazonS3Client.deleteObjects(deleteObjectsRequest);
        if (deleteObjectsResult != null) {
            LOG.info("Successfully deleted all the " + deleteObjectsResult.getDeletedObjects().size()
                    + " items.\n");
            return true;
        }
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean publicEntity(String bucketName, String keyName) {
    LOG.info("Sets the CannedAccessControlList for the specified object " + keyName
            + " in Amazon S3 using one of the pre-configured CannedAccessControlLists");

    try {/*from w  w  w. j a  v  a 2 s  . c o  m*/
        amazonS3Client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicRead);
        return true;
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean copyEntity(String sourceBucketName, String sourceKeyName, String destinationBucketName,
        String destinationKeyName) {

    // If target bucket name is null or empty, that mean copy inside current
    // bucket.//  w ww.j a  v  a2 s. c  om
    if (StringUtils.isEmpty(destinationBucketName)) {
        destinationBucketName = sourceBucketName;
    }

    LOG.info("Copies a source object " + sourceKeyName + " from a source bucket " + sourceBucketName
            + " to a new destination bucket " + destinationBucketName + " with specified key "
            + destinationKeyName + " in Amazon S3");

    try {
        CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourceBucketName, sourceKeyName,
                destinationBucketName, destinationKeyName);
        CopyObjectResult copyObjectResult = amazonS3Client.copyObject(copyObjectRequest);
        if (copyObjectResult != null) {
            LOG.info(
                    "A CopyObjectResult object containing the information returned by Amazon S3 about the newly created object: "
                            + copyObjectResult);
            return true;
        }
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean isPublicEntity(String bucketName, String keyName) {
    LOG.info("Gets the AccessControlList (ACL) for the specified object " + keyName
            + " in the specified bucket " + bucketName);

    final String GROUPS_USERS = "http://acs.amazonaws.com/groups/global/AllUsers";
    try {/*from   ww w.j av  a 2 s.  c  o m*/
        AccessControlList accessControlList = amazonS3Client.getObjectAcl(bucketName, keyName);
        for (Iterator<Grant> iterator = accessControlList.getGrants().iterator(); iterator.hasNext();) {
            Grant grant = iterator.next();
            if (grant.getPermission().equals(Permission.Read)
                    && grant.getGrantee().getIdentifier().equals(GROUPS_USERS)) {
                return true;
            }
        }
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public boolean downloadEntity(String bucketName, String keyNotAvailable, File destinationFile) {
    LOG.info("Gets the object metadata for the object stored in Amazon S3 under the specified bucket "
            + bucketName + " and key " + keyNotAvailable
            + ", and saves the object contents to the specified file " + destinationFile);
    try {//  w  w w .  j av  a2  s. co  m
        ObjectMetadata objectMetadata = amazonS3Client
                .getObject(new GetObjectRequest(bucketName, keyNotAvailable), destinationFile);
        if (objectMetadata != null) {
            return true;
        }
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public InputStream downloadEntity(String bucketName, String keyName) {
    LOG.info("Gets the object stored in Amazon S3 under the specified bucket " + bucketName + " and key "
            + keyName);//from  ww w. j  a  va2s  .  c o m
    try {
        S3Object s3Object = amazonS3Client.getObject(bucketName, keyName);
        if (s3Object != null) {
            return s3Object.getObjectContent();
        }
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return null;
}

From source file:io.milton.s3.AmazonS3ManagerImpl.java

License:Open Source License

@Override
public S3Object findEntityByUniqueKey(String bucketName, String keyName) {
    if (StringUtils.isEmpty(keyName)) {
        return null;
    }/*  w w  w  .  j  av  a2  s .c  om*/

    LOG.info("Gets the object stored in Amazon S3 under the specified bucket " + bucketName + " and key "
            + keyName);
    try {
        return amazonS3Client.getObject(bucketName, keyName);
    } catch (AmazonServiceException ase) {
        LOG.warn(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.warn(ace.getMessage(), ace);
    }
    return null;
}

From source file:io.milton.s3.db.DynamoDBServiceImpl.java

License:Open Source License

@Override
public boolean createTable(String tableName) {
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(AttributeKey.UUID)
            .withAttributeType(ScalarAttributeType.S));

    List<KeySchemaElement> keySchemaElement = new ArrayList<KeySchemaElement>();
    keySchemaElement.add(new KeySchemaElement().withAttributeName(AttributeKey.UUID).withKeyType(KeyType.HASH));

    // Provide the initial provisioned throughput values as Java long data types
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(10L);

    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withAttributeDefinitions(attributeDefinitions).withKeySchema(keySchemaElement)
            .withProvisionedThroughput(provisionedThroughput);

    try {//from   w w w. j a  v a  2s.  c  om
        CreateTableResult createdTableDescription = dynamoDBClient.createTable(createTableRequest);
        LOG.info("Creating table description: " + createdTableDescription);

        // Wait for it to become active
        waitForTableAvailable(tableName);
        if (describeTable(tableName) != null) {
            return true;
        }
    } catch (ResourceInUseException rie) {
        LOG.warn("Table " + tableName + " already exists");
    } catch (AmazonServiceException ase) {
        LOG.error(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error(ace.getMessage(), ace);
    }
    return false;
}

From source file:io.milton.s3.db.DynamoDBServiceImpl.java

License:Open Source License

@Override
public boolean deleteTable(String tableName) {
    try {/*from  w w w  . j  a v a 2s.  co m*/
        DeleteTableRequest deleteTableRequest = new DeleteTableRequest().withTableName(tableName);
        DeleteTableResult deleteTableResult = dynamoDBClient.deleteTable(deleteTableRequest);
        if (deleteTableRequest != null) {
            LOG.info("Deleting table description: " + deleteTableResult);

            // Waiting for table deleted
            waitForTableDeleted(tableName);
            LOG.info("Successfully deleted table " + tableName);
            return true;
        }
    } catch (ResourceInUseException rie) {
        LOG.warn("Table " + tableName + " already exists");
    } catch (AmazonServiceException ase) {
        LOG.error(ase.getMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error(ace.getMessage(), ace);
    }
    return false;
}