You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by geppo <ge...@gmail.com> on 2015/05/22 12:39:05 UTC

Exchange setBody not working with Camel 2.15.2

Hi,
I'm upgrading some programs from Camel 2.9.3 to 2.15.2 and I'm having all
sort of issues.

One of them is that I'm filtering out messages with Null body, but the new
version of Camel doesn't think that the body is Null.

The route is really simple e.g.

from(DirectRoutes.MyRoute)
                .id(getClass().getSimpleName())
                .transacted()
                .process(myProcessor)
                .log("Body ${in.body}")
                .filter(body().isNotNull())
                .log("Message not filtered out")
                ...

And inside myProcessor I'm setting the body to null depending on some
conditions:

    exchange.getIn().setBody(null)

With Camel 2.9.3 the message is filtered out correctly e.g.
    [22-May-2015 11:22:45.908] [INFO] [Camel (camel-1) thread #2 -
file://src/data/] MyRoute : Body

But with Camel 2.15.2 the body doesn't appear to be null, so it's not
filtered out:
    [22-May-2015 11:22:45.908] [INFO] [Camel (camel-1) thread #2 -
file://src/data/] MyRoute : Body {I AM THE MESSAGE IN INPUT}
    [22-May-2015 11:22:45.908] [INFO] [Camel (camel-1) thread #2 -
file://src/data/] MyRoute : Message not filtered out



--
View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exchange setBody not working with Camel 2.15.2

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Use the message translator eip to set a null message. If you work on
the exchange directly you likely need more work as its done here
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java#L56

On Tue, May 26, 2015 at 1:27 PM, geppo <ge...@gmail.com> wrote:
> Thanks hekonsek for the reply. I'll do it as soon as I can (I need to cleanup
> the code from all references to my company).
>
> I think the problem is on how the new Camel handles the command:
>
>    exchange.getIn().setBody(null)
>
> where:
> - exchange is DefaultExchange
> - exchange.getIn() is GenericFileMessage
>
> With Camel 2.9.3 the value of exchange.getIn().getBody() would is Null after
> the command above.
> With Camel 2.15.2 the value of exchange.getIn().getBody() is an instance of
> java.io.File with:
>    filePath = null
>    path = "C:\input_file.txt"
>    prefixLength = 3
>    status = null
>
> Has anybody noticed this behaviour?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767473.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Exchange setBody not working with Camel 2.15.2

Posted by geppo <ge...@gmail.com>.
Thanks hekonsek for the reply. I'll do it as soon as I can (I need to cleanup
the code from all references to my company).

I think the problem is on how the new Camel handles the command:

   exchange.getIn().setBody(null)

where:
- exchange is DefaultExchange
- exchange.getIn() is GenericFileMessage

With Camel 2.9.3 the value of exchange.getIn().getBody() would is Null after
the command above.
With Camel 2.15.2 the value of exchange.getIn().getBody() is an instance of
java.io.File with:
   filePath = null
   path = "C:\input_file.txt"
   prefixLength = 3
   status = null

Has anybody noticed this behaviour?



--
View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767473.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exchange setBody not working with Camel 2.15.2

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

Maybe a little Maven example demonstrating the issue? That would encourage
us to debug your problem :) .

Cheers!

pt., 22.05.2015 o 13:33 użytkownik geppo <ge...@gmail.com> napisał:

> Also the official API doc says using getIn() is fine:
>
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html
>
> "If your Processor is not producing a different Message but only needs to
> slightly modify the in, you can simply update the in Message returned by
> getIn()."
>
> So how comes this is not supported by Camel 2.15.2?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767422.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Exchange setBody not working with Camel 2.15.2

Posted by geppo <ge...@gmail.com>.
Also the official API doc says using getIn() is fine:
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html

"If your Processor is not producing a different Message but only needs to
slightly modify the in, you can simply update the in Message returned by
getIn()."

So how comes this is not supported by Camel 2.15.2?



--
View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767422.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exchange setBody not working with Camel 2.15.2

Posted by geppo <ge...@gmail.com>.
I've found a way to fix the issue by using getOut() instead of getIn() i.e.

exchange.getOut().setBody(null);

but I'm not happy:
1) the headers of the message are not exactly the same, so now I will have
to add code to copy the headers
2) I should not need to change the code. Using getIn() should be perfectly
fine as described in the Camel documentation in the section "Consider using
getIn":
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

What am I doing wrong?



--
View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767421.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exchange setBody not working with Camel 2.15.2

Posted by geppo <ge...@gmail.com>.
P.S. I've tried different versions of Camel. The bug seems to have been
introduced between version 2.14.2 and version 2.15.0



--
View this message in context: http://camel.465427.n5.nabble.com/Exchange-setBody-not-working-with-Camel-2-15-2-tp5767420p5767474.html
Sent from the Camel - Users mailing list archive at Nabble.com.