You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/07/13 11:56:37 UTC

[camel] branch camel-2.22.x updated: CAMEL-12647 : Problem in setting region for camel AWS-SQS endpoint

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.22.x by this push:
     new a39c811  CAMEL-12647 : Problem in setting region for camel AWS-SQS endpoint
a39c811 is described below

commit a39c811a3a9f6abb951098f7e8d47d6f895796e0
Author: Saravanakumar Selvaraj <sa...@gmail.com>
AuthorDate: Fri Jul 13 16:23:13 2018 +0530

    CAMEL-12647 : Problem in setting region for camel AWS-SQS endpoint
---
 .../main/java/org/apache/camel/component/aws/sns/SnsComponent.java  | 6 ++++++
 .../main/java/org/apache/camel/component/aws/sqs/SqsComponent.java  | 3 ++-
 .../camel/component/aws/sns/SnsComponentConfigurationTest.java      | 4 ++--
 .../camel/component/aws/sqs/SqsComponentConfigurationTest.java      | 4 ++--
 4 files changed, 12 insertions(+), 5 deletions(-)

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 655f92e..89a0e92 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.sns;
 
 import java.util.Map;
 
+import com.amazonaws.regions.Regions;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
@@ -54,7 +55,12 @@ public class SnsComponent extends DefaultComponent {
             throw new IllegalArgumentException("Topic name must be specified.");
         }
         if (remaining.startsWith("arn:")) {
+            String[] parts = remaining.split(":");
+            if (parts.length != 6 || !parts[2].equals("sns")) {
+                throw new IllegalArgumentException("Topic arn must be in format arn:aws:sns:region:account:name.");
+            }
             configuration.setTopicArn(remaining);
+            configuration.setRegion(Regions.fromName(parts[3]).toString());
         } else {
             configuration.setTopicName(remaining);
         }
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 e21610b..e09f76c 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.sqs;
 
 import java.util.Map;
 
+import com.amazonaws.regions.Regions;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
@@ -60,7 +61,7 @@ public class SqsComponent extends DefaultComponent {
             if (parts.length != 6 || !parts[2].equals("sqs")) {
                 throw new IllegalArgumentException("Queue arn must be in format arn:aws:sqs:region:account:name.");
             }
-            configuration.setRegion(parts[3]);
+            configuration.setRegion(Regions.fromName(parts[3]).toString());
             configuration.setQueueOwnerAWSAccountId(parts[4]);
             configuration.setQueueName(parts[5]);
         } else {
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 329263f..0e56469 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
@@ -61,10 +61,10 @@ public class SnsComponentConfigurationTest extends CamelTestSupport {
         
         ((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?amazonSNSClient=#amazonSNSClient&accessKey=xxx&secretKey=yyy");
+        SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://arn:aws:sns:us-east-1:account:MyTopic?amazonSNSClient=#amazonSNSClient&accessKey=xxx&secretKey=yyy");
 
         assertNull(endpoint.getConfiguration().getTopicName());
-        assertEquals("arn:aws:sns:region:account:MyTopic", endpoint.getConfiguration().getTopicArn());
+        assertEquals("arn:aws:sns:us-east-1:account:MyTopic", endpoint.getConfiguration().getTopicArn());
     }
 
     @Test
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 240a48b..2699482 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
@@ -73,9 +73,9 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
         
         ((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?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy");
+        SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://arn:aws:sqs:us-east-1:account:MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy");
 
-        assertEquals("region", endpoint.getConfiguration().getRegion());
+        assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
         assertEquals("account", endpoint.getConfiguration().getQueueOwnerAWSAccountId());
         assertEquals("MyQueue", endpoint.getConfiguration().getQueueName());
         assertEquals("xxx", endpoint.getConfiguration().getAccessKey());