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 4bf3ca7530d0 CAMEL-24317: camel-aws2-eventbridge - throw when 
pojoRequest=true and the body is the wrong type (#25255)
4bf3ca7530d0 is described below

commit 4bf3ca7530d0276aa0d487e29838514cc34be84f
Author: Andrea Cosentino <[email protected]>
AuthorDate: Fri Jul 31 18:21:54 2026 +0200

    CAMEL-24317: camel-aws2-eventbridge - throw when pojoRequest=true and the 
body is the wrong type (#25255)
    
    * CAMEL-24317: camel-aws2-eventbridge - throw when pojoRequest=true and the 
body is the wrong type
    
    Child of CAMEL-24261. EventbridgeProducer.putRule only acted when the body 
was a
    PutRuleRequest 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.
    
    Covered by a new Mockito-based unit test (the module has no producer route
    harness); verified to fail (silent no-op) before the fix. The shared 4.22
    upgrade-guide entry was added with CAMEL-24263.
    
    Co-authored-by: Claude Opus 4.8 <[email protected]>
    Signed-off-by: Andrea Cosentino <[email protected]>
    
    * CAMEL-24317: align putRule POJO-type error message with executeOperation
    
    Addresses gnodet's review: putRule threw a bespoke "putRule operation 
requires
    PutRuleRequest in POJO mode" message while every other operation goes 
through
    executeOperation, which throws String.format("Expected body of type %s but 
was
    %s", ...). Match that format for consistency and debuggability, and update 
the
    test assertion accordingly.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
    Signed-off-by: Andrea Cosentino <[email protected]>
    
    ---------
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-authored-by: Claude Opus 4.8 <[email protected]>
---
 .../aws2/eventbridge/EventbridgeProducer.java      |  5 ++
 .../EventbridgeProducerPojoRequestTest.java        | 56 ++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git 
a/components/camel-aws/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java
 
b/components/camel-aws/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java
index 1d4a9b5af4f6..2bd92919f3c8 100644
--- 
a/components/camel-aws/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java
+++ 
b/components/camel-aws/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java
@@ -155,6 +155,11 @@ public class EventbridgeProducer extends DefaultProducer {
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
                 message.setHeader(EventbridgeConstants.RULE_ARN, 
result.ruleArn());
+            } else {
+                throw new IllegalArgumentException(
+                        String.format("Expected body of type %s but was %s",
+                                PutRuleRequest.class.getName(),
+                                ObjectHelper.isNotEmpty(payload) ? 
payload.getClass().getName() : "null"));
             }
         } else {
             PutRuleRequest.Builder builder = PutRuleRequest.builder();
diff --git 
a/components/camel-aws/camel-aws2-eventbridge/src/test/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducerPojoRequestTest.java
 
b/components/camel-aws/camel-aws2-eventbridge/src/test/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducerPojoRequestTest.java
new file mode 100644
index 000000000000..bbbaa8f92e6f
--- /dev/null
+++ 
b/components/camel-aws/camel-aws2-eventbridge/src/test/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducerPojoRequestTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.eventbridge;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * When {@code pojoRequest=true}, the producer must fail fast if the body is 
not the expected request type, rather than
+ * silently doing nothing (see CAMEL-24261).
+ */
+class EventbridgeProducerPojoRequestTest {
+
+    @Test
+    void putRuleWithPojoRequestAndWrongBodyTypeThrows() {
+        EventbridgeConfiguration configuration = new 
EventbridgeConfiguration();
+        configuration.setPojoRequest(true);
+        configuration.setOperation(EventbridgeOperations.putRule);
+
+        EventbridgeEndpoint endpoint = mock(EventbridgeEndpoint.class);
+        when(endpoint.getConfiguration()).thenReturn(configuration);
+        
when(endpoint.getEventbridgeClient()).thenReturn(mock(EventBridgeClient.class));
+
+        EventbridgeProducer producer = new EventbridgeProducer(endpoint);
+
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setBody("not a PutRuleRequest");
+
+        assertThatThrownBy(() -> producer.process(exchange))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("Expected body of type")
+                .hasMessageContaining("PutRuleRequest")
+                .hasMessageContaining("java.lang.String");
+    }
+}

Reply via email to