camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [7/9] camel git commit: CAMEL-11736 - Camel-AWS: Use regional client instead of define region for single operation - AWS SNS
Date Fri, 01 Sep 2017 11:45:23 GMT
CAMEL-11736 - Camel-AWS: Use regional client instead of define region for single operation
- AWS SNS


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

Branch: refs/heads/master
Commit: fadf9805b11d2a967b75ec529eec48b5a6270fcf
Parents: eb21bd4
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Sep 1 12:55:00 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Sep 1 12:55:00 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/aws-sns-component.adoc        |  7 ++++---
 .../component/aws/sns/SnsConfiguration.java     | 19 +++++++++++++++---
 .../camel/component/aws/sns/SnsEndpoint.java    | 21 ++++++++++----------
 .../aws/sns/SnsComponentConfigurationTest.java  |  2 +-
 4 files changed, 32 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fadf9805/components/camel-aws/src/main/docs/aws-sns-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/docs/aws-sns-component.adoc b/components/camel-aws/src/main/docs/aws-sns-component.adoc
index 69a7a1d..ac3839b 100644
--- a/components/camel-aws/src/main/docs/aws-sns-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-sns-component.adoc
@@ -50,7 +50,7 @@ with the following path and query parameters:
 | **topicNameOrArn** | *Required* Topic name or ARN |  | String
 |=======================================================================
 
-#### Query Parameters (11 parameters):
+#### Query Parameters (12 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |=======================================================================
@@ -61,8 +61,9 @@ with the following path and query parameters:
 | **headerFilterStrategy** (producer) | To use a custom HeaderFilterStrategy to map headers
to/from Camel. |  | HeaderFilterStrategy
 | **messageStructure** (producer) | The message structure to use such as json |  | String
 | **policy** (producer) | The policy for this queue |  | String
-| **proxyHost** (producer) | To define a proxy host when instantiating the SQS client | 
| String
-| **proxyPort** (producer) | To define a proxy port when instantiating the SQS client | 
| Integer
+| **proxyHost** (producer) | To define a proxy host when instantiating the SNS client | 
| String
+| **proxyPort** (producer) | To define a proxy port when instantiating the SNS client | 
| Integer
+| **region** (producer) | The region in which SNS client needs to work |  | String
 | **secretKey** (producer) | Amazon AWS Secret Key |  | String
 | **subject** (producer) | The subject which is used if the message header 'CamelAwsSnsSubject'
is not present. |  | String
 | **synchronous** (advanced) | Sets whether synchronous processing should be strictly used
or Camel is allowed to use asynchronous processing (if supported). | false | boolean

http://git-wip-us.apache.org/repos/asf/camel/blob/fadf9805/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
index 06dd582..7edced8 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
@@ -47,7 +47,9 @@ public class SnsConfiguration implements Cloneable {
     private String policy;
     @UriParam
     private String messageStructure;
-
+    @UriParam
+    private String region;
+    
     /**
      * The region with which the AWS-SNS client wants to work with.
      */
@@ -148,7 +150,7 @@ public class SnsConfiguration implements Cloneable {
     }
     
     /**
-     * To define a proxy host when instantiating the SQS client
+     * To define a proxy host when instantiating the SNS client
      */
     public String getProxyHost() {
         return proxyHost;
@@ -159,7 +161,7 @@ public class SnsConfiguration implements Cloneable {
     }
 
     /**
-     * To define a proxy port when instantiating the SQS client
+     * To define a proxy port when instantiating the SNS client
      */
     public Integer getProxyPort() {
         return proxyPort;
@@ -168,6 +170,17 @@ public class SnsConfiguration implements Cloneable {
     public void setProxyPort(Integer proxyPort) {
         this.proxyPort = proxyPort;
     }
+    
+    /**
+     * The region in which SNS client needs to work
+     */
+    public String getRegion() {
+        return region;
+    }
+
+    public void setRegion(String region) {
+        this.region = region;
+    }
 
     @Override
     public String toString() {

http://git-wip-us.apache.org/repos/asf/camel/blob/fadf9805/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 39f39c8..22ad83c 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
@@ -22,6 +22,7 @@ import com.amazonaws.auth.AWSCredentials;
 import com.amazonaws.auth.AWSCredentialsProvider;
 import com.amazonaws.auth.AWSStaticCredentialsProvider;
 import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
 import com.amazonaws.services.sns.AmazonSNS;
 import com.amazonaws.services.sns.AmazonSNSClient;
 import com.amazonaws.services.sns.AmazonSNSClientBuilder;
@@ -104,12 +105,6 @@ public class SnsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
         super.doStart();
         snsClient = configuration.getAmazonSNSClient() != null
             ? configuration.getAmazonSNSClient() : createSNSClient();
-        
-        // Override the setting Endpoint from url
-        if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
-            LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
-            snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
-        }
 
         // check the setting the headerFilterStrategy
         if (headerFilterStrategy == null) {
@@ -182,6 +177,7 @@ public class SnsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
      */
     AmazonSNS createSNSClient() {
         AmazonSNS client = null;
+        AmazonSNSClientBuilder clientBuilder = null;
         ClientConfiguration clientConfiguration = null;
         boolean isClientConfigFound = false;
         if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort()))
{
@@ -194,17 +190,22 @@ public class SnsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
             AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
configuration.getSecretKey());
             AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
             if (isClientConfigFound) {
-                client = AmazonSNSClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider).build();
+                clientBuilder = AmazonSNSClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider);
             } else {
-                client = AmazonSNSClientBuilder.standard().withCredentials(credentialsProvider).build();
+                clientBuilder = AmazonSNSClientBuilder.standard().withCredentials(credentialsProvider);
             }
         } else {
             if (isClientConfigFound) {
-                client = AmazonSNSClientBuilder.standard().build();
+                clientBuilder = AmazonSNSClientBuilder.standard();
             } else {
-                client = AmazonSNSClientBuilder.standard().withClientConfiguration(clientConfiguration).build();
+                clientBuilder = AmazonSNSClientBuilder.standard().withClientConfiguration(clientConfiguration);
             }
         }
+        if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint()) && ObjectHelper.isNotEmpty(configuration.getRegion()))
{
+            EndpointConfiguration endpointConfiguration = new EndpointConfiguration(configuration.getAmazonSNSEndpoint(),
configuration.getRegion());
+            clientBuilder = clientBuilder.withEndpointConfiguration(endpointConfiguration);
+        }
+        client = clientBuilder.build();
         return client;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/fadf9805/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 65967da..8c1374b 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
@@ -87,7 +87,7 @@ public class SnsComponentConfigurationTest extends CamelTestSupport {
         
         assertEquals("arn:aws:sns:us-east-1:541925086079:MyTopic", endpoint.getConfiguration().getTopicArn());
         // check the setting of AmazonSNSEndpoint
-        assertEquals("sns.ap-southeast-2.amazonaws.com", mock.getEndpoint());
+        assertEquals("https://sns.us-east-1.amazonaws.com", mock.getEndpoint());
         
         endpoint.stop();
     }


Mime
View raw message