Angel
Angel

Reputation: 3

Apache Camel - from netty to file

I'm using the netty component for socket communication between two systems, request and response.

This is the route

<from uri="netty:tcp://localhost:61616?encoder=#encoder"/>
<to uri="netty:tcp://localhost:61618?decoder=#decoder"/>
<log message="Receive ${body}">
<to uri="file://data?fileName=data2&amp;charset=utf-8"/>

Everything, works fine, the data I send is buffer type, as well as the response received. I can see this data as String using the log ${body}, but there's nothing in the file where is suppossed to store this data.

I'm guessing that camel uses a converter (from buffer to string) for logging the body as plain text, but why is not saving something in the file, using a default converter for this????

I appreciate any comments of how to resolve this. Thank you !!!

Upvotes: 0

Views: 906

Answers (1)

Uday Matta
Uday Matta

Reputation: 56

Since your paylaod is ByteBuffer you need to explicitly convert to either String or byte[]

<from uri="netty:tcp://localhost:61616?encoder=#encoder"/>
<to uri="netty:tcp://localhost:61618?decoder=#decoder"/>
<convertBodyTo type="byte[]"/>
<log message="Receive ${body}">
<to uri="file://data?fileName=data2&amp;charset=utf-8"/>

You can even use type="java.lang.String"

Please refer to the link http://camel.apache.org/type-converter.html

Hope it helps...

Upvotes: 1

Related Questions