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 cde36a6cba60 CAMEL-24285: camel-aws2-polly - throw when
pojoRequest=true and the body is the wrong type (#25199)
cde36a6cba60 is described below
commit cde36a6cba607066432f9bba0c86524947e337bb
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Jul 29 14:09:38 2026 +0200
CAMEL-24285: camel-aws2-polly - throw when pojoRequest=true and the body is
the wrong type (#25199)
Child of CAMEL-24261. Polly2Producer's nine operations (synthesizeSpeech,
describeVoices, listLexicons, getLexicon, putLexicon, deleteLexicon,
startSpeechSynthesisTask, getSpeechSynthesisTask, listSpeechSynthesisTasks)
only
acted when the body was the matching request type 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.
A parameterized test covers all nine operations; verified to fail (silent
no-op)
before the fix. The shared 4.22 upgrade-guide entry was added with
CAMEL-24263.
Signed-off-by: Andrea Cosentino <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
components/camel-aws/camel-aws2-polly/pom.xml | 5 +++
.../camel/component/aws2/polly/Polly2Producer.java | 27 ++++++++++++++++
.../component/aws2/polly/Polly2ProducerTest.java | 37 ++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/components/camel-aws/camel-aws2-polly/pom.xml
b/components/camel-aws/camel-aws2-polly/pom.xml
index 80c1b2b4a4ef..5195df7e87c2 100644
--- a/components/camel-aws/camel-aws2-polly/pom.xml
+++ b/components/camel-aws/camel-aws2-polly/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-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java
b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java
index 90371bc4bb4e..a55ac6843c54 100644
---
a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java
+++
b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java
@@ -148,6 +148,9 @@ public class Polly2Producer extends DefaultProducer {
message.setHeader(Polly2Constants.CONTENT_TYPE,
result.response().contentType());
}
message.setHeader(Polly2Constants.REQUEST_CHARACTERS,
result.response().requestCharacters());
+ } else {
+ throw new IllegalArgumentException(
+ "synthesizeSpeech operation requires
SynthesizeSpeechRequest in POJO mode");
}
} else {
SynthesizeSpeechRequest.Builder request =
SynthesizeSpeechRequest.builder();
@@ -248,6 +251,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result.voices());
+ } else {
+ throw new IllegalArgumentException(
+ "describeVoices operation requires
DescribeVoicesRequest in POJO mode");
}
} else {
DescribeVoicesRequest.Builder request =
DescribeVoicesRequest.builder();
@@ -295,6 +301,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result.lexicons());
+ } else {
+ throw new IllegalArgumentException(
+ "listLexicons operation requires ListLexiconsRequest
in POJO mode");
}
} else {
ListLexiconsRequest request =
ListLexiconsRequest.builder().build();
@@ -323,6 +332,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result.lexicon());
+ } else {
+ throw new IllegalArgumentException(
+ "getLexicon operation requires GetLexiconRequest in
POJO mode");
}
} else {
String lexiconName = getConfiguration().getLexiconName();
@@ -358,6 +370,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "putLexicon operation requires PutLexiconRequest in
POJO mode");
}
} else {
String lexiconName = getConfiguration().getLexiconName();
@@ -406,6 +421,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "deleteLexicon operation requires DeleteLexiconRequest
in POJO mode");
}
} else {
String lexiconName = getConfiguration().getLexiconName();
@@ -443,6 +461,9 @@ public class Polly2Producer extends DefaultProducer {
Message message = getMessageForResponse(exchange);
message.setBody(result.synthesisTask());
message.setHeader(Polly2Constants.TASK_ID,
result.synthesisTask().taskId());
+ } else {
+ throw new IllegalArgumentException(
+ "startSpeechSynthesisTask operation requires
StartSpeechSynthesisTaskRequest in POJO mode");
}
} else {
StartSpeechSynthesisTaskRequest.Builder request =
StartSpeechSynthesisTaskRequest.builder();
@@ -570,6 +591,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result.synthesisTask());
+ } else {
+ throw new IllegalArgumentException(
+ "getSpeechSynthesisTask operation requires
GetSpeechSynthesisTaskRequest in POJO mode");
}
} else {
String taskId = getConfiguration().getTaskId();
@@ -609,6 +633,9 @@ public class Polly2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result.synthesisTasks());
+ } else {
+ throw new IllegalArgumentException(
+ "listSpeechSynthesisTasks operation requires
ListSpeechSynthesisTasksRequest in POJO mode");
}
} else {
ListSpeechSynthesisTasksRequest request =
ListSpeechSynthesisTasksRequest.builder().build();
diff --git
a/components/camel-aws/camel-aws2-polly/src/test/java/org/apache/camel/component/aws2/polly/Polly2ProducerTest.java
b/components/camel-aws/camel-aws2-polly/src/test/java/org/apache/camel/component/aws2/polly/Polly2ProducerTest.java
index 6373b43c8efc..8654a852e2f1 100644
---
a/components/camel-aws/camel-aws2-polly/src/test/java/org/apache/camel/component/aws2/polly/Polly2ProducerTest.java
+++
b/components/camel-aws/camel-aws2-polly/src/test/java/org/apache/camel/component/aws2/polly/Polly2ProducerTest.java
@@ -27,6 +27,8 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import software.amazon.awssdk.services.polly.model.Lexicon;
import software.amazon.awssdk.services.polly.model.LexiconDescription;
import software.amazon.awssdk.services.polly.model.OutputFormat;
@@ -35,6 +37,7 @@ import
software.amazon.awssdk.services.polly.model.SynthesizeSpeechRequest;
import software.amazon.awssdk.services.polly.model.Voice;
import software.amazon.awssdk.services.polly.model.VoiceId;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -228,6 +231,24 @@ public class Polly2ProducerTest extends CamelTestSupport {
assertEquals(1, tasks.size());
}
+ @ParameterizedTest
+ @CsvSource({
+ "direct:synthesizeSpeechPojo,synthesizeSpeech operation requires
SynthesizeSpeechRequest in POJO mode",
+ "direct:describeVoicesPojo,describeVoices operation requires
DescribeVoicesRequest in POJO mode",
+ "direct:listLexiconsPojo,listLexicons operation requires
ListLexiconsRequest in POJO mode",
+ "direct:getLexiconPojo,getLexicon operation requires
GetLexiconRequest in POJO mode",
+ "direct:putLexiconPojo,putLexicon operation requires
PutLexiconRequest in POJO mode",
+ "direct:deleteLexiconPojo,deleteLexicon operation requires
DeleteLexiconRequest in POJO mode",
+ "direct:startSpeechSynthesisTaskPojo,startSpeechSynthesisTask
operation requires StartSpeechSynthesisTaskRequest in POJO mode",
+ "direct:getSpeechSynthesisTaskPojo,getSpeechSynthesisTask
operation requires GetSpeechSynthesisTaskRequest in POJO mode",
+ "direct:listSpeechSynthesisTasksPojo,listSpeechSynthesisTasks
operation requires ListSpeechSynthesisTasksRequest in POJO mode",
+ })
+ void pojoRequestWithWrongBodyTypeThrows(String route, String
expectedMessage) {
+ assertThatThrownBy(() -> template.requestBody(route, "not the expected
request type"))
+ .hasRootCauseInstanceOf(IllegalArgumentException.class)
+ .hasRootCauseMessage(expectedMessage);
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@@ -276,6 +297,22 @@ public class Polly2ProducerTest extends CamelTestSupport {
from("direct:listSpeechSynthesisTasks")
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=listSpeechSynthesisTasks")
.to("mock:result");
+ from("direct:describeVoicesPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=describeVoices&pojoRequest=true");
+ from("direct:listLexiconsPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=listLexicons&pojoRequest=true");
+ from("direct:getLexiconPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=getLexicon&pojoRequest=true");
+ from("direct:putLexiconPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=putLexicon&pojoRequest=true");
+ from("direct:deleteLexiconPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=deleteLexicon&pojoRequest=true");
+ from("direct:startSpeechSynthesisTaskPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=startSpeechSynthesisTask&pojoRequest=true");
+ from("direct:getSpeechSynthesisTaskPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=getSpeechSynthesisTask&pojoRequest=true");
+ from("direct:listSpeechSynthesisTasksPojo")
+
.to("aws2-polly://test?pollyClient=#amazonPollyClient&operation=listSpeechSynthesisTasks&pojoRequest=true");
}
};
}