FAQ
Hi all,
using the file component I encountered a behaviour that doesn't seem right
to me... but maybe it's an intended behaviour.

Basically the issue shows when I have a route that reads the contents of a
file using the file component and then the message body goes to null. At
this point, any subsequent call to "getBody" (for instance a log("${body})
will cause the file to be read again, and put in the body.

This behaviour is caused by the GenericFileMessage method "createBody()"
(invoked by the MessageSupport.getBody() when the body is null) that, for
the sake of lazy file loading, loads the file again every time it is
invoked.

This means that I cannot have an empty body, for any reason, in a route
initiated by a file component. This seems wrong to me as null body can have
valid meaning in a camel route.
It this an intended behaviour?

I created a test class for this issue that you can get here:
TestGhostFileBody.java
<http://camel.465427.n5.nabble.com/file/n5765116/TestGhostFileBody.java> .
Let me know if you have problems getting it.

Thanks,
A.



--
View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Willem Jiang at Apr 2, 2015 at 6:02 am
    It’s hard for the Camel to know if the null body is intend of just a lazy value.
    I think you can work around it by setting the message body to be an empty String instead of null if you don’t want to Camel to process the message any more.

    --
    Willem Jiang

    Red Hat, Inc.
    Web: http://www.redhat.com
    Blog: http://willemjiang.blogspot.com (English)
    http://jnn.iteye.com (Chinese)
    Twitter: willemjiang
    Weibo: 姜宁willem


    On April 1, 2015 at 5:02:58 PM, A.Light (angelo.leggio@axiossystems.com) wrote:
    Hi all,
    using the file component I encountered a behaviour that doesn't seem right
    to me... but maybe it's an intended behaviour.

    Basically the issue shows when I have a route that reads the contents of a
    file using the file component and then the message body goes to null. At
    this point, any subsequent call to "getBody" (for instance a log("${body})
    will cause the file to be read again, and put in the body.

    This behaviour is caused by the GenericFileMessage method "createBody()"
    (invoked by the MessageSupport.getBody() when the body is null) that, for
    the sake of lazy file loading, loads the file again every time it is
    invoked.

    This means that I cannot have an empty body, for any reason, in a route
    initiated by a file component. This seems wrong to me as null body can have
    valid meaning in a camel route.
    It this an intended behaviour?

    I created a test class for this issue that you can get here:
    TestGhostFileBody.java

    .
    Let me know if you have problems getting it.

    Thanks,
    A.



    --
    View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • A.Light at Apr 29, 2015 at 10:22 am
    Hi Willem,
    thanks for your reply.

    The more I think about this, the more I get convinced that this isn't right.
    Whatever the case is, the file should be read only once. I cannot find a
    scenario where reading the file more than once is different than exploiting
    a loose side effect.

    Maybe it's stupid, but couldn't the file component simply have an internal
    property that remembers if the file has been already read or not? Or
    something alike, that basically leaves the lazy reading in place, but avoids
    multiple readings of the file?

    Kind regards,
    A.



    --
    View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116p5766473.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • A.Light at Apr 29, 2015 at 10:21 am
    In case the answers to my questions are no, considering the serious issue of
    having a supposedly empty body suddenly filled with the whole file, I would
    then consider the extreme solution of giving up lazy reading (or at least
    having it optional, with clear explanations of the consecuencies).

    Thanks,
    A.



    --
    View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116p5766474.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Claus Ibsen at Apr 29, 2015 at 11:23 am
    Returning null from a bean is considered as a noop operation - eg dont
    change the message.

    If you want to set the message to null then use a message translator
    eip such as transform

    <transform><simple>${null}</simple></transform>







    On Wed, Apr 29, 2015 at 11:15 AM, A.Light
    wrote:
    In case the answers to my questions are no, considering the serious issue of
    having a supposedly empty body suddenly filled with the whole file, I would
    then consider the extreme solution of giving up lazy reading (or at least
    having it optional, with clear explanations of the consecuencies).

    Thanks,
    A.



    --
    View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116p5766474.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/
  • A.Light at Apr 29, 2015 at 3:14 pm
    Claus,
    I gave it a thought but... if what you say is true, why when the body type
    is String then - after the bean call - the body does atually change to null?
    It seems to be a problem of consistency or maybe there's a bug in the "noop"
    implementation, I don't know.

    Anyway, I debugged the code and the issue is that the File component
    actively reads the file AGAIN, every time it's invoked a getBody on a body =
    null. So the body WAS actually null but it got overwritten. And it will do
    that every time.

    To me this is not right, as I explained in my previous messages.
    Do you see my point?






    --
    View this message in context: http://camel.465427.n5.nabble.com/GenericFileMessage-creates-body-from-file-multiples-times-tp5765116p5766511.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedApr 1, '15 at 9:02a
activeApr 29, '15 at 3:14p
posts6
users3
websitecamel.apache.org

People

Translate

site design / logo © 2021 Grokbase