Repository: camel Updated Branches: refs/heads/master 6c39b692f -> c8d23d327
New Feature - AWS SNS add messageStructure property configuration Json message body support added as a new feature. on the URI configuration "..&messageStructure=json" or on the message header add (SnsConstans.MESSAGE_STRUCTURE,"json") key-value Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/48ac4abb Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/48ac4abb Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/48ac4abb Branch: refs/heads/master Commit: 48ac4abb96a78aec8df2f4c7c2e4b703f2c29a46 Parents: 6c39b69 Author: Can YAMAN <c...@yaman.me> Authored: Thu Apr 2 10:14:58 2015 +0300 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Apr 2 11:46:02 2015 +0200 ---------------------------------------------------------------------- .../camel/component/aws/sns/SnsConfiguration.java | 13 ++++++++++++- .../apache/camel/component/aws/sns/SnsConstants.java | 1 + .../apache/camel/component/aws/sns/SnsProducer.java | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/48ac4abb/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 c6d8a118..ab48722 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 @@ -44,6 +44,8 @@ public class SnsConfiguration implements Cloneable { private String topicArn; @UriParam private String policy; + @UriParam + private String messageStructure; public void setAmazonSNSEndpoint(String awsSNSEndpoint) { this.amazonSNSEndpoint = awsSNSEndpoint; @@ -108,7 +110,15 @@ public class SnsConfiguration implements Cloneable { public void setPolicy(String policy) { this.policy = policy; } - + + public String getMessageStructure() { + return messageStructure; + } + + public void setMessageStructure(String messageStructure) { + this.messageStructure = messageStructure; + } + @Override public String toString() { return "SnsConfiguration[topicName=" + topicName @@ -118,6 +128,7 @@ public class SnsConfiguration implements Cloneable { + ", subject=" + subject + ", topicArn=" + topicArn + ", policy=" + policy + + ", messageStructure=" + messageStructure + "]"; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/48ac4abb/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConstants.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConstants.java index bbbd856..72c2046 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConstants.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsConstants.java @@ -24,4 +24,5 @@ public interface SnsConstants { String MESSAGE_ID = "CamelAwsSnsMessageId"; String SUBJECT = "CamelAwsSnsSubject"; + String MESSAGE_STRUCTURE ="CamelAwsSnsMessageStructure"; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/48ac4abb/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsProducer.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsProducer.java index 5753b8a..b0dbdcc 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsProducer.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsProducer.java @@ -42,10 +42,12 @@ public class SnsProducer extends DefaultProducer { public void process(Exchange exchange) throws Exception { PublishRequest request = new PublishRequest(); + request.setTopicArn(getConfiguration().getTopicArn()); - request.setMessage(exchange.getIn().getBody(String.class)); request.setSubject(determineSubject(exchange)); - + request.setMessageStructure(determineMessageStructure(exchange)); + request.setMessage(exchange.getIn().getBody(String.class)); + LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange); PublishResult result = getEndpoint().getSNSClient().publish(request); @@ -74,6 +76,15 @@ public class SnsProducer extends DefaultProducer { return subject; } + + private String determineMessageStructure(Exchange exchange) { + String structure = exchange.getIn().getHeader(SnsConstants.MESSAGE_STRUCTURE, String.class); + if (structure == null) { + structure = getConfiguration().getMessageStructure(); + } + + return structure; + } protected SnsConfiguration getConfiguration() { return getEndpoint().getConfiguration();