You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Bernard Ligny <be...@gmail.com> on 2012/05/02 11:28:54 UTC

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

I rebuilt the 'camel-core' module with the suggested patch. It is working
fine...but not in *all* situations.
Let me explain:

a) A *simple* web service request (such a GET with query string) is working
fine. Thanks to the patch, I now see the various headers/properties (like
CamelHttpMethod) of the original message that is put into my DLQ 

b) A more complex web request (such as a POST with an *attachment*) is not
working. The headers are well present, but the multipart attachments are
lost. This makes impossible to "replay" the parked message

I then tried the following fix (still on 'camel-core' sources) :

Replace:
   this.originalInMessage = new DefaultMessage();
   this.originalInMessage.setBody(exchange.getIn().getBody());
   this.originalInMessage.setHeaders( exchange.getIn().getHeaders() )
By:
   this.originalInMessage = exchange.getIn().copy();
  (NB: exactly what is done for non JMS messages)

And it is, this time, working in *all* cases, even with attachments 

My problem is finally solved, but I wanted to interrogate Camel specialists
like you in order to be sure that there is no harm/risk of doing a:
   this.originalInMessage = exchange.getIn().copy();
for exchanges of JMS type

Regards,

Bernard.


--
View this message in context: http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5680043.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

Posted by Bernard Ligny <be...@gmail.com>.
I think you are confusing MIME attachments and attachments of Camel
exchanges.
When you post an attachment on a multipart web form, this attachment is
stored in a multipart *body* of an HTTP entity 

So MIME attachments are ending up into the *body* of the Camel
message/exchange (and no more as attachments) making thereby possible to
convert/serialize it into to a JMS message (on a DLQ for instance).

This being said, I still do not understand what really makes a:
     this.originalInMessage = exchange.getIn().copy(); 
work better than this:
     this.originalInMessage.setBody( exchange.getIn().getBody() ); 
     this.originalInMessage.setHeaders( exchange.getIn().getHeaders() 

 




--
View this message in context: http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5713795.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

Posted by Christian Müller <ch...@gmail.com>.
Could you share your test with us which shows your solution works?
I'm wondering because in JMS there is no equivalent for attachments... If
you send a message with attachments to ActiveMQ, I'm afraid you will lose
your attachments...

Best,
Christian

On Thu, May 3, 2012 at 10:40 AM, Bernard Ligny <be...@gmail.com>wrote:

> One more - and last - thing.
> I've just performed some additionnal tests this morning.
>
> The (complete) patch you've suggested, eg:
>            this.originalInMessage.setBody( exchange.getIn().getBody() );
>            this.originalInMessage.setHeaders( exchange.getIn().getHeaders()
> );
>            this.originalInMessage.setAttachments(
> exchange.getIn().getAttachments() );
> is *NOT* working
>
> The only "always-working" solution (at least with ActiveMQ) is copying the
> whole message through:
>            this.originalInMessage = exchange.getIn().copy();
>
> So I'm finally going to keep this satisfying solution...
>
> <END-OF-STORY>
>
> Regards,
>
> Bernard.
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5682643.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

Posted by Bernard Ligny <be...@gmail.com>.
One more - and last - thing.
I've just performed some additionnal tests this morning.

The (complete) patch you've suggested, eg:
            this.originalInMessage.setBody( exchange.getIn().getBody() );
            this.originalInMessage.setHeaders( exchange.getIn().getHeaders()
);
            this.originalInMessage.setAttachments(
exchange.getIn().getAttachments() );
is *NOT* working

The only "always-working" solution (at least with ActiveMQ) is copying the
whole message through:
            this.originalInMessage = exchange.getIn().copy();

So I'm finally going to keep this satisfying solution...

<END-OF-STORY>

Regards,

Bernard.


--
View this message in context: http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5682643.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

Posted by Bernard Ligny <be...@gmail.com>.
If I need to copy:
- the body
- the headers
- the attachements
Then, given the code behind the copy() method (see below), I do not see any
objection of invoking the whole copy method.
Can you also clarify why it could not work with all JMS implementations, eg
which portion of code, being part of CopyFrom(), may cause problem ? 
Because of the copy of the message ID (which could then be not unique) ??



public void copyFrom(Message that) {
        if (that == this) {
            // the same instance so do not need to copy
            return;
        }

        setMessageId(that.getMessageId());
        setBody(that.getBody());
        if (hasHeaders()) {
            getHeaders().clear();
        }
        if (that.hasHeaders()) {
            getHeaders().putAll(that.getHeaders());
        }
        
        if (hasAttachments()) {
            getAttachments().clear();
        }
        if (that.hasAttachments()) {
            getAttachments().putAll(that.getAttachments());
        }
    }

--
View this message in context: http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5682544.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: OriginalMsg - Why is (only) the body cloned for JMS messages ?

Posted by Christian Müller <ch...@gmail.com>.
It looks like it works with ActiveMQ. But this doesn't mean it will work
with WebShereMQ, Oracle Advanced Queuing, ...

What's about adding
this.originalInMessage.setAttachments(exchange.getIn().getAttachments());

Could you try this?

Best.
Christian

On Wed, May 2, 2012 at 11:28 AM, Bernard Ligny <be...@gmail.com>wrote:

> I rebuilt the 'camel-core' module with the suggested patch. It is working
> fine...but not in *all* situations.
> Let me explain:
>
> a) A *simple* web service request (such a GET with query string) is working
> fine. Thanks to the patch, I now see the various headers/properties (like
> CamelHttpMethod) of the original message that is put into my DLQ
>
> b) A more complex web request (such as a POST with an *attachment*) is not
> working. The headers are well present, but the multipart attachments are
> lost. This makes impossible to "replay" the parked message
>
> I then tried the following fix (still on 'camel-core' sources) :
>
> Replace:
>   this.originalInMessage = new DefaultMessage();
>   this.originalInMessage.setBody(exchange.getIn().getBody());
>   this.originalInMessage.setHeaders( exchange.getIn().getHeaders() )
> By:
>   this.originalInMessage = exchange.getIn().copy();
>  (NB: exactly what is done for non JMS messages)
>
> And it is, this time, working in *all* cases, even with attachments
>
> My problem is finally solved, but I wanted to interrogate Camel specialists
> like you in order to be sure that there is no harm/risk of doing a:
>   this.originalInMessage = exchange.getIn().copy();
> for exchanges of JMS type
>
> Regards,
>
> Bernard.
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/OriginalMsg-Why-is-only-the-body-cloned-for-JMS-messages-tp5675413p5680043.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>