This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit da81043f14c91d961d8dd040c3e409d777eb9a63 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Dec 18 13:40:29 2020 +0100 CAMEL-15973 - Camel-AWS2-SQS: Set the queue policy as file and not as plain String --- components/camel-aws2-sqs/pom.xml | 4 ++++ .../camel/component/aws2/sqs/Sqs2Configuration.java | 3 ++- .../apache/camel/component/aws2/sqs/Sqs2Endpoint.java | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/camel-aws2-sqs/pom.xml b/components/camel-aws2-sqs/pom.xml index a5a6944..47296d4 100644 --- a/components/camel-aws2-sqs/pom.xml +++ b/components/camel-aws2-sqs/pom.xml @@ -50,6 +50,10 @@ <artifactId>apache-client</artifactId> <version>${aws-java-sdk2-version}</version> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> <!-- test infra --> <dependency> diff --git a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java index 9b7f0b2..e824a72 100644 --- a/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java +++ b/components/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java @@ -286,7 +286,8 @@ public class Sqs2Configuration implements Cloneable { } /** - * The policy for this queue + * The policy for this queue. It can be loaded by default from classpath, but you can prefix with "classpath:", "file:", or + * "http:" to load the resource from different systems. */ public void setPolicy(String policy) { this.policy = policy; 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 1282b4b..2dc209c 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 @@ -16,6 +16,9 @@ */ package org.apache.camel.component.aws2.sqs; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -35,9 +38,11 @@ import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; import org.apache.camel.support.DefaultScheduledPollConsumerScheduler; +import org.apache.camel.support.ResourceHelper; import org.apache.camel.support.ScheduledPollEndpoint; import org.apache.camel.util.FileUtil; import org.apache.camel.util.ObjectHelper; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.awssdk.regions.Region; @@ -211,7 +216,7 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint implements HeaderFilterS } } - protected void createQueue(SqsClient client) { + protected void createQueue(SqsClient client) throws IOException { if (queueExists(client)) { return; } @@ -239,7 +244,10 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint implements HeaderFilterS String.valueOf(getConfiguration().getMessageRetentionPeriod())); } if (getConfiguration().getPolicy() != null) { - attributes.put(QueueAttributeName.POLICY, String.valueOf(getConfiguration().getPolicy())); + InputStream s = ResourceHelper.resolveMandatoryResourceAsInputStream(this.getCamelContext(), + getConfiguration().getPolicy()); + String policy = IOUtils.toString(s, Charset.defaultCharset()); + attributes.put(QueueAttributeName.POLICY, policy); } if (getConfiguration().getReceiveMessageWaitTimeSeconds() != null) { attributes.put(QueueAttributeName.RECEIVE_MESSAGE_WAIT_TIME_SECONDS, @@ -278,7 +286,7 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint implements HeaderFilterS LOG.trace("Queue created and available at: {}", queueUrl); } - private void updateQueueAttributes(SqsClient client) { + private void updateQueueAttributes(SqsClient client) throws IOException { SetQueueAttributesRequest.Builder request = SetQueueAttributesRequest.builder().queueUrl(queueUrl); Map<QueueAttributeName, String> attributes = new HashMap<QueueAttributeName, String>(); if (getConfiguration().getDefaultVisibilityTimeout() != null) { @@ -293,7 +301,10 @@ public class Sqs2Endpoint extends ScheduledPollEndpoint implements HeaderFilterS String.valueOf(getConfiguration().getMessageRetentionPeriod())); } if (getConfiguration().getPolicy() != null) { - attributes.put(QueueAttributeName.POLICY, String.valueOf(getConfiguration().getPolicy())); + InputStream s = ResourceHelper.resolveMandatoryResourceAsInputStream(this.getCamelContext(), + getConfiguration().getPolicy()); + String policy = IOUtils.toString(s, Charset.defaultCharset()); + attributes.put(QueueAttributeName.POLICY, policy); } if (getConfiguration().getReceiveMessageWaitTimeSeconds() != null) { attributes.put(QueueAttributeName.RECEIVE_MESSAGE_WAIT_TIME_SECONDS,