use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project photon-model by vmware.
the class TestAWSClientManagement method testAwsS3ClientManagement.
@Test
public void testAwsS3ClientManagement() throws Throwable {
// Ensure that we start with a clean state.
AWSClientManagerFactory.cleanUp(AwsClientType.S3_TRANSFER_MANAGER);
// Get a reference to the client manager in the test
AWSClientManager s3ClientManager = getClientManager(AwsClientType.S3_TRANSFER_MANAGER);
assertEquals(1, getClientReferenceCount(AwsClientType.S3_TRANSFER_MANAGER));
AuthCredentialsServiceState testCreds = new AuthCredentialsServiceState();
testCreds.privateKey = this.accessKey;
testCreds.privateKeyId = this.secretKey;
final AmazonS3Client[] s3Client = new AmazonS3Client[1];
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
s3ClientManager.getOrCreateS3TransferManagerAsync(testCreds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(i -> waitContext.complete());
waitContext.await();
assertEquals(1, s3ClientManager.getCacheCount());
// Return the references from the test
returnClientManager(s3ClientManager, AwsClientType.S3_TRANSFER_MANAGER);
assertEquals(0, getClientReferenceCount(AwsClientType.S3_TRANSFER_MANAGER));
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project wildfly-camel by wildfly-extras.
the class S3Utils method createS3Client.
// Attach Policy: AmazonS3FullAccess
public static AmazonS3Client createS3Client() {
BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
AmazonS3Client client = !credentials.isValid() ? null : (AmazonS3Client) AmazonS3ClientBuilder.standard().withCredentials(credentials).withRegion("eu-west-1").build();
return client;
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project wildfly-camel by wildfly-extras.
the class S3IntegrationTest method testBucketOperations.
@Test
public void testBucketOperations() throws Exception {
AmazonS3Client s3Client = provider.getClient();
Assume.assumeNotNull("AWS client not null", s3Client);
assertNoStaleBuckets(s3Client, "before");
try {
try {
S3Utils.createBucket(s3Client, bucketName);
WildFlyCamelContext camelctx = new WildFlyCamelContext();
camelctx.getNamingContext().bind("s3Client", s3Client);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
String clientref = "amazonS3Client=#s3Client";
from("direct:upload").to("aws-s3://" + bucketName + "?" + clientref);
from("aws-s3://" + bucketName + "?" + clientref).to("seda:read");
}
});
try {
camelctx.start();
try {
// Put object
Map<String, Object> headers = new HashMap<>();
headers.put(S3Constants.KEY, OBJECT_KEY);
ProducerTemplate producer = camelctx.createProducerTemplate();
String content = "My bucket content";
String result1 = producer.requestBodyAndHeaders("direct:upload", content, headers, String.class);
Assert.assertEquals(content, result1);
ConsumerTemplate consumer = camelctx.createConsumerTemplate();
String result2 = consumer.receiveBody("seda:read", String.class);
Assert.assertEquals(content, result2);
} finally {
camelctx.stop();
}
} finally {
s3Client.deleteObject(bucketName, OBJECT_KEY);
}
} finally {
S3Utils.deleteBucket(s3Client, bucketName);
}
} finally {
assertNoStaleBuckets(s3Client, "after");
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project opentest by mcdcorp.
the class GetS3Metadata method run.
@Override
public void run() {
super.run();
String awsCredentialsProfile = this.readStringArgument("awsProfile", "default");
String bucket = this.readStringArgument("bucket");
String objectKey = this.readStringArgument("objectKey");
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider(awsCredentialsProfile));
ObjectMetadata metadata = s3Client.getObjectMetadata(new GetObjectMetadataRequest(bucket, objectKey));
try {
Date expirationTime = metadata.getExpirationTime();
if (expirationTime != null) {
this.writeOutput("expirationTime", metadata.getExpirationTime().getTime());
} else {
this.writeOutput("expirationTime", null);
}
this.writeOutput("lastModified", metadata.getLastModified().getTime());
this.writeOutput("userMetadata", metadata.getUserMetadata());
this.writeOutput("size", metadata.getContentLength());
this.writeOutput("storageClass", metadata.getStorageClass());
this.writeOutput("versionId", metadata.getVersionId());
} catch (Exception ex) {
throw new RuntimeException(String.format("Failed to get object metadata for object key %s in bucket %s", objectKey, bucket), ex);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project SimpleContentPortlet by Jasig.
the class AmazonS3PersistenceStrategy method persistAttachmentBinary.
@Override
public String persistAttachmentBinary(HttpServletRequest request, Attachment attachment) throws PersistenceException {
// The data import is only going to update the attachment metadata in the database.
if (request == null && attachment.getData() == null) {
return null;
}
AmazonS3 s3 = new AmazonS3Client();
String key = PATH_FORMAT.format(new Object[] { s3BucketPath, attachment.getGuid(), attachment.getFilename() });
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(attachment.getContentType());
metadata.setContentLength(attachment.getData().length);
metadata.setCacheControl(s3CacheControlString);
// S3 chose base64-encoded hash not the typical 32-character hex string so convert accordingly.
// Hex.decodeHex(attachment.getChecksum().toCharArray())
metadata.setContentMD5(Base64.encodeBase64String(DatatypeConverter.parseHexBinary(attachment.getChecksum())));
try {
s3.putObject(new PutObjectRequest(s3BucketName, key, new ByteArrayInputStream(attachment.getData()), metadata));
log.debug("Successfully sent {} to S3 bucket {} under key {}", attachment.getFilename(), s3BucketName, key);
} catch (AmazonClientException e) {
String message = String.format("Unable to persist attachment %1s to S3 bucket %2s, key %3s", attachment.getFilename(), s3BucketName, key);
throw new PersistenceException(message, e);
}
return (s3BucketBaseUrl.endsWith("/") ? s3BucketBaseUrl : s3BucketBaseUrl + "/") + key;
}
Aggregations