This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new c71471f CAMEL-15391: override the endpoint if a custom AWS Host is provided (#4084) c71471f is described below commit c71471fc5dfc862b0ded9c01c80950db77a4c0b3 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 ee0b334..ea2b497 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 @@ -118,6 +118,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. @@ -126,13 +130,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(); @@ -151,9 +166,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()); @@ -361,6 +374,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())); }