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

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 31f0b6a614da15cf6fea686bd8470888c1fd3301
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Feb 15 13:17:52 2023 +0100

    CAMEL-19060: avoid extra unnecessary work when copying the messages
    
    - Setting the Camel context is done on copyFromWithNewBody
    - Setting the exchange is done on copyFromWithNewBody
---
 .../main/java/org/apache/camel/support/MessageSupport.java | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java 
b/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
index fac6df58d72..87f30bac445 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
@@ -173,8 +173,7 @@ public abstract class MessageSupport implements Message, 
CamelContextAware, Data
     @Override
     public Message copy() {
         Message answer = newInstance();
-        // must copy over CamelContext
-        CamelContextAware.trySetCamelContext(answer, camelContext);
+
         answer.copyFrom(this);
         return answer;
     }
@@ -182,17 +181,10 @@ public abstract class MessageSupport implements Message, 
CamelContextAware, Data
     @Override
     public void copyFrom(Message that) {
         if (that == this) {
-            // the same instance so do not need to copy
+            // it's the same instance, so do not need to copy
             return;
         }
 
-        // must copy over CamelContext
-        CamelContextAware.trySetCamelContext(that, camelContext);
-        // cover over exchange if none has been assigned
-        if (getExchange() == null) {
-            setExchange(that.getExchange());
-        }
-
         copyFromWithNewBody(that, that.getBody());
         // Preserve the DataType
         if (that instanceof DataTypeAware) {
@@ -206,7 +198,7 @@ public abstract class MessageSupport implements Message, 
CamelContextAware, Data
     @Override
     public void copyFromWithNewBody(Message that, Object newBody) {
         if (that == this) {
-            // the same instance so do not need to copy
+            // it's the same instance, so do not need to copy
             return;
         }
 

Reply via email to