CAMEL-7286 fixed the same issue of other aws clients

Conflicts:
        
components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java

Conflicts:
        
components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/90d9611c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/90d9611c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/90d9611c

Branch: refs/heads/camel-2.11.x
Commit: 90d9611c9eec66ac9811dab3b0eabf5972190305
Parents: 92fa48c
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed Mar 12 15:46:44 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed Mar 12 16:21:43 2014 +0800

----------------------------------------------------------------------
 .../camel/component/aws/cw/CwEndpoint.java      | 15 ++++++------
 .../camel/component/aws/ddb/DdbEndpoint.java    | 17 ++++++++------
 .../camel/component/aws/s3/S3Endpoint.java      | 24 ++++++++++----------
 .../camel/component/aws/sdb/SdbEndpoint.java    | 14 +++++++-----
 .../camel/component/aws/ses/SesEndpoint.java    | 23 +++++++++++++------
 .../camel/component/aws/sqs/SqsEndpoint.java    |  9 +++++---
 6 files changed, 60 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/90d9611c/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/90d9611c/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/90d9611c/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 64f9315..242b20c 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;
 
@@ -79,12 +80,19 @@ public class S3Endpoint extends ScheduledPollEndpoint {
     @Override
     public void doStart() throws Exception {
         super.doStart();
+
+        s3Client = configuration.getAmazonS3Client() != null
+            ? configuration.getAmazonS3Client() : createS3Client();
         
+        if (ObjectHelper.isNotEmpty(configuration.getAmazonS3Endpoint())) {
+            s3Client.setEndpoint(configuration.getAmazonS3Endpoint());
+        }
+
         String bucketName = getConfiguration().getBucketName();
         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) {
@@ -104,14 +112,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");
         }
@@ -159,11 +167,6 @@ public class S3Endpoint extends ScheduledPollEndpoint {
     }
     
     public AmazonS3 getS3Client() {
-        if (s3Client == null) {
-            s3Client = configuration.getAmazonS3Client() != null
-                ? configuration.getAmazonS3Client() : createS3Client();
-        }
-        
         return s3Client;
     }
 
@@ -175,9 +178,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;
     }
 
@@ -188,4 +188,4 @@ public class S3Endpoint extends ScheduledPollEndpoint {
     public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
         this.maxMessagesPerPoll = maxMessagesPerPoll;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/90d9611c/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/90d9611c/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/90d9611c/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 40ee0b5..9c21722 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
@@ -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;
 
@@ -78,6 +79,11 @@ public class SqsEndpoint extends ScheduledPollEndpoint {
         client = getConfiguration().getAmazonSQSClient() != null
                 ? getConfiguration().getAmazonSQSClient() : getClient();
 
+         // Override the endpoint location
+        if 
(ObjectHelper.isNotEmpty(getConfiguration().getAmazonSQSEndpoint())) {
+            client.setEndpoint(getConfiguration().getAmazonSQSEndpoint());
+        }
+
         // check whether the queue already exists
         ListQueuesResult listQueuesResult = client.listQueues();
         for (String url : listQueuesResult.getQueueUrls()) {
@@ -196,9 +202,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;
     }
 

Reply via email to