Search in sources :

Example 1 with AwsException

use of com.adeptj.modules.aws.core.AwsException in project adeptj-modules by AdeptJ.

the class AwsS3Service method createFolder.

/**
 * {@inheritDoc}
 */
@Override
public S3Response createFolder(String bucketName, String folderName) {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(0);
    try {
        return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(bucketName, folderName + PATH_SEPARATOR, new ByteArrayInputStream(new byte[0]), objectMetadata)));
    } catch (RuntimeException ex) {
        LOGGER.error("Exception while creating folder!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : S3Response(com.adeptj.modules.aws.s3.S3Response) ByteArrayInputStream(java.io.ByteArrayInputStream) AwsException(com.adeptj.modules.aws.core.AwsException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 2 with AwsException

use of com.adeptj.modules.aws.core.AwsException in project adeptj-modules by AdeptJ.

the class AwsSnsService method start.

@Activate
protected void start(SmsConfig smsConfig) {
    this.smsAttributes = new HashMap<>();
    this.smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue().withStringValue(smsConfig.senderId()).withDataType("String"));
    this.smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue().withStringValue(smsConfig.smsType()).withDataType("String"));
    try {
        this.asyncSNS = AmazonSNSAsyncClient.asyncBuilder().withEndpointConfiguration(AwsUtil.getEndpointConfig(smsConfig.serviceEndpoint(), smsConfig.signingRegion())).withCredentials(AwsUtil.getCredentialsProvider(smsConfig.accessKey(), smsConfig.secretKey())).build();
    } catch (Exception ex) {
        LOGGER.error("Exception while starting SmsService!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : AwsException(com.adeptj.modules.aws.core.AwsException) AwsException(com.adeptj.modules.aws.core.AwsException) MessageAttributeValue(com.amazonaws.services.sns.model.MessageAttributeValue) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with AwsException

use of com.adeptj.modules.aws.core.AwsException in project adeptj-modules by AdeptJ.

the class AwsS3Service method uploadFile.

/**
 * {@inheritDoc}
 */
@Override
public S3Response uploadFile(S3Request request) {
    ObjectMetadata objectMetadata = Objects.requireNonNull(request.getMetadata(), OBJ_METADATA_NULL_MSG);
    CannedAccessControlList cannedACL = Objects.requireNonNull(request.getCannedACL(), ACL_NULL_MSG);
    try (InputStream data = Objects.requireNonNull(request.getData(), DATA_NULL_MSG)) {
        return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(request.getBucketName(), request.getKey(), data, objectMetadata).withCannedAcl(cannedACL)));
    } catch (Exception ex) {
        LOGGER.error("Exception while uploading file!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : S3Response(com.adeptj.modules.aws.s3.S3Response) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AwsException(com.adeptj.modules.aws.core.AwsException) CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) AwsException(com.adeptj.modules.aws.core.AwsException)

Aggregations

AwsException (com.adeptj.modules.aws.core.AwsException)3 S3Response (com.adeptj.modules.aws.s3.S3Response)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CannedAccessControlList (com.amazonaws.services.s3.model.CannedAccessControlList)1 MessageAttributeValue (com.amazonaws.services.sns.model.MessageAttributeValue)1 InputStream (java.io.InputStream)1 Activate (org.osgi.service.component.annotations.Activate)1