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 c929360ee7af CAMEL-24263: camel-aws2-sts - throw when pojoRequest=true 
and the body is the wrong type (#25153)
c929360ee7af is described below

commit c929360ee7afec88d97af72541a1bba29ca99b8a
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Jul 28 09:22:40 2026 +0200

    CAMEL-24263: camel-aws2-sts - throw when pojoRequest=true and the body is 
the wrong type (#25153)
    
    Child of CAMEL-24261. When pojoRequest=true, STS2Producer's assumeRole,
    getSessionToken and getFederationToken branches only acted when the body 
was the
    matching request type; any other body silently fell through, so no AWS call 
was
    made, no response was set, and the original body was returned with no error.
    
    Add the missing else that throws IllegalArgumentException naming the 
required
    request type, consistent with the behaviour already shipped for 
camel-aws-bedrock
    in CAMEL-23462. Documented once in the 4.22 upgrade guide for the whole AWS2
    producer roll-out.
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-authored-by: Claude Opus 4.8 <[email protected]>
---
 .../camel/component/aws2/sts/STS2Producer.java     |  9 ++++++++
 .../camel/component/aws2/sts/STS2ProducerTest.java | 27 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_22.adoc    | 17 ++++++++++++++
 3 files changed, 53 insertions(+)

diff --git 
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
 
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
index 1a9d0c5a9a5b..b3624ca2c75b 100644
--- 
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
+++ 
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
@@ -103,6 +103,9 @@ public class STS2Producer extends DefaultProducer {
                 }
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
+            } else {
+                throw new IllegalArgumentException(
+                        "assumeRole operation requires AssumeRoleRequest in 
POJO mode");
             }
         } else {
             Builder builder = AssumeRoleRequest.builder();
@@ -157,6 +160,9 @@ public class STS2Producer extends DefaultProducer {
                 }
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
+            } else {
+                throw new IllegalArgumentException(
+                        "getSessionToken operation requires 
GetSessionTokenRequest in POJO mode");
             }
         } else {
             GetSessionTokenRequest.Builder builder = 
GetSessionTokenRequest.builder();
@@ -191,6 +197,9 @@ public class STS2Producer extends DefaultProducer {
                 }
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
+            } else {
+                throw new IllegalArgumentException(
+                        "getFederationToken operation requires 
GetFederationTokenRequest in POJO mode");
             }
         } else {
             GetFederationTokenRequest.Builder builder = 
GetFederationTokenRequest.builder();
diff --git 
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
 
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
index c520f5d73035..edd458bd86c8 100644
--- 
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
+++ 
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
@@ -100,6 +100,27 @@ public class STS2ProducerTest extends CamelTestSupport {
                 .hasRootCauseMessage("Federated name needs to be specified for 
getFederationToken operation");
     }
 
+    @Test
+    void assumeRoleWithPojoRequestAndWrongBodyTypeThrows() {
+        assertThatThrownBy(() -> template.requestBody("direct:assumeRolePojo", 
"not an AssumeRoleRequest"))
+                .hasRootCauseInstanceOf(IllegalArgumentException.class)
+                .hasRootCauseMessage("assumeRole operation requires 
AssumeRoleRequest in POJO mode");
+    }
+
+    @Test
+    void getSessionTokenWithPojoRequestAndWrongBodyTypeThrows() {
+        assertThatThrownBy(() -> 
template.requestBody("direct:getSessionTokenPojo", "not a 
GetSessionTokenRequest"))
+                .hasRootCauseInstanceOf(IllegalArgumentException.class)
+                .hasRootCauseMessage("getSessionToken operation requires 
GetSessionTokenRequest in POJO mode");
+    }
+
+    @Test
+    void getFederationTokenWithPojoRequestAndWrongBodyTypeThrows() {
+        assertThatThrownBy(() -> 
template.requestBody("direct:getFederationTokenPojo", "not a 
GetFederationTokenRequest"))
+                .hasRootCauseInstanceOf(IllegalArgumentException.class)
+                .hasRootCauseMessage("getFederationToken operation requires 
GetFederationTokenRequest in POJO mode");
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -111,6 +132,12 @@ public class STS2ProducerTest extends CamelTestSupport {
                         .to("mock:result");
                 
from("direct:getFederationToken").to("aws2-sts://test?stsClient=#amazonStsClient&operation=getFederationToken")
                         .to("mock:result");
+                from("direct:assumeRolePojo")
+                        
.to("aws2-sts://test?stsClient=#amazonStsClient&operation=assumeRole&pojoRequest=true");
+                from("direct:getSessionTokenPojo")
+                        
.to("aws2-sts://test?stsClient=#amazonStsClient&operation=getSessionToken&pojoRequest=true");
+                from("direct:getFederationTokenPojo")
+                        
.to("aws2-sts://test?stsClient=#amazonStsClient&operation=getFederationToken&pojoRequest=true");
             }
         };
     }
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
index 3e1b236e3a9c..67b28ea11a44 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
@@ -1313,3 +1313,20 @@ Update any catch blocks or method `throws` declarations 
accordingly.
 } catch (MinioException e) { ... }
 ----
 
+=== camel-aws2 - producers now fail fast on a wrong POJO request type
+
+When an AWS2 producer is configured with `pojoRequest=true`, it expects the
+Exchange body to be the AWS SDK request object for the selected operation
+(for example an `AssumeRoleRequest` for the `assumeRole` operation of
+`camel-aws2-sts`). Previously, if the body was some other type, the operation
+silently did nothing: no AWS call was made, no response was set, and the
+original body was returned with no error.
+
+These producers now throw an `IllegalArgumentException` naming the required
+request type, consistent with the behaviour already shipped for
+`camel-aws-bedrock` in 4.21 (CAMEL-23462). This roll-out across the remaining
+AWS2 producers is tracked by CAMEL-24261.
+
+If you relied on the previous silent no-op, ensure the body is the correct
+request type when `pojoRequest=true`, or drive the operation through headers
+with `pojoRequest=false`.

Reply via email to