Repository: camel Updated Branches: refs/heads/master f05f319a2 -> 9e0e52a5d
CAMEL-9210 - accessKey and secretKey options are optional accessKey and secretKey options are optional now Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9e0e52a5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9e0e52a5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9e0e52a5 Branch: refs/heads/master Commit: 9e0e52a5d830d09f4856bd6dc5f78bfc4f841026 Parents: 17c5040 Author: onders86 <ondersezgin+git...@gmail.com> Authored: Sat Jan 21 02:18:12 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat Jan 21 09:02:15 2017 +0100 ---------------------------------------------------------------------- .../camel/component/aws/ddb/DdbComponent.java | 4 +- .../camel/component/aws/ddb/DdbEndpoint.java | 21 ++++++-- .../camel/component/aws/ec2/EC2Component.java | 4 +- .../camel/component/aws/ec2/EC2Endpoint.java | 21 ++++++-- .../camel/component/aws/s3/S3Component.java | 4 +- .../camel/component/aws/s3/S3Endpoint.java | 32 +++++++++--- .../camel/component/aws/sdb/SdbComponent.java | 4 +- .../camel/component/aws/sdb/SdbEndpoint.java | 21 ++++++-- .../camel/component/aws/ses/SesComponent.java | 4 +- .../camel/component/aws/ses/SesEndpoint.java | 21 ++++++-- .../camel/component/aws/sns/SnsComponent.java | 4 +- .../camel/component/aws/sns/SnsEndpoint.java | 21 ++++++-- .../camel/component/aws/sqs/SqsComponent.java | 4 +- .../camel/component/aws/sqs/SqsEndpoint.java | 21 ++++++-- .../component/aws/ddb/DdbComponentTest.java | 12 +++++ .../aws/ec2/EC2ComponentConfigurationTest.java | 25 +++++++-- .../aws/s3/S3ComponentConfigurationTest.java | 36 ++++++++++--- .../aws/sdb/SdbComponentConfigurationTest.java | 28 ++++++++-- .../aws/ses/SesComponentConfigurationTest.java | 29 +++++++++-- .../aws/sns/SnsComponentConfigurationTest.java | 31 +++++++++-- .../aws/sqs/SqsComponentConfigurationTest.java | 54 ++++++++++++++++---- 21 files changed, 322 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java index 156ff4d..60707ba 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java @@ -41,8 +41,8 @@ public class DdbComponent extends UriEndpointComponent { } configuration.setTableName(remaining); - if (configuration.getAmazonDDBClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("amazonDDBClient or accessKey and secretKey must be specified"); + if (configuration.getAmazonDDBClient() == null) { + throw new IllegalArgumentException("amazonDDBClient must be specified"); } DdbEndpoint endpoint = new DdbEndpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java index d6d3066..d9b979c 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java @@ -135,14 +135,27 @@ public class DdbEndpoint extends ScheduledPollEndpoint { AmazonDynamoDB createDdbClient() { AmazonDynamoDB client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonDynamoDBClient(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonDynamoDBClient(credentials, clientConfiguration); + } else { + client = new AmazonDynamoDBClient(credentials); + } } else { - client = new AmazonDynamoDBClient(credentials); + if (isClientConfigFound) { + client = new AmazonDynamoDBClient(); + } else { + client = new AmazonDynamoDBClient(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java index 1dc8c4c..545a297 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java @@ -40,8 +40,8 @@ public class EC2Component extends UriEndpointComponent { EC2Configuration configuration = new EC2Configuration(); setProperties(configuration, parameters); - if (configuration.getAmazonEc2Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("amazonEC2Client or accessKey and secretKey must be specified"); + if (configuration.getAmazonEc2Client() == null) { + throw new IllegalArgumentException("amazonEC2Client must be specified"); } EC2Endpoint endpoint = new EC2Endpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Endpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Endpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Endpoint.java index c710f26..83e707f 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Endpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Endpoint.java @@ -78,14 +78,27 @@ public class EC2Endpoint extends ScheduledPollEndpoint { AmazonEC2Client createEc2Client() { AmazonEC2Client client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonEC2Client(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonEC2Client(credentials, clientConfiguration); + } else { + client = new AmazonEC2Client(credentials); + } } else { - client = new AmazonEC2Client(credentials); + if (isClientConfigFound) { + client = new AmazonEC2Client(); + } else { + client = new AmazonEC2Client(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java index a481267..8bdd994 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java @@ -44,8 +44,8 @@ public class S3Component extends UriEndpointComponent { } configuration.setBucketName(remaining); - if (configuration.getAmazonS3Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("AmazonS3Client or accessKey and secretKey must be specified"); + if (configuration.getAmazonS3Client() == null) { + throw new IllegalArgumentException("AmazonS3Client must be specified"); } S3Endpoint endpoint = new S3Endpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java index f39463d..843e7ff 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java @@ -231,8 +231,30 @@ public class S3Endpoint extends ScheduledPollEndpoint { * Provide the possibility to override this method for an mock implementation */ AmazonS3 createS3Client() { - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); - AmazonS3Client client = configuration.hasProxyConfiguration() ? createClientWithProxy(credentials) : new AmazonS3Client(credentials); + + 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()) @@ -241,12 +263,6 @@ public class S3Endpoint extends ScheduledPollEndpoint { return client; } - private AmazonS3Client createClientWithProxy(final AWSCredentials credentials) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); - clientConfiguration.setProxyHost(configuration.getProxyHost()); - clientConfiguration.setProxyPort(configuration.getProxyPort()); - return new AmazonS3Client(credentials, clientConfiguration); - } public int getMaxMessagesPerPoll() { return maxMessagesPerPoll; http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java index 18c44d3..989d35b 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java @@ -41,8 +41,8 @@ public class SdbComponent extends UriEndpointComponent { } configuration.setDomainName(remaining); - if (configuration.getAmazonSDBClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("amazonSDBClient or accessKey and secretKey must be specified"); + if (configuration.getAmazonSDBClient() == null) { + throw new IllegalArgumentException("amazonSDBClient must be specified"); } SdbEndpoint endpoint = new SdbEndpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java index f72d1c3..46a6d55 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java @@ -107,14 +107,27 @@ public class SdbEndpoint extends ScheduledPollEndpoint { AmazonSimpleDB createSdbClient() { AmazonSimpleDB client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonSimpleDBClient(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonSimpleDBClient(credentials, clientConfiguration); + } else { + client = new AmazonSimpleDBClient(credentials); + } } else { - client = new AmazonSimpleDBClient(credentials); + if (isClientConfigFound) { + client = new AmazonSimpleDBClient(); + } else { + client = new AmazonSimpleDBClient(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java index d330533..ba67145 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java @@ -41,8 +41,8 @@ public class SesComponent extends UriEndpointComponent { } configuration.setFrom(remaining); - if (configuration.getAmazonSESClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("AmazonSESClient or accessKey and secretKey must be specified"); + if (configuration.getAmazonSESClient() == null) { + throw new IllegalArgumentException("AmazonSESClient must be specified"); } return new SesEndpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesEndpoint.java index 577e19d..a00cead 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesEndpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesEndpoint.java @@ -87,14 +87,27 @@ public class SesEndpoint extends DefaultEndpoint { private AmazonSimpleEmailService createSESClient() { AmazonSimpleEmailService client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonSimpleEmailServiceClient(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonSimpleEmailServiceClient(credentials, clientConfiguration); + } else { + client = new AmazonSimpleEmailServiceClient(credentials); + } } else { - client = new AmazonSimpleEmailServiceClient(credentials); + if (isClientConfigFound) { + client = new AmazonSimpleEmailServiceClient(); + } else { + client = new AmazonSimpleEmailServiceClient(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java index da6b311..1c270d4 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java @@ -45,8 +45,8 @@ public class SnsComponent extends UriEndpointComponent { configuration.setTopicName(remaining); } - if (configuration.getAmazonSNSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("AmazonSNSClient or accessKey and secretKey must be specified"); + if (configuration.getAmazonSNSClient() == null) { + throw new IllegalArgumentException("AmazonSNSClient must be specified"); } SnsEndpoint endpoint = new SnsEndpoint(uri, this, configuration); http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java index af894d2..ee43639 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java @@ -158,14 +158,27 @@ public class SnsEndpoint extends DefaultEndpoint { */ AmazonSNS createSNSClient() { AmazonSNS client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonSNSClient(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonSNSClient(credentials, clientConfiguration); + } else { + client = new AmazonSNSClient(credentials); + } } else { - client = new AmazonSNSClient(credentials); + if (isClientConfigFound) { + client = new AmazonSNSClient(); + } else { + client = new AmazonSNSClient(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java index f865670..4028d82 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java @@ -53,8 +53,8 @@ public class SqsComponent extends UriEndpointComponent { configuration.setQueueName(remaining); } - if (configuration.getAmazonSQSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { - throw new IllegalArgumentException("AmazonSQSClient or accessKey and secretKey must be specified."); + if (configuration.getAmazonSQSClient() == null) { + throw new IllegalArgumentException("AmazonSQSClient must be specified."); } // Verify that visibilityTimeout is set if extendMessageVisibility is set to true. http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java index f777444..4b5e9c3 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java @@ -269,14 +269,27 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt */ AmazonSQS createClient() { AmazonSQS client = null; - AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + ClientConfiguration clientConfiguration = null; + boolean isClientConfigFound = false; if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { - ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); - client = new AmazonSQSClient(credentials, clientConfiguration); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + client = new AmazonSQSClient(credentials, clientConfiguration); + } else { + client = new AmazonSQSClient(credentials); + } } else { - client = new AmazonSQSClient(credentials); + if (isClientConfigFound) { + client = new AmazonSQSClient(); + } else { + client = new AmazonSQSClient(clientConfiguration); + } } return client; } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java index ddfcadb..ad03469 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentTest.java @@ -38,6 +38,18 @@ public class DdbComponentTest extends CamelTestSupport { "aws-ddb://creatibleTable?amazonDDBClient=#amazonDDBClient"); assertEquals("creatibleTable", amazonDDBClient.createTableRequest.getTableName()); } + + @Test(expected = IllegalArgumentException.class) + public void createEndpointWithOnlySecretKeyConfiguration() throws Exception { + DdbComponent component = new DdbComponent(context); + component.createEndpoint("aws-ddb://activeTable?secretKey=xxx"); + } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + DdbComponent component = new DdbComponent(context); + component.createEndpoint("aws-ddb://activeTable?amazonDDBClient=#amazonDDBClient"); + } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java index a7c441c..2dd3437 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurationTest.java @@ -16,20 +16,26 @@ */ package org.apache.camel.component.aws.ec2; +import com.amazonaws.services.ec2.AmazonEC2Client; +import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; +import static org.mockito.Mockito.*; + + + public class EC2ComponentConfigurationTest extends CamelTestSupport { - + AmazonEC2Client amazonEc2Client = mock(AmazonEC2Client.class); @Test public void createEndpointWithMinimalConfiguration() throws Exception { EC2Component component = new EC2Component(context); EC2Endpoint endpoint = (EC2Endpoint) component.createEndpoint( - "aws-ec2://TestDomain?accessKey=xxx&secretKey=yyy"); + "aws-ec2://TestDomain?amazonEc2Client=#amazonEc2Client&accessKey=xxx&secretKey=yyy"); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonEc2Client()); + assertNotNull(endpoint.getConfiguration().getAmazonEc2Client()); } @Test(expected = IllegalArgumentException.class) @@ -55,4 +61,17 @@ public class EC2ComponentConfigurationTest extends CamelTestSupport { EC2Component component = new EC2Component(context); component.createEndpoint("aws-ec2://TestDomain?accessKey=xxx"); } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + EC2Component component = new EC2Component(context); + component.createEndpoint("aws-ec2://TestDomain?amazonEc2Client=#amazonEc2Client"); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + registry.bind("amazonEc2Client", amazonEc2Client); + return registry; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java index ec4afd3..40185b5 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java @@ -25,13 +25,17 @@ public class S3ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfiguration() throws Exception { + AmazonS3ClientMock mock = new AmazonS3ClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonS3Client", mock); + S3Component component = new S3Component(context); - S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://MyBucket?accessKey=xxx&secretKey=yyy"); + S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://MyBucket?amazonS3Client=#amazonS3Client&accessKey=xxx&secretKey=yyy"); assertEquals("MyBucket", endpoint.getConfiguration().getBucketName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonS3Client()); + assertNotNull(endpoint.getConfiguration().getAmazonS3Client()); assertNull(endpoint.getConfiguration().getRegion()); assertTrue(endpoint.getConfiguration().isDeleteAfterRead()); assertEquals(10, endpoint.getMaxMessagesPerPoll()); @@ -43,8 +47,12 @@ public class S3ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalArnConfiguration() throws Exception { + AmazonS3ClientMock mock = new AmazonS3ClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonS3Client", mock); + S3Component component = new S3Component(context); - S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://arn:aws:s3:::MyBucket?accessKey=xxx&secretKey=yyy"); + S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://arn:aws:s3:::MyBucket?amazonS3Client=#amazonS3Client&accessKey=xxx&secretKey=yyy"); assertEquals("MyBucket", endpoint.getConfiguration().getBucketName()); } @@ -73,8 +81,12 @@ public class S3ComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { + AmazonS3ClientMock mock = new AmazonS3ClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonS3Client", mock); + S3Component component = new S3Component(context); - S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://MyBucket?amazonS3Endpoint=sns.eu-west-1.amazonaws.com" + S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://MyBucket?amazonS3Client=#amazonS3Client&amazonS3Endpoint=sns.eu-west-1.amazonaws.com" + "&accessKey=xxx&secretKey=yyy®ion=us-west-1&deleteAfterRead=false&maxMessagesPerPoll=1&policy=%7B%22Version%22%3A%222008-10-17%22,%22Id%22%3A%22Policy4324355464%22," + "%22Statement%22%3A%5B%7B%22Sid%22%3A%22Stmt456464646477%22,%22Action%22%3A%5B%22s3%3AGetObject%22%5D,%22Effect%22%3A%22Allow%22," + "%22Resource%22%3A%5B%22arn%3Aaws%3As3%3A%3A%3Amybucket/some/path/*%22%5D,%22Principal%22%3A%7B%22AWS%22%3A%5B%22*%22%5D%7D%7D%5D%7D&storageClass=REDUCED_REDUNDANCY" @@ -83,7 +95,7 @@ public class S3ComponentConfigurationTest extends CamelTestSupport { assertEquals("MyBucket", endpoint.getConfiguration().getBucketName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonS3Client()); + assertNotNull(endpoint.getConfiguration().getAmazonS3Client()); assertEquals("us-west-1", endpoint.getConfiguration().getRegion()); assertFalse(endpoint.getConfiguration().isDeleteAfterRead()); assertEquals(1, endpoint.getMaxMessagesPerPoll()); @@ -104,12 +116,22 @@ public class S3ComponentConfigurationTest extends CamelTestSupport { @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAccessKeyConfiguration() throws Exception { S3Component component = new S3Component(context); - component.createEndpoint("aws-sns://MyTopic?secretKey=yyy"); + component.createEndpoint("aws-s3://MyTopic?secretKey=yyy"); } @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutSecretKeyConfiguration() throws Exception { S3Component component = new S3Component(context); - component.createEndpoint("aws-sns://MyTopic?accessKey=xxx"); + component.createEndpoint("aws-s3://MyTopic?accessKey=xxx"); + } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + AmazonS3ClientMock mock = new AmazonS3ClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonS3Client", mock); + + S3Component component = new S3Component(context); + component.createEndpoint("aws-s3://MyTopic?amazonS3Client=#amazonS3Client"); } } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentConfigurationTest.java index e666d68..8d4aa2b 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentConfigurationTest.java @@ -25,14 +25,19 @@ public class SdbComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfiguration() throws Exception { + AmazonSDBClientMock mock = new AmazonSDBClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSDBClient", mock); + SdbComponent component = new SdbComponent(context); SdbEndpoint endpoint = (SdbEndpoint) component.createEndpoint( - "aws-sdb://TestDomain?accessKey=xxx&secretKey=yyy"); + "aws-sdb://TestDomain?amazonSDBClient=#amazonSDBClient&accessKey=xxx&secretKey=yyy"); assertEquals("TestDomain", endpoint.getConfiguration().getDomainName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSDBClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSDBClient()); assertEquals(SdbOperations.PutAttributes, endpoint.getConfiguration().getOperation()); assertNull(endpoint.getConfiguration().getAmazonSdbEndpoint()); assertFalse(endpoint.getConfiguration().isConsistentRead()); @@ -62,15 +67,19 @@ public class SdbComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { + AmazonSDBClientMock mock = new AmazonSDBClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSDBClient", mock); SdbComponent component = new SdbComponent(context); SdbEndpoint endpoint = (SdbEndpoint) component.createEndpoint( - "aws-sdb://TestDomain?accessKey=xxx&secretKey=yyy&operation=DeleteAttributes&consistentRead=true" + "aws-sdb://TestDomain?amazonSDBClient=#amazonSDBClient&accessKey=xxx&secretKey=yyy&operation=DeleteAttributes&consistentRead=true" + "&maxNumberOfDomains=5"); assertEquals("TestDomain", endpoint.getConfiguration().getDomainName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSDBClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSDBClient()); assertEquals(SdbOperations.DeleteAttributes, endpoint.getConfiguration().getOperation()); assertNull(endpoint.getConfiguration().getAmazonSdbEndpoint()); assertTrue(endpoint.getConfiguration().isConsistentRead()); @@ -100,4 +109,15 @@ public class SdbComponentConfigurationTest extends CamelTestSupport { SdbComponent component = new SdbComponent(context); component.createEndpoint("aws-sdb://TestDomain?accessKey=xxx"); } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + AmazonSDBClientMock mock = new AmazonSDBClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSDBClient", mock); + + SdbComponent component = new SdbComponent(context); + component.createEndpoint("aws-sdb://TestDomain?amazonSDBClient=#amazonSDBClient"); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java index db16f03..1f86a50 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentConfigurationTest.java @@ -25,14 +25,19 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfiguration() throws Exception { + AmazonSESClientMock mock = new AmazonSESClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSESClient", mock); + SesComponent component = new SesComponent(context); - SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?accessKey=xxx&secretKey=yyy"); + SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx&secretKey=yyy"); assertEquals("f...@example.com", endpoint.getConfiguration().getFrom()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); assertNull(endpoint.getConfiguration().getAmazonSESEndpoint()); - assertNull(endpoint.getConfiguration().getAmazonSESClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSESClient()); assertNull(endpoint.getConfiguration().getTo()); assertNull(endpoint.getConfiguration().getSubject()); assertNull(endpoint.getConfiguration().getReturnPath()); @@ -63,8 +68,13 @@ public class SesComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { + AmazonSESClientMock mock = new AmazonSESClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSESClient", mock); + SesComponent component = new SesComponent(context); - SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?accessKey=xxx" + SesEndpoint endpoint = (SesEndpoint) component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient&accessKey=xxx" + "&secretKey=yyy&to=t...@example.com,t...@example.com&amazonSESEndpoint=us-east-1&subject=Subject" + "&returnPath=bou...@example.com&replyToAddresses=reply...@example.com,reply...@example.com"); @@ -72,7 +82,7 @@ public class SesComponentConfigurationTest extends CamelTestSupport { assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); assertEquals("us-east-1", endpoint.getConfiguration().getAmazonSESEndpoint()); - assertNull(endpoint.getConfiguration().getAmazonSESClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSESClient()); assertEquals(2, endpoint.getConfiguration().getTo().size()); assertTrue(endpoint.getConfiguration().getTo().contains("t...@example.com")); assertTrue(endpoint.getConfiguration().getTo().contains("t...@example.com")); @@ -106,4 +116,15 @@ public class SesComponentConfigurationTest extends CamelTestSupport { SesComponent component = new SesComponent(context); component.createEndpoint("aws-ses://f...@example.com?accessKey=xxx"); } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + AmazonSESClientMock mock = new AmazonSESClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()) + .bind("amazonSESClient", mock); + + SesComponent component = new SesComponent(context); + component.createEndpoint("aws-ses://f...@example.com?amazonSESClient=#amazonSESClient"); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java index f1b2e46..3f8a3bc 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java @@ -25,13 +25,16 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfiguration() throws Exception { + AmazonSNSClientMock mock = new AmazonSNSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSNSClient", mock); SnsComponent component = new SnsComponent(context); - SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://MyTopic?accessKey=xxx&secretKey=yyy"); + SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://MyTopic?amazonSNSClient=#amazonSNSClient&accessKey=xxx&secretKey=yyy"); assertEquals("MyTopic", endpoint.getConfiguration().getTopicName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSNSClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSNSClient()); assertNull(endpoint.getConfiguration().getTopicArn()); assertNull(endpoint.getConfiguration().getSubject()); assertNull(endpoint.getConfiguration().getAmazonSNSEndpoint()); @@ -39,8 +42,11 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { } public void createEndpointWithMinimalArnConfiguration() throws Exception { + AmazonSNSClientMock mock = new AmazonSNSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSNSClient", mock); SnsComponent component = new SnsComponent(context); - SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://arn:aws:sns:region:account:MyTopic?accessKey=xxx&secretKey=yyy"); + SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://arn:aws:sns:region:account:MyTopic?amazonSNSClient=#amazonSNSClient&accessKey=xxx&secretKey=yyy"); assertNull(endpoint.getConfiguration().getTopicName()); assertEquals("arn:aws:sns:region:account:MyTopic", endpoint.getConfiguration().getTopicArn()); @@ -73,8 +79,13 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { + + AmazonSNSClientMock mock = new AmazonSNSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSNSClient", mock); + SnsComponent component = new SnsComponent(context); - SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://MyTopic?amazonSNSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx&secretKey=yyy" + SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://MyTopic?amazonSNSClient=#amazonSNSClient&amazonSNSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx&secretKey=yyy" + "&policy=%7B%22Version%22%3A%222008-10-17%22,%22Statement%22%3A%5B%7B%22Sid%22%3A%221%22,%22Effect%22%3A%22Allow%22,%22Principal%22%3A%7B%22AWS%22%3A%5B%22*%22%5D%7D," + "%22Action%22%3A%5B%22sns%3ASubscribe%22%5D%7D%5D%7D&subject=The+subject+message"); @@ -83,7 +94,7 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); assertNull(endpoint.getConfiguration().getTopicArn()); - assertNull(endpoint.getConfiguration().getAmazonSNSClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSNSClient()); assertEquals("The subject message", endpoint.getConfiguration().getSubject()); assertEquals( "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"1\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"sns:Subscribe\"]}]}", @@ -101,4 +112,14 @@ public class SnsComponentConfigurationTest extends CamelTestSupport { SnsComponent component = new SnsComponent(context); component.createEndpoint("aws-sns://MyTopic?accessKey=xxx"); } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + AmazonSNSClientMock mock = new AmazonSNSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSNSClient", mock); + + SnsComponent component = new SnsComponent(context); + component.createEndpoint("aws-sns://MyTopic?amazonSNSClient=#amazonSNSClient"); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/9e0e52a5/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java index cfc21d0..5bd717c 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java @@ -25,13 +25,16 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfiguration() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy"); + SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSQSClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSQSClient()); assertNull(endpoint.getConfiguration().getAttributeNames()); assertNull(endpoint.getConfiguration().getMessageAttributeNames()); assertNull(endpoint.getConfiguration().getDefaultVisibilityTimeout()); @@ -46,8 +49,11 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalArnConfiguration() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://arn:aws:sqs:region:account:MyQueue?accessKey=xxx&secretKey=yyy"); + SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://arn:aws:sqs:region:account:MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); assertEquals("region", endpoint.getConfiguration().getRegion()); assertEquals("account", endpoint.getConfiguration().getQueueOwnerAWSAccountId()); @@ -57,13 +63,16 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointAttributeNames() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&attributeNames=foo,bar"); + SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&attributeNames=foo,bar"); assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSQSClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSQSClient()); assertEquals("foo,bar", endpoint.getConfiguration().getAttributeNames()); } @@ -94,8 +103,13 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMaximalConfiguration() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx&secretKey=yyy&attributeNames=color,size" + + SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&amazonSQSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx" + + "&secretKey=yyy&attributeNames=color,size" + "&messageAttributeNames=msgColor,msgSize&DefaultVisibilityTimeout=1000&visibilityTimeout=2000&maximumMessageSize=65536&messageRetentionPeriod=1209600&policy=" + "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyQueue%2FSQSDefaultPolicy%22%2C%22Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22" + "Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyQueue%22%7D%5D%7D" @@ -106,7 +120,7 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); - assertNull(endpoint.getConfiguration().getAmazonSQSClient()); + assertNotNull(endpoint.getConfiguration().getAmazonSQSClient()); assertEquals("color,size", endpoint.getConfiguration().getAttributeNames()); assertEquals("msgColor,msgSize", endpoint.getConfiguration().getMessageAttributeNames()); assertEquals(new Integer(1000), endpoint.getConfiguration().getDefaultVisibilityTimeout()); @@ -127,8 +141,12 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithPollConsumerConfiguration() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&initialDelay=300&delay=400&maxMessagesPerPoll=50"); + SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" + + "&accessKey=xxx&secretKey=yyy&initialDelay=300&delay=400&maxMessagesPerPoll=50"); SqsConsumer consumer = (SqsConsumer) endpoint.createConsumer(null); assertEquals(300, consumer.getInitialDelay()); @@ -157,13 +175,29 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithExtendMessageVisibilityTrueAndVisibilityTimeoutSet() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - assertNotNull(component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=true")); + assertNotNull(component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=true")); } @Test public void createEndpointWithExtendMessageVisibilityFalseAndVisibilityTimeoutSet() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); + SqsComponent component = new SqsComponent(context); + assertNotNull(component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=false")); + } + + @Test + public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { + AmazonSQSClientMock mock = new AmazonSQSClientMock(); + + ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("amazonSQSClient", mock); + SqsComponent component = new SqsComponent(context); - assertNotNull(component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=false")); + component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"); } }