You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by LavanyaKC <ck...@progress.com> on 2008/10/27 08:23:03 UTC

Problems with convertBodyTo in Java DSL

I am having a problem using the below code:

from("file:///file.txt").splitter(expression).convertBodyTo(String.class).to("file://result.txt")

This does not work, the reason being the convertBodyTo method of
ProcessorType class returns convertBodyTo[null] though I have set the value
to String.class. However the following works:

SplitterType splitter = from("file:///file.txt").splitter(expression);
splitter.addOutput(new ConvertBodyType("java.lang.String"));
splitter.to("file://result.txt");

Did anyone come across such problem? It would be nice if a
convertBodyTo(String) method is exposed in ProcessorType.

Thanks,
Lavanya.
-- 
View this message in context: http://www.nabble.com/Problems-with-convertBodyTo-in-Java-DSL-tp20182844s22882p20182844.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Problems with convertBodyTo in Java DSL

Posted by Willem Jiang <wi...@gmail.com>.
The below rule should work, it does the same thing as your second rule does.
from("file:///file.txt").splitter(expression).convertBodyTo(String.class).to("file://result.txt")
I just dug the code of ConvertBodyType, found there is an issue of this
type's toString method, it will not reflect your setting of TypeClass.

I created a JIRA[1] ticked for it.

BTW, I will add a convertBodyTo(String) mehtod as you suggested.

[1]https://issues.apache.org/activemq/browse/CAMEL-1027

Willem

LavanyaKC wrote:
> I am having a problem using the below code:
> 
> from("file:///file.txt").splitter(expression).convertBodyTo(String.class).to("file://result.txt")
> 
> This does not work, the reason being the convertBodyTo method of
> ProcessorType class returns convertBodyTo[null] though I have set the value
> to String.class. However the following works:
> 
> SplitterType splitter = from("file:///file.txt").splitter(expression);
> splitter.addOutput(new ConvertBodyType("java.lang.String"));
> splitter.to("file://result.txt");
> 
> Did anyone come across such problem? It would be nice if a
> convertBodyTo(String) method is exposed in ProcessorType.
> 
> Thanks,
> Lavanya.