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 2026/07/28 07:23:26 UTC

(camel) branch main updated: CAMEL-24264: camel-aws2-translate - throw when pojoRequest=true and the body is the wrong type (#25158)

This is an automated email from the ASF dual-hosted git repository.

oscerd 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 557752dbd2fd CAMEL-24264: camel-aws2-translate - throw when pojoRequest=true and the body is the wrong type (#25158)
557752dbd2fd is described below

commit 557752dbd2fdb30c521fd374bcf07ffa4404ecb3
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Jul 28 09:23:19 2026 +0200

    CAMEL-24264: camel-aws2-translate - throw when pojoRequest=true and the body is the wrong type (#25158)
    
    Child of CAMEL-24261. Translate2Producer.translateText only acted when the body
    was a TranslateTextRequest under pojoRequest=true; any other body silently fell
    through with no AWS call and no error. Add the missing else that throws
    IllegalArgumentException naming the required type, consistent with CAMEL-23462.
    
    The shared 4.22 upgrade-guide entry was added with CAMEL-24263.
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
    Co-authored-by: Claude Opus 4.8 <no...@anthropic.com>
---
 components/camel-aws/camel-aws2-translate/pom.xml                 | 5 +++++
 .../apache/camel/component/aws2/translate/Translate2Producer.java | 3 +++
 .../camel/component/aws2/translate/Translate2ProducerTest.java    | 8 ++++++++
 3 files changed, 16 insertions(+)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index c22e0853e8a5..0cae2005dfcf 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -78,5 +78,10 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
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 c94175afe28d..17e5e0358415 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
@@ -100,6 +100,9 @@ public class Translate2Producer extends DefaultProducer {
                 }
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result.translatedText());
+            } else {
+                throw new IllegalArgumentException(
+                        "translateText operation requires TranslateTextRequest in POJO mode");
             }
         } else {
             Builder request = TranslateTextRequest.builder();
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 0ac9b2cb8a8d..dad42153da4e 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
@@ -26,6 +26,7 @@ import org.apache.camel.test.junit6.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 import software.amazon.awssdk.services.translate.model.TranslateTextRequest;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class Translate2ProducerTest extends CamelTestSupport {
@@ -76,6 +77,13 @@ public class Translate2ProducerTest extends CamelTestSupport {
 
     }
 
+    @Test
+    void translateTextWithPojoRequestAndWrongBodyTypeThrows() {
+        assertThatThrownBy(() -> template.requestBody("direct:translatePojoText", "not a TranslateTextRequest"))
+                .hasRootCauseInstanceOf(IllegalArgumentException.class)
+                .hasRootCauseMessage("translateText operation requires TranslateTextRequest in POJO mode");
+    }
+
     @Test
     public void translateTextTestOptions() throws Exception {