camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: ToStringTypeConverter and null message bodies
Date Wed, 21 Oct 2009 15:28:04 GMT
On Wed, Oct 21, 2009 at 4:53 PM, ndjensen <ndjensen@gmail.com> wrote:
>
> Just tested it against the 2.1 snapshot.  That fixed it, the method now
> receives null when null was sent.  Thanks!
>

Great and thanks for reporting. There is an unit test now so we wont
introduce the bug again :)

>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> I have committed a fix. Would be cool if you could test it on your system.
>>
>> You can build from the source or wait for a new SNAPSHOT being deployed
>> http://camel.apache.org/download.html
>>
>>
>> On Tue, Oct 20, 2009 at 6:43 PM, ndjensen <ndjensen@gmail.com> wrote:
>>>
>>> I'm upgrading to camel 2.0 and hit a snag with the type conversions that
>>> didn't occur with camel 1.5.  Basically I have a route like this:
>>>
>>> <route id="tasks">
>>>        <from uri="timer://taskTimer?fixedRate=true&amp;period=60000"
/>
>>>        <bean ref="taskQueue" method="fireTask" />
>>>        <bean ref="taskSrv" method="runTask" />
>>> </route>
>>>
>>>
>>> The taskQueue's fireTask() will return null if there are no tasks in the
>>> queue.  That gets passed along to the taskSrv's runTask(String msg)
>>> method,
>>> which instead of receiving null, it receives "Message: [Body is null]".
>>> Since it tries to process all the strings it receives that are not null,
>>> it
>>> fails.
>>>
>>> I traced into the camel code, and the
>>> ToStringTypeConverter.convertTo(Class,
>>> Object) method is called and gets into value.toString().  The value is of
>>> type DefaultMessage, which has a toString() method
>>>
>>>    @Override
>>>    public String toString() {
>>>        return MessageHelper.extractBodyForLogging(this);
>>>    }
>>>
>>> which returns the bad "Message: [Body is null]" message.  I think
>>> DefaultMessage should check for a null body and return null if the body
>>> really is null.
>>>
>>> To get around this in all cases, I tried to add my own converter for
>>> DefaultMessage to String, which is successfully detected but then not
>>> called.  The issue is that the ToStringTypeConverter had been promoted
>>> from
>>> a fallback type converter to a regular typeconverter (see rev 793935),
>>> which
>>> apparently was being found instead of my custom type converter.
>>>
>>> I've worked around this by putting a filter on this route that ensures
>>> the
>>> message is not null, but you should be able to send a null to a method
>>> expecting a string and receive a null.
>>>
>>> Also FYI, the links to camel 2.0 on the Download page don't work (I'm
>>> using
>>> Firefox 3.5).
>>> --
>>> View this message in context:
>>> http://www.nabble.com/ToStringTypeConverter-and-null-message-bodies-tp25978515p25978515.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://www.nabble.com/ToStringTypeConverter-and-null-message-bodies-tp25978515p25994104.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message