use of com.amazonaws.services.s3.AmazonS3 in project camel by apache.
the class S3Endpoint method createS3Client.
/**
* Provide the possibility to override this method for an mock implementation
*/
AmazonS3 createS3Client() {
AmazonS3Client client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (configuration.hasProxyConfiguration()) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonS3Client(credentials, clientConfiguration);
} else {
client = new AmazonS3Client(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonS3Client();
} else {
client = new AmazonS3Client(clientConfiguration);
}
}
S3ClientOptions clientOptions = S3ClientOptions.builder().setPathStyleAccess(configuration.isPathStyleAccess()).build();
client.setS3ClientOptions(clientOptions);
return client;
}
use of com.amazonaws.services.s3.AmazonS3 in project camel by apache.
the class S3Producer method copyObject.
private void copyObject(AmazonS3 s3Client, Exchange exchange) {
String bucketNameDestination;
String destinationKey;
String sourceKey;
String bucketName;
String versionId;
bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
if (ObjectHelper.isEmpty(bucketName)) {
bucketName = getConfiguration().getBucketName();
}
sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
bucketNameDestination = exchange.getIn().getHeader(S3Constants.BUCKET_DESTINATION_NAME, String.class);
versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);
if (ObjectHelper.isEmpty(bucketName)) {
throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(bucketNameDestination)) {
throw new IllegalArgumentException("Bucket Name Destination must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(sourceKey)) {
throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
}
if (ObjectHelper.isEmpty(destinationKey)) {
throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
}
CopyObjectRequest copyObjectRequest;
if (ObjectHelper.isEmpty(versionId)) {
copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
} else {
copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination, destinationKey);
}
CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);
Message message = getMessageForResponse(exchange);
message.setHeader(S3Constants.E_TAG, copyObjectResult.getETag());
if (copyObjectResult.getVersionId() != null) {
message.setHeader(S3Constants.VERSION_ID, copyObjectResult.getVersionId());
}
}
use of com.amazonaws.services.s3.AmazonS3 in project hadoop by apache.
the class ITestS3AConfiguration method testDefaultUserAgent.
@Test
public void testDefaultUserAgent() throws Exception {
conf = new Configuration();
fs = S3ATestUtils.createTestFileSystem(conf);
assertNotNull(fs);
AmazonS3 s3 = fs.getAmazonS3Client();
assertNotNull(s3);
ClientConfiguration awsConf = getField(s3, ClientConfiguration.class, "clientConfiguration");
assertEquals("Hadoop " + VersionInfo.getVersion(), awsConf.getUserAgentPrefix());
}
use of com.amazonaws.services.s3.AmazonS3 in project hadoop by apache.
the class ITestS3AConfiguration method testCustomUserAgent.
@Test
public void testCustomUserAgent() throws Exception {
conf = new Configuration();
conf.set(Constants.USER_AGENT_PREFIX, "MyApp");
fs = S3ATestUtils.createTestFileSystem(conf);
assertNotNull(fs);
AmazonS3 s3 = fs.getAmazonS3Client();
assertNotNull(s3);
ClientConfiguration awsConf = getField(s3, ClientConfiguration.class, "clientConfiguration");
assertEquals("MyApp, Hadoop " + VersionInfo.getVersion(), awsConf.getUserAgentPrefix());
}
use of com.amazonaws.services.s3.AmazonS3 in project hadoop by apache.
the class MockS3ClientFactory method createS3Client.
@Override
public AmazonS3 createS3Client(URI name, URI uri) {
String bucket = name.getHost();
AmazonS3 s3 = mock(AmazonS3.class);
when(s3.doesBucketExist(bucket)).thenReturn(true);
return s3;
}
Aggregations