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 c0c387337170 CAMEL-28019: Fix CamelStitchKeyNames header to accept
both Collection<String> and comma-separated String (#31240)
c0c387337170 is described below
commit c0c387337170943392c6f63ed079e38d224e64ac
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Dec 2 11:53:00 2026 +0100
CAMEL-28019: Fix CamelStitchKeyNames header to accept both
Collection<String> and comma-separated String (#31240)
The CamelStitchKeyNames header declares javaType Collection<String>, but it
was read as
a String, so List.of("a","b") became ["[a", " b]"]. A Collection header is
now used as
it is, and a comma-separated String is still split. The header description
states both
accepted forms.
Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../apache/camel/catalog/components/stitch.json | 2 +-
.../org/apache/camel/component/stitch/stitch.json | 2 +-
.../camel/component/stitch/StitchConstants.java | 4 +-
.../operations/StitchProducerOperations.java | 21 ++++++++--
.../operations/StitchProducerOperationsTest.java | 49 ++++++++++++++++++++++
.../endpoint/dsl/StitchEndpointBuilderFactory.java | 5 ++-
6 files changed, 73 insertions(+), 10 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/stitch.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/stitch.json
index 8dde6a586621..fc0fff5652d3 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/stitch.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/stitch.json
@@ -38,7 +38,7 @@
"headers": {
"CamelStitchTableName": { "index": 0, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The name of the destination table that the records are loaded
into. It overrides the table name of the endpoint URI.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#TABLE_NAME" },
"CamelStitchSchema": { "index": 1, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"org.apache.camel.component.stitch.client.models.StitchSchema or Map",
"deprecated": false, "autowired": false, "secret": false, "description": "The
JSON schema that describes the records, as a StitchSchema or as a Map of JSON
schema keywords. It overrides the stitchSchema option; a value of another type
is ignored.", "constantName": "org.ap [...]
- "CamelStitchKeyNames": { "index": 2, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Collection<String>", "deprecated": false, "autowired": false, "secret": false,
"description": "The Primary Key fields of the source table, as a comma
separated String without spaces. It overrides the keyNames option.",
"constantName": "org.apache.camel.component.stitch.StitchConstants#KEY_NAMES" },
+ "CamelStitchKeyNames": { "index": 2, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Collection<String>", "deprecated": false, "autowired": false, "secret": false,
"description": "The Primary Key fields of the source table. It overrides the
keyNames option. Accepted as a Collection of String or as a comma-separated
String without spaces.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#KEY_NAMES" },
"CamelStitchCode": { "index": 3, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Integer", "deprecated": false, "autowired": false, "secret": false,
"description": "The HTTP status code of the response of the Stitch Import API.
Set only when the request succeeds: a status code of 300 or more fails the
exchange with a StitchException.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#CODE" },
"CamelStitchHeaders": { "index": 4, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Map<String, Object>", "deprecated": false, "autowired": false, "secret":
false, "description": "The HTTP headers of the response of the Stitch Import
API, by header name. Set only when the request succeeds.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#HEADERS" },
"CamelStitchStatus": { "index": 5, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The status field of the JSON response of the Stitch Import API,
empty when the response has none. Set only when the request succeeds.",
"constantName": "org.apache.camel.component.stitch.StitchConstants#STATUS" }
diff --git
a/components/camel-stitch/src/generated/resources/META-INF/org/apache/camel/component/stitch/stitch.json
b/components/camel-stitch/src/generated/resources/META-INF/org/apache/camel/component/stitch/stitch.json
index 8dde6a586621..fc0fff5652d3 100644
---
a/components/camel-stitch/src/generated/resources/META-INF/org/apache/camel/component/stitch/stitch.json
+++
b/components/camel-stitch/src/generated/resources/META-INF/org/apache/camel/component/stitch/stitch.json
@@ -38,7 +38,7 @@
"headers": {
"CamelStitchTableName": { "index": 0, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The name of the destination table that the records are loaded
into. It overrides the table name of the endpoint URI.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#TABLE_NAME" },
"CamelStitchSchema": { "index": 1, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"org.apache.camel.component.stitch.client.models.StitchSchema or Map",
"deprecated": false, "autowired": false, "secret": false, "description": "The
JSON schema that describes the records, as a StitchSchema or as a Map of JSON
schema keywords. It overrides the stitchSchema option; a value of another type
is ignored.", "constantName": "org.ap [...]
- "CamelStitchKeyNames": { "index": 2, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Collection<String>", "deprecated": false, "autowired": false, "secret": false,
"description": "The Primary Key fields of the source table, as a comma
separated String without spaces. It overrides the keyNames option.",
"constantName": "org.apache.camel.component.stitch.StitchConstants#KEY_NAMES" },
+ "CamelStitchKeyNames": { "index": 2, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Collection<String>", "deprecated": false, "autowired": false, "secret": false,
"description": "The Primary Key fields of the source table. It overrides the
keyNames option. Accepted as a Collection of String or as a comma-separated
String without spaces.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#KEY_NAMES" },
"CamelStitchCode": { "index": 3, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Integer", "deprecated": false, "autowired": false, "secret": false,
"description": "The HTTP status code of the response of the Stitch Import API.
Set only when the request succeeds: a status code of 300 or more fails the
exchange with a StitchException.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#CODE" },
"CamelStitchHeaders": { "index": 4, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"Map<String, Object>", "deprecated": false, "autowired": false, "secret":
false, "description": "The HTTP headers of the response of the Stitch Import
API, by header name. Set only when the request succeeds.", "constantName":
"org.apache.camel.component.stitch.StitchConstants#HEADERS" },
"CamelStitchStatus": { "index": 5, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The status field of the JSON response of the Stitch Import API,
empty when the response has none. Set only when the request succeeds.",
"constantName": "org.apache.camel.component.stitch.StitchConstants#STATUS" }
diff --git
a/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/StitchConstants.java
b/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/StitchConstants.java
index 178160e51c3e..bb3b01986eec 100644
---
a/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/StitchConstants.java
+++
b/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/StitchConstants.java
@@ -31,8 +31,8 @@ public final class StitchConstants {
javaType =
"org.apache.camel.component.stitch.client.models.StitchSchema or Map")
public static final String SCHEMA = HEADER_PREFIX + "Schema";
@Metadata(label = "producer",
- description = "The Primary Key fields of the source table, as a
comma separated String without spaces. It"
- + " overrides the keyNames option.",
+ description = "The Primary Key fields of the source table. It
overrides the keyNames option."
+ + " Accepted as a Collection of String or as a
comma-separated String without spaces.",
javaType = "Collection<String>")
public static final String KEY_NAMES = HEADER_PREFIX + "KeyNames";
// headers set by producer
diff --git
a/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/operations/StitchProducerOperations.java
b/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/operations/StitchProducerOperations.java
index 5c35457d7e68..3ad31a9203c0 100644
---
a/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/operations/StitchProducerOperations.java
+++
b/components/camel-stitch/src/main/java/org/apache/camel/component/stitch/operations/StitchProducerOperations.java
@@ -173,16 +173,29 @@ public class StitchProducerOperations {
return configuration.getStitchSchema();
}
+ @SuppressWarnings("unchecked")
private Collection<String> getKeyNames(final Message message) {
- final String keys = getOption(message, StitchConstants.KEY_NAMES,
configuration::getKeyNames, String.class);
-
+ final Object header = message.getHeader(StitchConstants.KEY_NAMES);
+ if (ObjectHelper.isNotEmpty(header)) {
+ if (header instanceof Collection) {
+ return (Collection<String>) header;
+ }
+ final String keys = header.toString();
+ if (ObjectHelper.isNotEmpty(keys)) {
+ return splitKeys(keys);
+ }
+ }
+ final String keys = configuration.getKeyNames();
if (ObjectHelper.isNotEmpty(keys)) {
- return Arrays.asList(keys.split(",").clone());
+ return splitKeys(keys);
}
-
return Collections.emptyList();
}
+ private static Collection<String> splitKeys(final String csv) {
+ return Arrays.asList(csv.split(",").clone());
+ }
+
private <R> R getOption(
final Message message, final String headerName, final Supplier<R>
fallbackFn, final Class<R> type) {
// we first try to look if our value in exchange otherwise fallback to
fallbackFn which could be either a function or constant
diff --git
a/components/camel-stitch/src/test/java/org/apache/camel/component/stitch/operations/StitchProducerOperationsTest.java
b/components/camel-stitch/src/test/java/org/apache/camel/component/stitch/operations/StitchProducerOperationsTest.java
index 483448b2aff0..7f1aeb5b0c60 100644
---
a/components/camel-stitch/src/test/java/org/apache/camel/component/stitch/operations/StitchProducerOperationsTest.java
+++
b/components/camel-stitch/src/test/java/org/apache/camel/component/stitch/operations/StitchProducerOperationsTest.java
@@ -85,6 +85,55 @@ class StitchProducerOperationsTest extends CamelTestSupport {
JsonUtils.convertMapToJson(operations.createStitchRequestBody(exchange.getMessage()).toMap()));
}
+ @Test
+ void testKeyNamesAsCollectionHeader() {
+ // CAMEL-28019: CamelStitchKeyNames set as List<String> must not
produce broken key names like "[a, b]"
+ final StitchConfiguration configuration = new StitchConfiguration();
+ configuration.setTableName("test_table");
+
configuration.setStitchSchema(StitchSchema.builder().addKeyword("field_1",
"integer").build());
+
+ final StitchMessage message = StitchMessage.builder()
+ .withData("field_1", "data")
+ .withSequence(0)
+ .build();
+
+ final Exchange exchange = new DefaultExchange(context);
+ exchange.getMessage().setBody(message);
+ // Set the header as a List<String> as documented in the catalog
(Collection<String>)
+ exchange.getMessage().setHeader(StitchConstants.KEY_NAMES,
List.of("field_1", "field_2"));
+
+ final StitchProducerOperations operations = new
StitchProducerOperations(new TestClient(), configuration);
+
+ assertEquals(
+
"{\"table_name\":\"test_table\",\"schema\":{\"field_1\":\"integer\"},\"messages\":[{\"action\":\"upsert\","
+ +
"\"sequence\":0,\"data\":{\"field_1\":\"data\"}}],\"key_names\":[\"field_1\",\"field_2\"]}",
+
JsonUtils.convertMapToJson(operations.createStitchRequestBody(exchange.getMessage()).toMap()));
+ }
+
+ @Test
+ void testKeyNamesAsStringHeader() {
+ // CamelStitchKeyNames set as a comma-separated String via header
(backward-compatible path)
+ final StitchConfiguration configuration = new StitchConfiguration();
+ configuration.setTableName("test_table");
+
configuration.setStitchSchema(StitchSchema.builder().addKeyword("field_1",
"integer").build());
+
+ final StitchMessage message = StitchMessage.builder()
+ .withData("field_1", "data")
+ .withSequence(0)
+ .build();
+
+ final Exchange exchange = new DefaultExchange(context);
+ exchange.getMessage().setBody(message);
+ exchange.getMessage().setHeader(StitchConstants.KEY_NAMES,
"field_1,field_2");
+
+ final StitchProducerOperations operations = new
StitchProducerOperations(new TestClient(), configuration);
+
+ assertEquals(
+
"{\"table_name\":\"test_table\",\"schema\":{\"field_1\":\"integer\"},\"messages\":[{\"action\":\"upsert\","
+ +
"\"sequence\":0,\"data\":{\"field_1\":\"data\"}}],\"key_names\":[\"field_1\",\"field_2\"]}",
+
JsonUtils.convertMapToJson(operations.createStitchRequestBody(exchange.getMessage()).toMap()));
+ }
+
@Test
void testIfCreateIfStitchRequestBodySet() {
final StitchConfiguration configuration = new StitchConfiguration();
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StitchEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StitchEndpointBuilderFactory.java
index 7ff6d4481730..7c7f1ad2e50f 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StitchEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StitchEndpointBuilderFactory.java
@@ -430,8 +430,9 @@ public interface StitchEndpointBuilderFactory {
return "CamelStitchSchema";
}
/**
- * The Primary Key fields of the source table, as a comma separated
- * String without spaces. It overrides the keyNames option.
+ * The Primary Key fields of the source table. It overrides the
keyNames
+ * option. Accepted as a Collection of String or as a comma-separated
+ * String without spaces.
*
* The option is a: {@code Collection<String>} type.
*