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.19.x updated: CAMEL-12292: SnsProducer/SqsProducer setting MessageAttributes with empty values which causes errors
Date Sat, 03 Mar 2018 16:52:33 GMT
This is an automated email from the ASF dual-hosted git repository.

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


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

commit ac04b60541572f861ef68701779f880f003e2313
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   | 67 ++++++++++++++++++++++
 .../camel/component/aws/sqs/SqsProducerTest.java   | 20 ++++++-
 4 files changed, 91 insertions(+), 6 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..38fffdc
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsProducerTest.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.sns;
+
+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;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
+@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..b7e0897 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,10 +34,13 @@ 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.junit.Assert.assertThat;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -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