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

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


The following commit(s) were added to refs/heads/camel-3.4.x by this push:
     new a943fa0  CAMEL-15391: override the endpoint if a custom AWS Host is 
provided (#4084)
a943fa0 is described below

commit a943fa05752acb9770ecad9ff603621757dcebe9
Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com>
AuthorDate: Tue Aug 11 16:21:36 2020 +0200

    CAMEL-15391: override the endpoint if a custom AWS Host is provided (#4084)
---
 .../camel/component/aws2/sqs/Sqs2Endpoint.java     | 26 ++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java
 
b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java
index 773dea6..1c343c1 100644
--- 
a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java
+++ 
b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java
@@ -115,6 +115,10 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint 
implements HeaderFilterS
         return sqsConsumer;
     }
 
+    private boolean isDefaultAwsHost() {
+        return configuration.getAmazonAWSHost().equals("amazonaws.com");
+    }
+
     /*
      * If using a different AWS host, do not assume specific parts of the AWS
      * host and, instead, just return whatever is provided as the host.
@@ -123,13 +127,24 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint 
implements HeaderFilterS
         String host = configuration.getAmazonAWSHost();
         host = FileUtil.stripTrailingSeparator(host);
 
-        if (host.equals("amazonaws.com")) {
+        if (isDefaultAwsHost()) {
             return "sqs." + Region.of(configuration.getRegion()).id() + "." + 
host;
         }
 
         return host;
     }
 
+    /*
+     * Gets the base endpoint for AWS (ie.: http(s)://host:port.
+     *
+     * Do not confuse with other Camel endpoint methods: this one is named 
after AWS'
+     * own endpoint terminology and can also be used for the endpoint override 
in the
+     * client builder.
+     */
+    private String getAwsEndpointUri() {
+        return configuration.getProtocol() + "://" + 
getFullyQualifiedAWSHost();
+    }
+
     @Override
     protected void doInit() throws Exception {
         super.doInit();
@@ -148,9 +163,7 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint 
implements HeaderFilterS
             // This allows accessing queues where you don't have permission to
             // list queues or query queues
             if (configuration.getRegion() != null && 
configuration.getQueueOwnerAWSAccountId() != null) {
-                String protocol = configuration.getProtocol();
-
-                queueUrl = protocol + "://" + getFullyQualifiedAWSHost() + "/" 
+ configuration.getQueueOwnerAWSAccountId() + "/" + 
configuration.getQueueName();
+                queueUrl = getAwsEndpointUri() + "/" + 
configuration.getQueueOwnerAWSAccountId() + "/" + configuration.getQueueName();
             } else if (configuration.getQueueOwnerAWSAccountId() != null) {
                 GetQueueUrlRequest.Builder getQueueUrlRequest = 
GetQueueUrlRequest.builder();
                 getQueueUrlRequest.queueName(configuration.getQueueName());
@@ -358,6 +371,11 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint 
implements HeaderFilterS
             }
         }
 
+        if (!isDefaultAwsHost()) {
+            String endpointOverrideUri = getAwsEndpointUri();
+            clientBuilder.endpointOverride(URI.create(endpointOverrideUri));
+        }
+
         if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
             clientBuilder = 
clientBuilder.region(Region.of(configuration.getRegion()));
         }

Reply via email to