camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject [camel] branch camel-2.20.x updated: CAMEL-12292: SnsProducer/SqsProducer setting MessageAttributes with empty values which causes errors
Date Sat, 03 Mar 2018 16:40:47 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new 519e639  CAMEL-12292: SnsProducer/SqsProducer setting MessageAttributes with empty
values which causes errors
519e639 is described below

commit 519e63989512b35b4d7aac22c1c5b4e3fde01c8c
Author: Christian Mueller <cmr@amazon.com>
AuthorDate: Sat Mar 3 17:10:09 2018 +0100

    CAMEL-12292: SnsProducer/SqsProducer setting MessageAttributes with empty values which
causes errors
---
 .../camel/component/aws/sns/SnsProducer.java       |  4 +-
 .../camel/component/aws/sqs/SqsProducer.java       |  6 +--
 .../camel/component/aws/sns/SnsProducerTest.java   | 51 ++++++++++++++++++++++
 .../camel/component/aws/sqs/SqsProducerTest.java   | 22 +++++++++-
 4 files changed, 76 insertions(+), 7 deletions(-)

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 36c4a15..d87add7 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
@@ -87,14 +87,14 @@ public class SnsProducer extends DefaultProducer {
         return structure;
     }
 
-    private Map<String, MessageAttributeValue> translateAttributes(Map<String, Object>
headers, Exchange exchange) {
+    Map<String, MessageAttributeValue> translateAttributes(Map<String, Object>
headers, Exchange exchange) {
         Map<String, MessageAttributeValue> result = new HashMap<String, MessageAttributeValue>();
         HeaderFilterStrategy headerFilterStrategy = getEndpoint().getHeaderFilterStrategy();
         for (Entry<String, Object> entry : headers.entrySet()) {
             // only put the message header which is not filtered into the message attribute
             if (!headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), entry.getValue(),
exchange)) {
                 Object value = entry.getValue();
-                if (value instanceof String) {
+                if (value instanceof String && !((String)value).isEmpty()) {
                     MessageAttributeValue mav = new MessageAttributeValue();
                     mav.setDataType("String");
                     mav.withStringValue((String)value);
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java
index 682d75e..6268ea8 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java
@@ -102,15 +102,15 @@ public class SqsProducer extends DefaultProducer {
         }
         return sqsProducerToString;
     }
-    
-    private Map<String, MessageAttributeValue> translateAttributes(Map<String, Object>
headers, Exchange exchange) {
+
+    Map<String, MessageAttributeValue> translateAttributes(Map<String, Object>
headers, Exchange exchange) {
         Map<String, MessageAttributeValue> result = new HashMap<String, MessageAttributeValue>();
         HeaderFilterStrategy headerFilterStrategy = getEndpoint().getHeaderFilterStrategy();
         for (Entry<String, Object> entry : headers.entrySet()) {
             // only put the message header which is not filtered into the message attribute
             if (!headerFilterStrategy.applyFilterToCamelHeaders(entry.getKey(), entry.getValue(),
exchange)) {
                 Object value = entry.getValue();
-                if (value instanceof String) {
+                if (value instanceof String && !((String)value).isEmpty()) {
                     MessageAttributeValue mav = new MessageAttributeValue();
                     mav.setDataType("String");
                     mav.withStringValue((String)value);
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsProducerTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsProducerTest.java
new file mode 100644
index 0000000..bba7698
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsProducerTest.java
@@ -0,0 +1,51 @@
+package org.apache.camel.component.aws.sns;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.amazonaws.services.dynamodbv2.model.GetRecordsRequest;
+import com.amazonaws.services.sns.model.MessageAttributeValue;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.aws.firehose.KinesisFirehoseEndpoint;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SnsProducerTest {
+
+    @Mock
+    private Exchange exchange;
+    @Mock
+    private SnsEndpoint endpoint;
+    private SnsProducer producer;
+
+    @Before
+    public void setUp() {
+        producer = new SnsProducer(endpoint);
+
+        when(endpoint.getHeaderFilterStrategy()).thenReturn(new SnsHeaderFilterStrategy());
+    }
+
+    @Test
+    public void translateAttributes() {
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("key1", null);
+        headers.put("key2", "");
+        headers.put("key3", "value3");
+
+        Map<String, MessageAttributeValue> translateAttributes = producer.translateAttributes(headers,
exchange);
+
+        assertThat(translateAttributes.size(), is(1));
+        assertThat(translateAttributes.get("key3").getDataType(), is("String"));
+        assertThat(translateAttributes.get("key3").getStringValue(), is("value3"));
+    }
+}
\ No newline at end of file
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerTest.java
index bed350c..ab8d23f 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerTest.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import com.amazonaws.services.sqs.AmazonSQSClient;
+import com.amazonaws.services.sqs.model.MessageAttributeValue;
 import com.amazonaws.services.sqs.model.SendMessageRequest;
 import com.amazonaws.services.sqs.model.SendMessageResult;
 import org.apache.camel.Exchange;
@@ -33,13 +34,16 @@ import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 
 @RunWith(MockitoJUnitRunner.class)
 public class SqsProducerTest {
@@ -87,6 +91,20 @@ public class SqsProducerTest {
     }
 
     @Test
+    public void translateAttributes() {
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("key1", null);
+        headers.put("key2", "");
+        headers.put("key3", "value3");
+
+        Map<String, MessageAttributeValue> translateAttributes = underTest.translateAttributes(headers,
exchange);
+
+        assertThat(translateAttributes.size(), is(1));
+        assertThat(translateAttributes.get("key3").getDataType(), is("String"));
+        assertThat(translateAttributes.get("key3").getStringValue(), is("value3"));
+    }
+
+    @Test
     public void itSendsTheBodyFromAnExchange() throws Exception {
         underTest.process(exchange);
 

-- 
To stop receiving notification emails like this one, please contact
cmueller@apache.org.

Mime
View raw message