FAQ
I am trying to copy a message so that I can alter it for subsequent
processing

Message newMessage = message.copy();

but the MessageSupport.copyFrom() method (which is called from
MessageSupport.copy() ) does not copy the original message body to the
newMessage body, but only a reference to the original message body, which of
course then, causes any modification to the newMessage to modify the
original message.

This looks like a bug to me. Can anyone confirm or deny this? Or suggest a
workaround?

FYI- newMessage.copyFrom(message) does the same thing:

Message newMessage = new DefaultMessage();
newMessage.copyFrom(message);

Thanks




--
View this message in context: http://camel.465427.n5.nabble.com/message-copy-Does-not-perform-deep-copy-of-the-message-body-tp5577607p5577607.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at Mar 19, 2012 at 4:40 pm
    Hi

    This is by design. Camel cannot know how to do deep copy of any
    arbitrary payload ppl may put in there.
    You have to do that yourself. Some EIPs have a onPrepare option, where
    you can do the custom deep copy,
    such as the multicast
    http://camel.apache.org/multicast

    On Mon, Mar 19, 2012 at 5:37 PM, Clay wrote:
    I am trying to copy a message so that I can alter it for subsequent
    processing

    Message newMessage = message.copy();

    but the MessageSupport.copyFrom() method (which is called from
    MessageSupport.copy() )  does not copy the original message body to the
    newMessage body, but only a reference to the original message body, which of
    course then, causes any modification to the newMessage to modify the
    original message.

    This looks like a bug to me.  Can anyone confirm or deny this?  Or suggest a
    workaround?

    FYI- newMessage.copyFrom(message) does the same thing:

    Message newMessage = new DefaultMessage();
    newMessage.copyFrom(message);

    Thanks




    --
    View this message in context: http://camel.465427.n5.nabble.com/message-copy-Does-not-perform-deep-copy-of-the-message-body-tp5577607p5577607.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/
  • Clay at Mar 19, 2012 at 4:52 pm
    Thanks Claus.

    --
    View this message in context: http://camel.465427.n5.nabble.com/message-copy-Does-not-perform-deep-copy-of-the-message-body-tp5577607p5577646.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMar 19, '12 at 4:38p
activeMar 19, '12 at 4:52p
posts3
users2
websitecamel.apache.org

2 users in discussion

Clay: 2 posts Claus Ibsen: 1 post

People

Translate

site design / logo © 2022 Grokbase