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 b6e669684227 CAMEL-27833: camel-aws2-translate - accept a String 
CamelAwsTranslateTerminologyNames header (#31148)
b6e669684227 is described below

commit b6e6696842277903ed075618885bec3ac8011010
Author: Urmila Unni <[email protected]>
AuthorDate: Tue Dec 1 14:12:17 2026 +0530

    CAMEL-27833: camel-aws2-translate - accept a String 
CamelAwsTranslateTerminologyNames header (#31148)
    
    The CamelAwsTranslateTerminologyNames header was read as a Collection, so a
    String value (a single name, or a comma-separated list) converted to null 
and
    the terminology was dropped silently. The producer now accepts a String 
(split
    on commas, trimmed, empty names dropped), a String[] or a Collection, and 
fails
    with an IllegalArgumentException for other types. The 4.25 upgrade guide
    describes the change.
    
    Co-authored-by: Claude <[email protected]>
---
 .../camel/catalog/components/aws2-translate.json   |  2 +-
 .../component/aws2/translate/aws2-translate.json   |  2 +-
 .../aws2/translate/Translate2Constants.java        |  4 +-
 .../aws2/translate/Translate2Producer.java         | 29 +++++++++--
 .../aws2/translate/Translate2ProducerTest.java     | 56 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc    | 10 ++++
 .../dsl/Translate2EndpointBuilderFactory.java      |  4 +-
 7 files changed, 97 insertions(+), 10 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-translate.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-translate.json
index f8768381282f..195c4edfc6f0 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-translate.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-translate.json
@@ -53,7 +53,7 @@
   "headers": {
     "CamelAwsTranslateSourceLanguage": { "index": 0, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The language code of the text to translate, such as en or 
zh-TW, or auto to let Amazon Translate detect the language. It is used only 
when the sourceLanguage option is not set, and not when 
autodetectSourceLanguage or pojoRequest is true.", "constantNam [...]
     "CamelAwsTranslateTargetLanguage": { "index": 1, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The language code of the language to translate the text into, 
such as de or zh-TW. It is used only when the targetLanguage option is not set, 
and not when pojoRequest is true.", "constantName": 
"org.apache.camel.component.aws2.translate.Translate2Consta [...]
-    "CamelAwsTranslateTerminologyNames": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "Collection<String>", "deprecated": false, "autowired": false, 
"secret": false, "description": "The names of the custom terminologies that 
Amazon Translate applies to the translation, as a Collection of String or a 
String array; a single String is not converted and is ignored. Amazon Translate 
accepts one custom terminology per reque [...]
+    "CamelAwsTranslateTerminologyNames": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "Collection<String>", "deprecated": false, "autowired": false, 
"secret": false, "description": "The names of the custom terminologies that 
Amazon Translate applies to the translation, as a Collection of String, a 
String array, or a String with one name or names separated by commas. Amazon 
Translate accepts one custom terminology per  [...]
     "CamelAwsTranslateOperation": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The operation that the producer performs, which replaces the 
operation option. The only value is translateText.", "constantName": 
"org.apache.camel.component.aws2.translate.Translate2Constants#OPERATION" }
   },
   "bodyTypes": {
diff --git 
a/components/camel-aws/camel-aws2-translate/src/generated/resources/META-INF/org/apache/camel/component/aws2/translate/aws2-translate.json
 
b/components/camel-aws/camel-aws2-translate/src/generated/resources/META-INF/org/apache/camel/component/aws2/translate/aws2-translate.json
index f8768381282f..195c4edfc6f0 100644
--- 
a/components/camel-aws/camel-aws2-translate/src/generated/resources/META-INF/org/apache/camel/component/aws2/translate/aws2-translate.json
+++ 
b/components/camel-aws/camel-aws2-translate/src/generated/resources/META-INF/org/apache/camel/component/aws2/translate/aws2-translate.json
@@ -53,7 +53,7 @@
   "headers": {
     "CamelAwsTranslateSourceLanguage": { "index": 0, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The language code of the text to translate, such as en or 
zh-TW, or auto to let Amazon Translate detect the language. It is used only 
when the sourceLanguage option is not set, and not when 
autodetectSourceLanguage or pojoRequest is true.", "constantNam [...]
     "CamelAwsTranslateTargetLanguage": { "index": 1, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The language code of the language to translate the text into, 
such as de or zh-TW. It is used only when the targetLanguage option is not set, 
and not when pojoRequest is true.", "constantName": 
"org.apache.camel.component.aws2.translate.Translate2Consta [...]
-    "CamelAwsTranslateTerminologyNames": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "Collection<String>", "deprecated": false, "autowired": false, 
"secret": false, "description": "The names of the custom terminologies that 
Amazon Translate applies to the translation, as a Collection of String or a 
String array; a single String is not converted and is ignored. Amazon Translate 
accepts one custom terminology per reque [...]
+    "CamelAwsTranslateTerminologyNames": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "Collection<String>", "deprecated": false, "autowired": false, 
"secret": false, "description": "The names of the custom terminologies that 
Amazon Translate applies to the translation, as a Collection of String, a 
String array, or a String with one name or names separated by commas. Amazon 
Translate accepts one custom terminology per  [...]
     "CamelAwsTranslateOperation": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "autowired": false, "secret": false, 
"description": "The operation that the producer performs, which replaces the 
operation option. The only value is translateText.", "constantName": 
"org.apache.camel.component.aws2.translate.Translate2Constants#OPERATION" }
   },
   "bodyTypes": {
diff --git 
a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Constants.java
 
b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Constants.java
index 9e09c072ba9f..a721e3596fff 100644
--- 
a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Constants.java
+++ 
b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Constants.java
@@ -32,8 +32,8 @@ public interface Translate2Constants {
               javaType = "String")
     String TARGET_LANGUAGE = "CamelAwsTranslateTargetLanguage";
     @Metadata(description = "The names of the custom terminologies that Amazon 
Translate applies to the translation, as"
-                            + " a Collection of String or a String array; a 
single String is not converted and is"
-                            + " ignored. Amazon Translate accepts one custom 
terminology per request. It is not used"
+                            + " a Collection of String, a String array, or a 
String with one name or names separated by"
+                            + " commas. Amazon Translate accepts one custom 
terminology per request. It is not used"
                             + " when pojoRequest is true.",
               javaType = "Collection<String>")
     String TERMINOLOGY_NAMES = "CamelAwsTranslateTerminologyNames";
diff --git 
a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
 
b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
index 6e7fb01bcb2e..06d488a7c0bc 100644
--- 
a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
+++ 
b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.aws2.translate;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -134,10 +136,22 @@ public class Translate2Producer extends DefaultProducer {
             }
             request.sourceLanguageCode(source);
             request.targetLanguageCode(target);
-            if 
(!ObjectHelper.isEmpty(exchange.getIn().getHeader(Translate2Constants.TERMINOLOGY_NAMES,
 Collection.class))) {
-                Collection<String> terminologies
-                        = 
exchange.getIn().getHeader(Translate2Constants.TERMINOLOGY_NAMES, 
Collection.class);
-                request.terminologyNames(terminologies);
+            Object terminologyNames = 
exchange.getIn().getHeader(Translate2Constants.TERMINOLOGY_NAMES);
+            if (terminologyNames != null) {
+                // a String is one name or names separated by commas; a 
String[] or a Collection goes through the
+                // type converter
+                Collection<String> terminologies = terminologyNames instanceof 
String text
+                        ? splitTerminologyNames(text)
+                        : 
exchange.getIn().getHeader(Translate2Constants.TERMINOLOGY_NAMES, 
Collection.class);
+                if (terminologies == null) {
+                    throw new IllegalArgumentException(
+                            "The " + Translate2Constants.TERMINOLOGY_NAMES + " 
header must be a String, a String[] or a"
+                                                       + " Collection of 
names, but was a "
+                                                       + 
terminologyNames.getClass().getName());
+                }
+                if (!terminologies.isEmpty()) {
+                    request.terminologyNames(terminologies);
+                }
             }
             request.text(exchange.getMessage().getBody(String.class));
             TranslateTextResponse result;
@@ -180,4 +194,11 @@ public class Translate2Producer extends DefaultProducer {
         }
     }
 
+    private static List<String> splitTerminologyNames(String text) {
+        return Arrays.stream(text.split(","))
+                .map(String::trim)
+                .filter(name -> !name.isEmpty())
+                .toList();
+    }
+
 }
diff --git 
a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerTest.java
 
b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerTest.java
index 9c66904a1be4..8609e941ce4c 100644
--- 
a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerTest.java
+++ 
b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.aws2.translate;
 
+import java.util.List;
+
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -28,6 +30,9 @@ import 
software.amazon.awssdk.services.translate.model.TranslateTextRequest;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class Translate2ProducerTest extends CamelTestSupport {
 
@@ -57,6 +62,57 @@ public class Translate2ProducerTest extends CamelTestSupport 
{
 
     }
 
+    @Test
+    public void terminologyNamesAsCommaSeparatedString() {
+        translateWithTerminologyNames("medical, legal");
+        assertEquals(List.of("medical", "legal"), 
clientMock.lastRequest.terminologyNames());
+    }
+
+    @Test
+    public void terminologyNamesAsOneName() {
+        translateWithTerminologyNames("medical");
+        assertEquals(List.of("medical"), 
clientMock.lastRequest.terminologyNames());
+    }
+
+    @Test
+    public void terminologyNamesAsAnEmptyStringAreNotSent() {
+        Exchange exchange = translateWithTerminologyNames("");
+        assertNull(exchange.getException());
+        assertTrue(clientMock.lastRequest.terminologyNames().isEmpty());
+
+        exchange = translateWithTerminologyNames(" , ");
+        assertNull(exchange.getException());
+        assertTrue(clientMock.lastRequest.terminologyNames().isEmpty());
+    }
+
+    @Test
+    public void terminologyNamesAsArray() {
+        translateWithTerminologyNames(new String[] { "medical", "legal" });
+        assertEquals(List.of("medical", "legal"), 
clientMock.lastRequest.terminologyNames());
+    }
+
+    @Test
+    public void terminologyNamesAsList() {
+        translateWithTerminologyNames(List.of("medical", "legal"));
+        assertEquals(List.of("medical", "legal"), 
clientMock.lastRequest.terminologyNames());
+    }
+
+    @Test
+    public void terminologyNamesOfAnotherTypeFail() {
+        Exchange exchange = translateWithTerminologyNames(42);
+        IllegalArgumentException e = 
assertInstanceOf(IllegalArgumentException.class, exchange.getException());
+        assertTrue(e.getMessage().contains("java.lang.Integer"), 
e.getMessage());
+    }
+
+    private Exchange translateWithTerminologyNames(Object names) {
+        return template.request("direct:translateText", exchange -> {
+            exchange.getIn().setHeader(Translate2Constants.SOURCE_LANGUAGE, 
Translate2LanguageEnum.ITALIAN);
+            exchange.getIn().setHeader(Translate2Constants.TARGET_LANGUAGE, 
Translate2LanguageEnum.ENGLISH);
+            exchange.getIn().setHeader(Translate2Constants.TERMINOLOGY_NAMES, 
names);
+            exchange.getIn().setBody("ciao");
+        });
+    }
+
     @Test
     public void translateTextPojoTest() throws Exception {
 
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index 9abc5366181a..bf4269a9d427 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -144,3 +144,13 @@ setting) will raise an `IllegalArgumentException` ("Cannot 
use existing queue ..
 starts, the same error that was already raised when the endpoint was still 
active. Before this change, the released
 queue was silently replaced with a fresh one,
 which caused the buffered messages to be discarded.
+
+=== camel-aws2-translate - a String CamelAwsTranslateTerminologyNames header 
is used, and other types fail
+
+The `CamelAwsTranslateTerminologyNames` header can now be a `String` with one 
terminology name or names separated by
+commas, as well as a `String[]` or a `Collection` of names. Before, a `String` 
header was ignored, and the text was
+translated without a custom terminology. A route that sets this header as a 
`String` now sends the names to Amazon
+Translate, so a name that does not exist now fails the request with a 
`ResourceNotFoundException` from AWS.
+
+A header of another type, such as an `Integer`, now fails the exchange with an 
`IllegalArgumentException` instead of
+being ignored.
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Translate2EndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Translate2EndpointBuilderFactory.java
index 7e04ed75a973..094a922fa73f 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Translate2EndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Translate2EndpointBuilderFactory.java
@@ -776,8 +776,8 @@ public interface Translate2EndpointBuilderFactory {
         }
         /**
          * The names of the custom terminologies that Amazon Translate applies
-         * to the translation, as a Collection of String or a String array; a
-         * single String is not converted and is ignored. Amazon Translate
+         * to the translation, as a Collection of String, a String array, or a
+         * String with one name or names separated by commas. Amazon Translate
          * accepts one custom terminology per request. It is not used when
          * pojoRequest is true.
          * 

Reply via email to