This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 e8a15a45a768 CAMEL-25319: camel-aws2-sqs - batchSeparator is a plain
string, not a regular expression (#27395)
e8a15a45a768 is described below
commit e8a15a45a768a7514e9d02f3e86e54c36cd0add4
Author: allthingssecurity <[email protected]>
AuthorDate: Tue Oct 6 14:51:37 2026 +0530
CAMEL-25319: camel-aws2-sqs - batchSeparator is a plain string, not a
regular expression (#27395)
* CAMEL-25319: camel-aws2-sqs - batchSeparator is a plain string, not a
regular expression
The sendBatchMessage operation split a String body with
String.split(batchSeparator), which takes a regular expression. A separator
such as | split the body into single characters, which were sent as messages
together with the separators, and . sent no message at all.
Quote the separator.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* CAMEL-25319: camel-aws2-sqs - Use the plain component name as the
upgrade-guide heading
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel/component/aws2/sqs/Sqs2Producer.java | 4 +-
.../aws2/sqs/SqsProducerBatchSeparatorTest.java | 86 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc | 12 +++
3 files changed, 101 insertions(+), 1 deletion(-)
diff --git
a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java
b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java
index 2dfeb90d2f0f..5ad74c9f13eb 100644
---
a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java
+++
b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Producer.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
+import java.util.regex.Pattern;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -138,7 +139,8 @@ public class Sqs2Producer extends DefaultProducer {
sendBatchEntries(amazonSQS, exchange, entries);
} else if (exchange.getIn().getBody() instanceof String) {
String c = exchange.getIn().getBody(String.class);
- String[] elements =
c.split(getConfiguration().getBatchSeparator());
+ // the separator is a plain string, not a regular expression
+ String[] elements =
c.split(Pattern.quote(getConfiguration().getBatchSeparator()));
List<SendMessageBatchRequestEntry> entries = new ArrayList<>();
int index = 0;
for (String o : elements) {
diff --git
a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsProducerBatchSeparatorTest.java
b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsProducerBatchSeparatorTest.java
new file mode 100644
index 000000000000..71f326297b9a
--- /dev/null
+++
b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsProducerBatchSeparatorTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.sqs.model.SendMessageBatchRequestEntry;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The batchSeparator splits a String body into the messages of the batch: it
is a separator, not a regular expression.
+ */
+class SqsProducerBatchSeparatorTest extends CamelTestSupport {
+
+ @BindToRegistry("client")
+ AmazonSQSClientMock mock = new AmazonSQSClientMock();
+
+ @EndpointInject("direct:start")
+ private ProducerTemplate template;
+
+ @Test
+ void pipeSeparator() {
+ template.sendBodyAndHeader("direct:start", "team1|team2|team3",
"separator", "pipe");
+
+ assertEquals(List.of("team1", "team2", "team3"), sentBodies());
+ }
+
+ @Test
+ void dotSeparator() {
+ template.sendBodyAndHeader("direct:start", "team1.team2", "separator",
"dot");
+
+ assertEquals(List.of("team1", "team2"), sentBodies());
+ }
+
+ @Test
+ void defaultCommaSeparator() {
+ template.sendBodyAndHeader("direct:start", "team1,team2,team3",
"separator", "comma");
+
+ assertEquals(List.of("team1", "team2", "team3"), sentBodies());
+ }
+
+ private List<String> sentBodies() {
+ return mock.getSendMessageBatchRequests().stream()
+ .flatMap(request -> request.entries().stream())
+ .map(SendMessageBatchRequestEntry::messageBody)
+ .toList();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .choice()
+ .when(header("separator").isEqualTo("pipe"))
+
.to("aws2-sqs://camel-1?amazonSQSClient=#client&operation=sendBatchMessage&batchSeparator=|")
+ .when(header("separator").isEqualTo("dot"))
+
.to("aws2-sqs://camel-1?amazonSQSClient=#client&operation=sendBatchMessage&batchSeparator=.")
+ .otherwise()
+
.to("aws2-sqs://camel-1?amazonSQSClient=#client&operation=sendBatchMessage");
+ }
+ };
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index d254cf412111..93dfb7d63f0f 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -543,6 +543,18 @@ A header that carries a literal `${...}` string is now
used as the object key ve
A configured `keyName` or `bucketName` whose Simple expression resolves to
`null` now fails with an
`IllegalArgumentException` at the producer, instead of passing a `null`
key/bucket on to the AWS SDK.
+=== camel-aws2-sqs
+
+The `batchSeparator` option (default `,`), which splits a `String` body into
the messages of the `sendBatchMessage`
+operation, was used as a regular expression: a separator such as `|` split the
body into single characters, and `.`
+sent no message at all. It is now a plain string. A route that escaped a
separator to work around this
+(for example `batchSeparator=\|`) must now use the separator itself
(`batchSeparator=|`). The same applies to escape
+sequences, which the regular expression interpreted: `batchSeparator=\n` in an
endpoint URI split the body at line
+breaks, and is now the two characters `+\+` and `n`; use the line break itself
instead (for example
+`batchSeparator=%0A` in the endpoint URI, which works before and after this
change). A separator that relied on a
+regular expression (such as `+\s*,\s*+`) is no longer supported; split the
body in the route and send a `List`
+instead.
+
=== camel-azure-eventhubs
The producer now leaves the Camel-internal headers (`Camel*`) out of the
`EventData` application properties by