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 90eec63026b1 CAMEL-24326: camel-aws-config - throw when
pojoRequest=true and the body is the wrong type (#25305)
90eec63026b1 is described below
commit 90eec63026b17f51fe9bce135f14f9da47397b2c
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Aug 3 11:53:21 2026 +0200
CAMEL-24326: camel-aws-config - throw when pojoRequest=true and the body is
the wrong type (#25305)
Child of CAMEL-24261. AWSConfigProducer's five operations (putConfigRule,
removeConfigRule, describeRuleCompliance, putConformancePack,
removeConformancePack) 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.
Covered by a new Mockito-based parameterized 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.
Signed-off-by: Andrea Cosentino <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
components/camel-aws/camel-aws-config/pom.xml | 5 ++
.../component/aws/config/AWSConfigProducer.java | 15 ++++++
.../config/AWSConfigProducerPojoRequestTest.java | 62 ++++++++++++++++++++++
3 files changed, 82 insertions(+)
diff --git a/components/camel-aws/camel-aws-config/pom.xml
b/components/camel-aws/camel-aws-config/pom.xml
index 7240b72dfc77..3c146053b6d8 100644
--- a/components/camel-aws/camel-aws-config/pom.xml
+++ b/components/camel-aws/camel-aws-config/pom.xml
@@ -84,5 +84,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-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
index 909fe3c7f3e6..7d90cb22d896 100644
---
a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
+++
b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
@@ -109,6 +109,9 @@ public class AWSConfigProducer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "putConfigRule operation requires PutConfigRuleRequest
in POJO mode");
}
} else {
PutConfigRuleRequest.Builder builder =
PutConfigRuleRequest.builder();
@@ -155,6 +158,9 @@ public class AWSConfigProducer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "removeConfigRule operation requires
DeleteConfigRuleRequest in POJO mode");
}
} else {
DeleteConfigRuleRequest.Builder builder =
DeleteConfigRuleRequest.builder();
@@ -191,6 +197,9 @@ public class AWSConfigProducer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "describeRuleCompliance operation requires
DescribeComplianceByConfigRuleRequest in POJO mode");
}
} else {
DescribeComplianceByConfigRuleRequest.Builder builder =
DescribeComplianceByConfigRuleRequest.builder();
@@ -225,6 +234,9 @@ public class AWSConfigProducer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "putConformancePack operation requires
PutConformancePackRequest in POJO mode");
}
} else {
PutConformancePackRequest.Builder builder =
PutConformancePackRequest.builder();
@@ -276,6 +288,9 @@ public class AWSConfigProducer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ } else {
+ throw new IllegalArgumentException(
+ "removeConformancePack operation requires
DeleteConformancePackRequest in POJO mode");
}
} else {
DeleteConformancePackRequest.Builder builder =
DeleteConformancePackRequest.builder();
diff --git
a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerPojoRequestTest.java
b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerPojoRequestTest.java
new file mode 100644
index 000000000000..e4d25c0fd6dc
--- /dev/null
+++
b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerPojoRequestTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.aws.config;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import software.amazon.awssdk.services.config.ConfigClient;
+
+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 AWSConfigProducerPojoRequestTest {
+
+ @ParameterizedTest
+ @CsvSource({
+ "putConfigRule,putConfigRule operation requires
PutConfigRuleRequest in POJO mode",
+ "removeConfigRule,removeConfigRule operation requires
DeleteConfigRuleRequest in POJO mode",
+ "describeRuleCompliance,describeRuleCompliance operation requires
DescribeComplianceByConfigRuleRequest in POJO mode",
+ "putConformancePack,putConformancePack operation requires
PutConformancePackRequest in POJO mode",
+ "removeConformancePack,removeConformancePack operation requires
DeleteConformancePackRequest in POJO mode",
+ })
+ void pojoRequestWithWrongBodyTypeThrows(String operation, String
expectedMessage) throws Exception {
+ AWSConfigConfiguration configuration = new AWSConfigConfiguration();
+ configuration.setPojoRequest(true);
+ configuration.setOperation(AWSConfigOperations.valueOf(operation));
+
+ AWSConfigEndpoint endpoint = mock(AWSConfigEndpoint.class);
+ when(endpoint.getConfiguration()).thenReturn(configuration);
+ when(endpoint.getConfigClient()).thenReturn(mock(ConfigClient.class));
+
+ AWSConfigProducer producer = new AWSConfigProducer(endpoint);
+
+ Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+ exchange.getIn().setBody("not the expected request type");
+
+ assertThatThrownBy(() -> producer.process(exchange))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(expectedMessage);
+ }
+}