You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/03/12 08:53:24 UTC
[1/2] git commit: CAMEL-7286 fixed the same issue of other aws clients
Repository: camel
Updated Branches:
refs/heads/master 3ec500cb4 -> 7ad65f991
CAMEL-7286 fixed the same issue of other aws clients
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7ad65f99
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7ad65f99
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7ad65f99
Branch: refs/heads/master
Commit: 7ad65f9917c0a9f7a919b722c888dffb546e5c06
Parents: c614b28
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Mar 12 15:46:44 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Mar 12 15:48:41 2014 +0800
----------------------------------------------------------------------
.../camel/component/aws/cw/CwEndpoint.java | 15 +++++++------
.../camel/component/aws/ddb/DdbEndpoint.java | 17 +++++++++------
.../camel/component/aws/s3/S3Endpoint.java | 22 +++++++++----------
.../camel/component/aws/sdb/SdbEndpoint.java | 14 +++++++-----
.../camel/component/aws/ses/SesEndpoint.java | 23 ++++++++++++++------
.../camel/component/aws/sqs/SqsEndpoint.java | 9 +++++---
6 files changed, 59 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
index 72a54b3..43deaf9 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
@@ -27,6 +27,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
/**
* Defines the <a href="http://aws.amazon.com/cloudwatch/">AWS CloudWatch Endpoint</a>
@@ -62,6 +63,13 @@ public class CwEndpoint extends DefaultEndpoint {
@Override
public void doStart() throws Exception {
super.doStart();
+
+ cloudWatchClient = configuration.getAmazonCwClient() != null
+ ? configuration.getAmazonCwClient() : createCloudWatchClient();
+
+ if (ObjectHelper.isNotEmpty(configuration.getAmazonCwEndpoint())) {
+ cloudWatchClient.setEndpoint(configuration.getAmazonCwEndpoint());
+ }
}
public CwConfiguration getConfiguration() {
@@ -77,19 +85,12 @@ public class CwEndpoint extends DefaultEndpoint {
}
public AmazonCloudWatch getCloudWatchClient() {
- if (cloudWatchClient == null) {
- cloudWatchClient = configuration.getAmazonCwClient() != null
- ? configuration.getAmazonCwClient() : createCloudWatchClient();
- }
return cloudWatchClient;
}
AmazonCloudWatch createCloudWatchClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonCloudWatch client = new AmazonCloudWatchClient(credentials);
- if (configuration.getAmazonCwEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonCwEndpoint());
- }
return client;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/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 443cef5..6f7e9c7 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
@@ -36,6 +36,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +47,7 @@ public class DdbEndpoint extends ScheduledPollEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(DdbEndpoint.class);
private DdbConfiguration configuration;
+ private AmazonDynamoDB ddbClient;
@Deprecated
public DdbEndpoint(String uri, CamelContext context, DdbConfiguration configuration) {
@@ -74,7 +76,13 @@ public class DdbEndpoint extends ScheduledPollEndpoint {
public void doStart() throws Exception {
super.doStart();
- AmazonDynamoDB ddbClient = getDdbClient();
+ ddbClient = configuration.getAmazonDDBClient() != null ? configuration.getAmazonDDBClient()
+ : createDdbClient();
+
+ if (ObjectHelper.isNotEmpty(configuration.getAmazonDdbEndpoint())) {
+ ddbClient.setEndpoint(configuration.getAmazonDdbEndpoint());
+ }
+
String tableName = getConfiguration().getTableName();
LOG.trace("Querying whether table [{}] already exists...", tableName);
@@ -116,18 +124,13 @@ public class DdbEndpoint extends ScheduledPollEndpoint {
}
public AmazonDynamoDB getDdbClient() {
- return configuration.getAmazonDDBClient() != null ? configuration.getAmazonDDBClient()
- : createDdbClient();
+ return ddbClient;
}
AmazonDynamoDB createDdbClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
configuration.getSecretKey());
AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);
- if (configuration.getAmazonDdbEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonDdbEndpoint());
- }
- configuration.setAmazonDDBClient(client);
return client;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/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 15d37d1..f150bf2 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
@@ -36,6 +36,7 @@ import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,6 +81,13 @@ public class S3Endpoint extends ScheduledPollEndpoint {
public void doStart() throws Exception {
super.doStart();
+ s3Client = configuration.getAmazonS3Client() != null
+ ? configuration.getAmazonS3Client() : createS3Client();
+
+ if (ObjectHelper.isNotEmpty(configuration.getAmazonS3Endpoint())) {
+ s3Client.setEndpoint(configuration.getAmazonS3Endpoint());
+ }
+
String fileName = getConfiguration().getFileName();
if (fileName != null) {
@@ -91,7 +99,7 @@ public class S3Endpoint extends ScheduledPollEndpoint {
LOG.trace("Quering whether bucket [{}] already exists...", bucketName);
try {
- getS3Client().listObjects(new ListObjectsRequest(bucketName, null, null, null, 0));
+ s3Client.listObjects(new ListObjectsRequest(bucketName, null, null, null, 0));
LOG.trace("Bucket [{}] already exists", bucketName);
return;
} catch (AmazonServiceException ase) {
@@ -111,14 +119,14 @@ public class S3Endpoint extends ScheduledPollEndpoint {
LOG.trace("Creating bucket [{}] in region [{}] with request [{}]...", new Object[]{configuration.getBucketName(), configuration.getRegion(), createBucketRequest});
- getS3Client().createBucket(createBucketRequest);
+ s3Client.createBucket(createBucketRequest);
LOG.trace("Bucket created");
if (configuration.getPolicy() != null) {
LOG.trace("Updating bucket [{}] with policy [{}]", bucketName, configuration.getPolicy());
- getS3Client().setBucketPolicy(bucketName, configuration.getPolicy());
+ s3Client.setBucketPolicy(bucketName, configuration.getPolicy());
LOG.trace("Bucket policy updated");
}
@@ -166,11 +174,6 @@ public class S3Endpoint extends ScheduledPollEndpoint {
}
public AmazonS3 getS3Client() {
- if (s3Client == null) {
- s3Client = configuration.getAmazonS3Client() != null
- ? configuration.getAmazonS3Client() : createS3Client();
- }
-
return s3Client;
}
@@ -182,9 +185,6 @@ public class S3Endpoint extends ScheduledPollEndpoint {
AmazonS3 createS3Client() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonS3 client = new AmazonS3Client(credentials);
- if (configuration.getAmazonS3Endpoint() != null) {
- client.setEndpoint(configuration.getAmazonS3Endpoint());
- }
return client;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/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 f46f89c..0a781a6 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
@@ -30,6 +30,7 @@ import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.component.aws.s3.S3Endpoint;
import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,6 +42,7 @@ public class SdbEndpoint extends ScheduledPollEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(S3Endpoint.class);
private SdbConfiguration configuration;
+ private AmazonSimpleDB sdbClient;
@Deprecated
public SdbEndpoint(String uri, CamelContext context, SdbConfiguration configuration) {
@@ -68,7 +70,11 @@ public class SdbEndpoint extends ScheduledPollEndpoint {
public void doStart() throws Exception {
super.doStart();
- AmazonSimpleDB sdbClient = getSdbClient();
+ sdbClient = configuration.getAmazonSDBClient() != null ? configuration.getAmazonSDBClient() : createSdbClient();
+ if (ObjectHelper.isNotEmpty(configuration.getAmazonSdbEndpoint())) {
+ sdbClient.setEndpoint(configuration.getAmazonSdbEndpoint());
+ }
+
String domainName = getConfiguration().getDomainName();
LOG.trace("Querying whether domain [{}] already exists...", domainName);
@@ -89,16 +95,12 @@ public class SdbEndpoint extends ScheduledPollEndpoint {
}
public AmazonSimpleDB getSdbClient() {
- return configuration.getAmazonSDBClient() != null ? configuration.getAmazonSDBClient() : createSdbClient();
+ return sdbClient;
}
AmazonSimpleDB createSdbClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonSimpleDB client = new AmazonSimpleDBClient(credentials);
- if (configuration.getAmazonSdbEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonSdbEndpoint());
- }
- configuration.setAmazonSDBClient(client);
return client;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/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 750b715..0cd952b 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
@@ -26,6 +26,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
/**
* Defines the <a href="http://camel.apache.org/aws.html">AWS SES Endpoint</a>.
@@ -34,6 +35,8 @@ import org.apache.camel.impl.DefaultEndpoint;
public class SesEndpoint extends DefaultEndpoint {
private SesConfiguration configuration;
+
+ private AmazonSimpleEmailService sesClient;
@Deprecated
public SesEndpoint(String uri, CamelContext context, SesConfiguration configuration) {
@@ -44,6 +47,18 @@ public class SesEndpoint extends DefaultEndpoint {
super(uri, component);
this.configuration = configuration;
}
+
+ @Override
+ public void doStart() throws Exception {
+ super.doStart();
+ sesClient = configuration.getAmazonSESClient() != null
+ ? configuration.getAmazonSESClient()
+ : createSESClient();
+
+ if (ObjectHelper.isNotEmpty(configuration.getAmazonSESEndpoint())) {
+ sesClient.setEndpoint(configuration.getAmazonSESEndpoint());
+ }
+ }
public Consumer createConsumer(Processor processor) throws Exception {
throw new UnsupportedOperationException("You cannot receive messages from this endpoint");
@@ -62,18 +77,12 @@ public class SesEndpoint extends DefaultEndpoint {
}
public AmazonSimpleEmailService getSESClient() {
- return configuration.getAmazonSESClient() != null
- ? configuration.getAmazonSESClient()
- : createSESClient();
+ return sesClient;
}
private AmazonSimpleEmailService createSESClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonSimpleEmailService client = new AmazonSimpleEmailServiceClient(credentials);
- if (configuration.getAmazonSESEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonSESEndpoint());
- }
- configuration.setAmazonSESClient(client);
return client;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7ad65f99/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 aa01c72..caf3c56 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
@@ -38,6 +38,7 @@ import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,6 +80,11 @@ public class SqsEndpoint extends ScheduledPollEndpoint {
protected void doStart() throws Exception {
client = getConfiguration().getAmazonSQSClient() != null
? getConfiguration().getAmazonSQSClient() : getClient();
+
+ // Override the endpoint location
+ if (ObjectHelper.isNotEmpty(getConfiguration().getAmazonSQSEndpoint())) {
+ client.setEndpoint(getConfiguration().getAmazonSQSEndpoint());
+ }
// If both region and Account ID is provided the queue URL can be built manually.
// This allows accessing queues where you don't have permission to list queues or query queues
@@ -211,9 +217,6 @@ public class SqsEndpoint extends ScheduledPollEndpoint {
AmazonSQS createClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonSQS client = new AmazonSQSClient(credentials);
- if (configuration.getAmazonSQSEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonSQSEndpoint());
- }
return client;
}
[2/2] git commit: CAMEL-7286 polish the code of SnsEndpoint
Posted by ni...@apache.org.
CAMEL-7286 polish the code of SnsEndpoint
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c614b28e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c614b28e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c614b28e
Branch: refs/heads/master
Commit: c614b28e9d254cfdc3ffd2490812a90563c54d9d
Parents: 3ec500c
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Mar 12 15:46:15 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Mar 12 15:48:41 2014 +0800
----------------------------------------------------------------------
.../camel/component/aws/sns/SnsEndpoint.java | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c614b28e/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 63c5046..031d112 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
@@ -70,13 +70,14 @@ public class SnsEndpoint extends DefaultEndpoint {
@Override
public void doStart() throws Exception {
super.doStart();
-
+ snsClient = configuration.getAmazonSNSClient() != null
+ ? configuration.getAmazonSNSClient() : createSNSClient();
// creates a new topic, or returns the URL of an existing one
CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);
- CreateTopicResult result = getSNSClient().createTopic(request);
+ CreateTopicResult result = snsClient.createTopic(request);
configuration.setTopicArn(result.getTopicArn());
LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
@@ -84,14 +85,14 @@ public class SnsEndpoint extends DefaultEndpoint {
if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(), configuration.getPolicy());
- getSNSClient().setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));
+ snsClient.setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));
LOG.trace("Topic policy updated");
}
-
+ // Override the setting Endpoint from url
if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
- getSNSClient().setEndpoint(configuration.getAmazonSNSEndpoint());
+ snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
}
}
@@ -108,11 +109,6 @@ public class SnsEndpoint extends DefaultEndpoint {
}
public AmazonSNS getSNSClient() {
- if (snsClient == null) {
- snsClient = configuration.getAmazonSNSClient() != null
- ? configuration.getAmazonSNSClient() : createSNSClient();
- }
-
return snsClient;
}
@@ -124,9 +120,6 @@ public class SnsEndpoint extends DefaultEndpoint {
AmazonSNS createSNSClient() {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
AmazonSNS client = new AmazonSNSClient(credentials);
- if (configuration.getAmazonSNSEndpoint() != null) {
- client.setEndpoint(configuration.getAmazonSNSEndpoint());
- }
return client;
}
}
\ No newline at end of file