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 8b900e03ccdf CAMEL-26125: camel-jcr - the insert operation keeps the 
headers of the message (#28901)
8b900e03ccdf is described below

commit 8b900e03ccdf60c4ed0bbd590278809753a16a17
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 2 20:39:17 2026 +0100

    CAMEL-26125: camel-jcr - the insert operation keeps the headers of the 
message (#28901)
    
    …e message
    
    The insert operation of JcrProducer set the identifier of the new node with
    exchange.getOut().setBody(...), which created a new out message without any
    headers, so every header of the incoming message was gone after the 
producer.
    It now uses exchange.getMessage().setBody(...). Added a test and an upgrade
    guide entry.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../apache/camel/component/jcr/JcrProducer.java    |  2 +-
 .../camel/component/jcr/JcrProducerTest.java       | 24 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  7 +++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
 
b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
index 7d78e93a67db..38ad2d96ef27 100644
--- 
a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
+++ 
b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
@@ -72,7 +72,7 @@ public class JcrProducer extends DefaultProducer {
                     }
                 }
                 node.addMixin("mix:referenceable");
-                exchange.getOut().setBody(node.getIdentifier());
+                exchange.getMessage().setBody(node.getIdentifier());
                 session.save();
             } else if (JcrConstants.JCR_GET_BY_ID.equals(operation)) {
                 Node node = session.getNodeByIdentifier(exchange.getIn()
diff --git 
a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
 
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
index aedee09490f3..2f140df8cbee 100644
--- 
a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
+++ 
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
@@ -49,6 +49,30 @@ public class JcrProducerTest extends JcrRouteTestSupport {
         }
     }
 
+    @Test
+    public void testInsertKeepsHeaders() throws Exception {
+        Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
+        exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, 
"keepHeadersNode");
+        exchange.getIn().setHeader("my.contents.property", 
exchange.getIn().getBody());
+        exchange.getIn().setHeader("myHeader", "myValue");
+        Exchange out = template.send("direct:a", exchange);
+        assertNotNull(out);
+        String uuid = out.getMessage().getBody(String.class);
+        assertNotNull(uuid);
+        assertEquals("myValue", out.getMessage().getHeader("myHeader"));
+        assertEquals("<hello>world!</hello>", 
out.getMessage().getHeader("my.contents.property"));
+        assertEquals("keepHeadersNode", 
out.getMessage().getHeader(JcrConstants.JCR_NODE_NAME));
+        Session session = openSession();
+        try {
+            Node node = session.getNodeByIdentifier(uuid);
+            assertEquals("/home/test/keepHeadersNode", node.getPath());
+        } finally {
+            if (session != null && session.isLive()) {
+                session.logout();
+            }
+        }
+    }
+
     @Test
     public void testNodeTypeIsSpecified() throws Exception {
         Exchange exchange = createExchangeWithBody("Test");
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index f50cb24f54d9..b3c96ca6168d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2453,6 +2453,13 @@ when `enableSniffer` is set, the nodes the sniffer 
finds, matching the scheme, h
 registered for any host. A request to another host, including the host of a 
node with another scheme or port, is now
 sent without them. A client set with the `restClient` option is not changed.
 
+=== camel-jcr - the insert operation keeps the headers of the message
+
+The `CamelJcrInsert` operation of the producer set the identifier of the new 
node on a new out message, so every
+header of the incoming message was gone after the producer. The headers are 
now kept, including `CamelJcrOperation`,
+`CamelJcrNodeName` and `CamelJcrNodeType`. Remove these headers before a later 
`jcr` producer in the same route
+if it must not use them.
+
 === camel-jira - the producers wait for the answer of Jira
 
 The `addComment`, `addIssueLink`, `addWorkLog`, `attach`, `deleteIssue`, 
`transitionIssue` and `watchers` producers

Reply via email to