You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/03/23 14:25:18 UTC
[camel] branch main updated: CAMEL-17816 - aws2-sqs: suport byte arrays when mapping camel headers to sqs attribute
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 7fbdfcf CAMEL-17816 - aws2-sqs: suport byte arrays when mapping camel headers to sqs attribute
7fbdfcf is described below
commit 7fbdfcf46c1f675bfc9d499daf92f8f38519de30
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 23 15:19:27 2022 +0100
CAMEL-17816 - aws2-sqs: suport byte arrays when mapping camel headers to sqs attribute
---
.../component/aws2/sqs/Sqs2MessageHelper.java | 5 ++
.../SqsProducerSendByteArrayLocalstackIT.java | 66 ++++++++++++++++++++++
2 files changed, 71 insertions(+)
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2MessageHelper.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2MessageHelper.java
index 24a587f..3d3bb5c 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2MessageHelper.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2MessageHelper.java
@@ -38,6 +38,11 @@ public final class Sqs2MessageHelper {
mav.dataType("Binary");
mav.binaryValue(SdkBytes.fromByteBuffer((ByteBuffer) value));
return mav.build();
+ } else if (value instanceof byte[]) {
+ MessageAttributeValue.Builder mav = MessageAttributeValue.builder();
+ mav.dataType("Binary");
+ mav.binaryValue(SdkBytes.fromByteArray((byte[]) value));
+ return mav.build();
} else if (value instanceof Boolean) {
MessageAttributeValue.Builder mav = MessageAttributeValue.builder();
mav.dataType("Number.Boolean");
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerSendByteArrayLocalstackIT.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerSendByteArrayLocalstackIT.java
new file mode 100644
index 0000000..9a783d7
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerSendByteArrayLocalstackIT.java
@@ -0,0 +1,66 @@
+/*
+ * 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.aws2.sqs.integration;
+
+import org.apache.camel.*;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.bouncycastle.util.Strings;
+
+public class SqsProducerSendByteArrayLocalstackIT extends Aws2SQSBaseTest {
+
+ @EndpointInject("direct:start")
+ private ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ @Test
+ public void sendInOnly() throws Exception {
+ result.expectedMessageCount(1);
+
+ Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() {
+ public void process(Exchange exchange) {
+ byte[] headerValue = "HeaderTest".getBytes();
+ exchange.getIn().setHeader("value1", headerValue);
+ exchange.getIn().setBody("Test");
+ }
+ });
+
+ assertMockEndpointsSatisfied();
+ Assert.assertEquals(3, result.getExchanges().get(0).getMessage().getHeaders().size());
+ Assert.assertEquals("HeaderTest",
+ Strings.fromByteArray((byte[]) result.getExchanges().get(0).getMessage().getHeaders().get("value1")));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").startupOrder(2)
+ .toF("aws2-sqs://%s?autoCreateQueue=true", sharedNameGenerator.getName()).to("mock:result");
+
+ fromF("aws2-sqs://%s?deleteAfterRead=true&autoCreateQueue=true", sharedNameGenerator.getName())
+ .startupOrder(1).log("${body}");
+ }
+ };
+ }
+}