This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 ee986cad332a CAMEL-26238: camel-jcache - PUTALL fails with an
InvalidPayloadException when the body is not a Map (#29079)
ee986cad332a is described below
commit ee986cad332a330be9ac19b4945a3e33b527d58a
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Nov 3 12:11:16 2026 +0100
CAMEL-26238: camel-jcache - PUTALL fails with an InvalidPayloadException
when the body is not a Map (#29079)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/docs/jcache-component.adoc | 2 ++
.../src/main/docs/jcache-component.adoc | 2 ++
.../camel/component/jcache/JCacheProducer.java | 6 ++++++
.../component/jcache/JCacheProducerPutTest.java | 22 ++++++++++++++++++++++
4 files changed, 32 insertions(+)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jcache-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jcache-component.adoc
index aba87a4c06b4..961e030eaf1c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jcache-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jcache-component.adoc
@@ -36,6 +36,8 @@ The producer performs one cache operation per message: the
`action` option sets
`GETALL`, `GETANDREMOVE`, `GETANDREPLACE`, `GETANDPUT`, `REPLACE`, `REMOVE`,
`REMOVEALL`, `CLEAR` and `INVOKE`.
The `CamelJCacheKey` header names the entry (`CamelJCacheKeys`, a set of keys,
for the `ALL` operations), the
message body is the value to store, and a `GET` puts the value found in the
body.
+`PUTALL` takes no key header: the body is a `Map` of the keys and the values
to store, and any other body fails
+with an `InvalidPayloadException`.
Storing a value under a key:
diff --git a/components/camel-jcache/src/main/docs/jcache-component.adoc
b/components/camel-jcache/src/main/docs/jcache-component.adoc
index aba87a4c06b4..961e030eaf1c 100644
--- a/components/camel-jcache/src/main/docs/jcache-component.adoc
+++ b/components/camel-jcache/src/main/docs/jcache-component.adoc
@@ -36,6 +36,8 @@ The producer performs one cache operation per message: the
`action` option sets
`GETALL`, `GETANDREMOVE`, `GETANDREPLACE`, `GETANDPUT`, `REPLACE`, `REMOVE`,
`REMOVEALL`, `CLEAR` and `INVOKE`.
The `CamelJCacheKey` header names the entry (`CamelJCacheKeys`, a set of keys,
for the `ALL` operations), the
message body is the value to store, and a `GET` puts the value found in the
body.
+`PUTALL` takes no key header: the body is a `Map` of the keys and the values
to store, and any other body fails
+with an `InvalidPayloadException`.
Storing a value under a key:
diff --git
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheProducer.java
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheProducer.java
index 2d9ed83db37f..3ee0bed74c7c 100644
---
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheProducer.java
+++
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheProducer.java
@@ -25,6 +25,7 @@ import javax.cache.Cache;
import javax.cache.processor.EntryProcessor;
import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Message;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
@@ -94,6 +95,11 @@ public class JCacheProducer extends DefaultProducer {
PUTALL {
@Override
void validate(Cache<Object, Object> cache, Exchange exchange)
throws Exception {
+ if (exchange.getIn().getBody(Map.class) == null) {
+ throw new InvalidPayloadException(
+ exchange, Map.class, exchange.getIn(),
+ "action " + name() + " needs a Map of the keys and
values to put in the message body");
+ }
}
@Override
diff --git
a/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheProducerPutTest.java
b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheProducerPutTest.java
index 17a079d0cbc6..7f7458775bd1 100644
---
a/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheProducerPutTest.java
+++
b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheProducerPutTest.java
@@ -21,7 +21,9 @@ import java.util.Map;
import javax.cache.Cache;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Predicate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -29,7 +31,10 @@ import org.apache.camel.test.junit6.TestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JCacheProducerPutTest extends JCacheComponentTestSupport {
@@ -147,6 +152,23 @@ public class JCacheProducerPutTest extends
JCacheComponentTestSupport {
}
}
+ @Test
+ void testPutAllWithBodyThatIsNotAMapFails() {
+ final Map<String, Object> headers = new HashMap<>();
+ headers.put(JCacheConstants.ACTION, "PUTALL");
+
+ for (Object body : new Object[] { "not a map", null }) {
+ CamelExecutionException e =
assertThrows(CamelExecutionException.class,
+ () -> template.requestBodyAndHeaders("direct:put", body,
headers));
+
+ InvalidPayloadException cause =
assertInstanceOf(InvalidPayloadException.class, e.getCause());
+ assertEquals(Map.class, cause.getType());
+ assertTrue(cause.getMessage().contains("action PUTALL needs a
Map"), cause.getMessage());
+ // the message names the type of the body, never its content
+ assertFalse(cause.getMessage().contains("not a map"),
cause.getMessage());
+ }
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {