use of 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.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.amazonaws.services.s3.AmazonS3Client in project wildfly-camel by wildfly-extras.
the class S3Utils method createBucket.
@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {
client.createBucket(bucketName);
HeadBucketRequest request = new HeadBucketRequest(bucketName);
Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists();
Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler());
future.get(1, TimeUnit.MINUTES);
}
use of 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.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);
}
}
Aggregations