You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/08 05:28:18 UTC

[camel] branch camel-3.18.x updated (7b06e1a5870 -> fe8fad61202)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 7b06e1a5870 Regen for commit ffc8c01f07efd4e19ec3f7a50b16c3d31143d420
     new aaa687ea08c CAMEL-18358: resource based endpoints should not lose attachments after processing such as freemarker and others.
     new fe8fad61202 CAMEL-17760: consolidate copy-exchange-if-capable logic

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/chunk/ChunkEndpoint.java       |  5 +--
 components/camel-freemarker/pom.xml                |  5 +++
 .../component/freemarker/FreemarkerEndpoint.java   |  7 ++--
 ...kerTest.java => FreemarkerAttachmentsTest.java} | 42 ++++++++--------------
 .../github/producer/ClosePullRequestProducer.java  |  7 ++--
 .../producer/PullRequestCommentProducer.java       |  7 ++--
 .../component/jira/producer/AddIssueProducer.java  |  9 ++---
 .../apache/camel/component/jolt/JoltEndpoint.java  | 10 +++---
 .../apache/camel/component/jslt/JsltEndpoint.java  |  6 ++--
 .../component/jsonpatch/JsonPatchProducer.java     |  4 ++-
 .../camel/component/jsonata/JsonataEndpoint.java   | 12 +++----
 .../camel/component/mustache/MustacheEndpoint.java |  5 +--
 .../apache/camel/component/mvel/MvelEndpoint.java  |  5 +--
 .../camel/component/pubnub/PubNubProducer.java     |  9 ++---
 .../stringtemplate/StringTemplateEndpoint.java     |  7 ++--
 .../component/twitter/timeline/UserProducer.java   |  9 +++--
 .../camel/component/velocity/VelocityEndpoint.java |  5 +--
 .../org/apache/camel/support/ExchangeHelper.java   | 30 ++++++++++++++++
 18 files changed, 85 insertions(+), 99 deletions(-)
 copy components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/{FreemarkerTest.java => FreemarkerAttachmentsTest.java} (61%)


[camel] 02/02: CAMEL-17760: consolidate copy-exchange-if-capable logic

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fe8fad6120269e2ef1996e41f3f011c9e641fd43
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jul 25 12:15:33 2022 +0200

    CAMEL-17760: consolidate copy-exchange-if-capable logic
---
 .../github/producer/ClosePullRequestProducer.java  |  7 ++---
 .../producer/PullRequestCommentProducer.java       |  7 ++---
 .../component/jira/producer/AddIssueProducer.java  |  9 ++-----
 .../camel/component/pubnub/PubNubProducer.java     |  9 +++----
 .../component/twitter/timeline/UserProducer.java   |  9 +++----
 .../org/apache/camel/support/ExchangeHelper.java   | 30 ++++++++++++++++++++++
 6 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/ClosePullRequestProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/ClosePullRequestProducer.java
index 671b0945cf7..62bfe4f0cec 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/ClosePullRequestProducer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/ClosePullRequestProducer.java
@@ -22,6 +22,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.github.GitHubConstants;
 import org.apache.camel.component.github.GitHubEndpoint;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.support.ExchangeHelper;
 import org.eclipse.egit.github.core.PullRequest;
 import org.eclipse.egit.github.core.service.PullRequestService;
 
@@ -55,11 +56,7 @@ public class ClosePullRequestProducer extends AbstractGitHubProducer {
         pullRequest = pullRequestService.editPullRequest(getRepository(), pullRequest);
 
         // support InOut
-        if (exchange.getPattern().isOutCapable()) {
-            // copy the header of in message to the out message
-            exchange.getOut().copyFrom(exchange.getIn());
-            exchange.getOut().setBody(pullRequest);
-        }
+        ExchangeHelper.setOutBodyPatternAware(exchange, pullRequest);
     }
 
 }
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestCommentProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestCommentProducer.java
index c5899692acf..9b4a53b7dae 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestCommentProducer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestCommentProducer.java
@@ -20,6 +20,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.github.GitHubConstants;
 import org.apache.camel.component.github.GitHubEndpoint;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.support.ExchangeHelper;
 import org.eclipse.egit.github.core.Comment;
 import org.eclipse.egit.github.core.service.IssueService;
 import org.eclipse.egit.github.core.service.PullRequestService;
@@ -78,11 +79,7 @@ public class PullRequestCommentProducer extends AbstractGitHubProducer {
         }
 
         // support InOut
-        if (exchange.getPattern().isOutCapable()) {
-            // copy the header of in message to the out message
-            exchange.getOut().copyFrom(exchange.getIn());
-            exchange.getOut().setBody(response);
-        }
+        ExchangeHelper.setOutBodyPatternAware(exchange, response);
     }
 
 }
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AddIssueProducer.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AddIssueProducer.java
index 007c69cfb26..3c21bc365c2 100644
--- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AddIssueProducer.java
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/producer/AddIssueProducer.java
@@ -29,6 +29,7 @@ import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.jira.JiraEndpoint;
 import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 
 import static org.apache.camel.component.jira.JiraConstants.*;
@@ -120,13 +121,7 @@ public class AddIssueProducer extends DefaultProducer {
         }
 
         // support InOut
-        if (exchange.getPattern().isOutCapable()) {
-            // copy the header of in message to the out message
-            exchange.getMessage().copyFrom(exchange.getIn());
-            exchange.getMessage().setBody(issue);
-        } else {
-            exchange.getIn().setBody(issue);
-        }
+        ExchangeHelper.setInOutBodyPatternAware(exchange, issue);
     }
 
 }
diff --git a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java
index 9bba652db26..3d6107d4421 100644
--- a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java
+++ b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java
@@ -33,6 +33,7 @@ import org.apache.camel.CamelException;
 import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.support.DefaultAsyncProducer;
+import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -229,12 +230,8 @@ public class PubNubProducer extends DefaultAsyncProducer {
             }
             throw new RuntimeCamelException(status.getErrorData().getThrowable());
         }
-        if (exchange.getPattern().isOutCapable()) {
-            exchange.getOut().copyFrom(exchange.getIn());
-            exchange.getOut().setBody(body);
-        } else {
-            exchange.getIn().setBody(body);
-        }
+
+        ExchangeHelper.setInOutBodyPatternAware(exchange, body);
 
         // signal exchange completion
         callback.done(false);
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/timeline/UserProducer.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/timeline/UserProducer.java
index 3f8a9a6132e..3d74ce9cd4a 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/timeline/UserProducer.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/timeline/UserProducer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.twitter.timeline;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.twitter.TwitterEndpoint;
 import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.ExchangeHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import twitter4j.Status;
@@ -54,12 +55,10 @@ public class UserProducer extends DefaultProducer {
          * Support the InOut exchange pattern in order to provide access to
          * the unique identifier for the published tweet which is returned in the response
          * by the Twitter REST API: https://dev.twitter.com/docs/api/1/post/statuses/update
+         *
+         * here we just copy the header of in message to the out message
          */
-        if (exchange.getPattern().isOutCapable()) {
-            // here we just copy the header of in message to the out message
-            exchange.getOut().copyFrom(exchange.getIn());
-            exchange.getOut().setBody(response);
-        }
+        ExchangeHelper.setOutBodyPatternAware(exchange, response);
     }
 
     private Status updateStatus(StatusUpdate status) throws Exception {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index 68e227984cd..1f93bbac561 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -1054,4 +1054,34 @@ public final class ExchangeHelper {
         UnitOfWork uow = exchange.getUnitOfWork();
         return uow != null ? uow.getRoute() : null;
     }
+
+    /**
+     * Sets the body in message in the exchange taking the exchange pattern into consideration. If the pattern is out
+     * capable, then the body is set outbound message. Otherwise it is set on the inbound message.
+     * 
+     * @param exchange the exchange containing the message to set the body
+     * @param body     the body to set
+     */
+    public static void setInOutBodyPatternAware(Exchange exchange, Object body) {
+        if (exchange.getPattern().isOutCapable()) {
+            exchange.getOut().copyFrom(exchange.getIn());
+            exchange.getOut().setBody(body);
+        } else {
+            exchange.getIn().setBody(body);
+        }
+    }
+
+    /**
+     * Sets the body in message in the exchange taking the exchange pattern into consideration. If the pattern is out
+     * capable, then the body is set outbound message. Otherwise nothing is done.
+     * 
+     * @param exchange the exchange containing the message to set the body
+     * @param body     the body to set
+     */
+    public static void setOutBodyPatternAware(Exchange exchange, Object body) {
+        if (exchange.getPattern().isOutCapable()) {
+            exchange.getOut().copyFrom(exchange.getIn());
+            exchange.getOut().setBody(body);
+        }
+    }
 }


[camel] 01/02: CAMEL-18358: resource based endpoints should not lose attachments after processing such as freemarker and others.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit aaa687ea08c977def2a6e1970537d2dd3566ddc7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Aug 8 07:25:13 2022 +0200

    CAMEL-18358: resource based endpoints should not lose attachments after processing such as freemarker and others.
---
 .../camel/component/chunk/ChunkEndpoint.java       |  5 +-
 components/camel-freemarker/pom.xml                |  5 ++
 .../component/freemarker/FreemarkerEndpoint.java   |  7 +--
 .../freemarker/FreemarkerAttachmentsTest.java      | 71 ++++++++++++++++++++++
 .../apache/camel/component/jolt/JoltEndpoint.java  | 10 ++-
 .../apache/camel/component/jslt/JsltEndpoint.java  |  6 +-
 .../component/jsonpatch/JsonPatchProducer.java     |  4 +-
 .../camel/component/jsonata/JsonataEndpoint.java   | 12 ++--
 .../camel/component/mustache/MustacheEndpoint.java |  5 +-
 .../apache/camel/component/mvel/MvelEndpoint.java  |  5 +-
 .../stringtemplate/StringTemplateEndpoint.java     |  7 +--
 .../camel/component/velocity/VelocityEndpoint.java |  5 +-
 12 files changed, 98 insertions(+), 44 deletions(-)

diff --git a/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java
index f8ad1e0b2b1..ddb8063dece 100644
--- a/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java
+++ b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java
@@ -29,7 +29,6 @@ import org.apache.camel.Category;
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -123,9 +122,7 @@ public class ChunkEndpoint extends ResourceEndpoint {
             writer.flush();
 
             // Fill out message
-            Message out = exchange.getOut();
-            out.setBody(newChunk.toString());
-            out.setHeaders(exchange.getIn().getHeaders());
+            ExchangeHelper.setInOutBodyPatternAware(exchange, newChunk.toString());
         } else {
             exchange.getIn().removeHeader(ChunkConstants.CHUNK_RESOURCE_URI);
             ChunkEndpoint newEndpoint
diff --git a/components/camel-freemarker/pom.xml b/components/camel-freemarker/pom.xml
index 1e777ded2d6..3438fef34f5 100644
--- a/components/camel-freemarker/pom.xml
+++ b/components/camel-freemarker/pom.xml
@@ -55,6 +55,11 @@
             <artifactId>camel-test-spring-junit5</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-attachments</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-management</artifactId>
diff --git a/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java b/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
index 9ab930b1110..9cb32e3250d 100644
--- a/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
+++ b/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
@@ -26,7 +26,6 @@ import org.apache.camel.Category;
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -180,9 +179,7 @@ public class FreemarkerEndpoint extends ResourceEndpoint {
         template.process(dataModel, buffer);
         buffer.flush();
 
-        // now lets output the results to the exchange
-        Message out = exchange.getOut();
-        out.setBody(buffer.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
+        // now lets store the result
+        ExchangeHelper.setInOutBodyPatternAware(exchange, buffer.toString());
     }
 }
diff --git a/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerAttachmentsTest.java b/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerAttachmentsTest.java
new file mode 100644
index 00000000000..4f57c47c027
--- /dev/null
+++ b/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerAttachmentsTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.freemarker;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.attachment.AttachmentMessage;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Freemarker unit test
+ */
+public class FreemarkerAttachmentsTest extends CamelTestSupport {
+
+    @Test
+    public void testFreemarkerAttachments() {
+        Exchange exchange = template.request("direct:a", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+                exchange.setProperty("item", "7");
+
+                AttachmentMessage am = exchange.getIn(AttachmentMessage.class);
+                am.setBody("Monday");
+                am.setHeader("name", "Christian");
+                am.addAttachment("123", new DataHandler(new FileDataSource("pom.xml")));
+            }
+        });
+
+        assertEquals("Dear Christian. You ordered item 7 on Monday.", exchange.getMessage().getBody());
+        assertEquals("Christian", exchange.getMessage().getHeader("name"));
+
+
+        AttachmentMessage am = exchange.getMessage(AttachmentMessage.class);
+        assertNotNull(am);
+        assertEquals("123", am.getAttachmentNames().iterator().next());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // START SNIPPET: example
+                from("direct:a").to(
+                        "freemarker:org/apache/camel/component/freemarker/example.ftl?allowTemplateFromHeader=true&allowContextMapAll=true");
+                // END SNIPPET: example
+            }
+        };
+    }
+}
diff --git a/components/camel-jolt/src/main/java/org/apache/camel/component/jolt/JoltEndpoint.java b/components/camel-jolt/src/main/java/org/apache/camel/component/jolt/JoltEndpoint.java
index 7d6d73c8397..40114f5c918 100644
--- a/components/camel-jolt/src/main/java/org/apache/camel/component/jolt/JoltEndpoint.java
+++ b/components/camel-jolt/src/main/java/org/apache/camel/component/jolt/JoltEndpoint.java
@@ -31,10 +31,10 @@ import com.bazaarvoice.jolt.Transform;
 import org.apache.camel.Category;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -206,13 +206,11 @@ public class JoltEndpoint extends ResourceEndpoint {
         }
 
         // now lets output the results to the exchange
-        Message message = exchange.getMessage();
+        Object body = output;
         if (getOutputType() == JoltInputOutputType.JsonString) {
-            message.setBody(JsonUtils.toJsonString(output));
-        } else {
-            message.setBody(output);
+            body = JsonUtils.toJsonString(output);
         }
-        message.setHeaders(exchange.getIn().getHeaders());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, body);
     }
 
 }
diff --git a/components/camel-jslt/src/main/java/org/apache/camel/component/jslt/JsltEndpoint.java b/components/camel-jslt/src/main/java/org/apache/camel/component/jslt/JsltEndpoint.java
index 2031fcbc10c..6f5f88ea15a 100644
--- a/components/camel-jslt/src/main/java/org/apache/camel/component/jslt/JsltEndpoint.java
+++ b/components/camel-jslt/src/main/java/org/apache/camel/component/jslt/JsltEndpoint.java
@@ -169,12 +169,10 @@ public class JsltEndpoint extends ResourceEndpoint {
         }
 
         Map<String, JsonNode> variables = extractVariables(exchange);
-
         JsonNode output = getTransform(exchange.getMessage()).apply(variables, input);
 
-        Message out = exchange.getMessage();
-        out.setBody(isPrettyPrint() ? output.toPrettyString() : output.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
+        Object body = isPrettyPrint() ? output.toPrettyString() : output.toString();
+        ExchangeHelper.setInOutBodyPatternAware(exchange, body);
     }
 
     /**
diff --git a/components/camel-json-patch/src/main/java/org/apache/camel/component/jsonpatch/JsonPatchProducer.java b/components/camel-json-patch/src/main/java/org/apache/camel/component/jsonpatch/JsonPatchProducer.java
index 15f591cc3e1..9d32e188ca8 100644
--- a/components/camel-json-patch/src/main/java/org/apache/camel/component/jsonpatch/JsonPatchProducer.java
+++ b/components/camel-json-patch/src/main/java/org/apache/camel/component/jsonpatch/JsonPatchProducer.java
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.fge.jsonpatch.JsonPatch;
 import org.apache.camel.Exchange;
 import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.support.ResourceHelper;
 
 public class JsonPatchProducer extends DefaultProducer {
@@ -48,7 +49,8 @@ public class JsonPatchProducer extends DefaultProducer {
                 JsonPatch.class);
         JsonNode input = objectMapper.readTree(exchange.getIn().getBody(String.class));
         JsonNode result = patch.apply(input);
-        exchange.getMessage().setBody(result.toString());
+
+        ExchangeHelper.setInOutBodyPatternAware(exchange, result.toString());
     }
 
 }
diff --git a/components/camel-jsonata/src/main/java/org/apache/camel/component/jsonata/JsonataEndpoint.java b/components/camel-jsonata/src/main/java/org/apache/camel/component/jsonata/JsonataEndpoint.java
index b4593c1cffa..affc1173fda 100644
--- a/components/camel-jsonata/src/main/java/org/apache/camel/component/jsonata/JsonataEndpoint.java
+++ b/components/camel-jsonata/src/main/java/org/apache/camel/component/jsonata/JsonataEndpoint.java
@@ -28,10 +28,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.camel.Category;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -114,13 +114,11 @@ public class JsonataEndpoint extends ResourceEndpoint {
         }
         output = expressions.evaluate(input);
 
-        // now lets output the results to the exchange 
-        Message out = exchange.getMessage();
+        // now lets output the results to the exchange
+        Object body = output;
         if (getOutputType() == JsonataInputOutputType.JsonString) {
-            out.setBody(output.toString());
-        } else {
-            out.setBody(output);
+            body = output.toString();
         }
-        out.setHeaders(exchange.getIn().getHeaders());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, body);
     }
 }
diff --git a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
index 402375773f4..345aaa9847f 100644
--- a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
+++ b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
@@ -30,7 +30,6 @@ import org.apache.camel.Category;
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -116,9 +115,7 @@ public class MustacheEndpoint extends ResourceEndpoint {
         writer.flush();
 
         // Fill out message
-        Message out = exchange.getMessage();
-        out.setBody(writer.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, writer.toString());
     }
 
     /**
diff --git a/components/camel-mvel/src/main/java/org/apache/camel/component/mvel/MvelEndpoint.java b/components/camel-mvel/src/main/java/org/apache/camel/component/mvel/MvelEndpoint.java
index 3316c006270..713c2a407e9 100644
--- a/components/camel-mvel/src/main/java/org/apache/camel/component/mvel/MvelEndpoint.java
+++ b/components/camel-mvel/src/main/java/org/apache/camel/component/mvel/MvelEndpoint.java
@@ -23,7 +23,6 @@ import java.util.Map;
 import org.apache.camel.Category;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -145,9 +144,7 @@ public class MvelEndpoint extends ResourceEndpoint {
         Object result = TemplateRuntime.execute(compiled, mvelContext, variableMap);
 
         // now lets output the results to the exchange
-        Message out = exchange.getMessage();
-        out.setBody(result.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, result.toString());
     }
 
     public MvelEndpoint findOrCreateEndpoint(String uri, String newResourceUri) {
diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
index c7005d4d266..29da186f221 100644
--- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
+++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
@@ -23,7 +23,6 @@ import org.apache.camel.Category;
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -154,9 +153,7 @@ public class StringTemplateEndpoint extends ResourceEndpoint {
         stTemplate.write(new NoIndentWriter(buffer));
 
         // now lets output the results to the exchange
-        Message out = exchange.getOut();
-        out.setBody(buffer.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
-        out.setHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, getResourceUri());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, buffer.toString());
+        exchange.getMessage().setHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, getResourceUri());
     }
 }
diff --git a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
index 46aa55c4ad2..64e09c102f5 100644
--- a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
+++ b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
@@ -27,7 +27,6 @@ import java.util.Properties;
 import org.apache.camel.Category;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
 import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -244,8 +243,6 @@ public class VelocityEndpoint extends ResourceEndpoint {
         engine.evaluate(velocityContext, buffer, logTag, reader);
 
         // now lets output the results to the exchange
-        Message out = exchange.getMessage();
-        out.setBody(buffer.toString());
-        out.setHeaders(exchange.getIn().getHeaders());
+        ExchangeHelper.setInOutBodyPatternAware(exchange, buffer.toString());
     }
 }