2014-09-04 61 views
0

我在两个系统之间使用netty组件进行套接字通信,请求和 响应。Apache Camel - 从netty到文件

这是路线

<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"/> 

一切,工作正常,我送的数据缓冲区类型,以及所收到的响应。我可以使用log $ {body}将这些数据看作字符串,但是文件中没有任何内容可以存储这些数据。

我猜骆驼使用转换器(从缓冲区到字符串)以纯文本形式记录身体,但为什么不在文件中保存某些内容,使用默认转换器为此?

我很欣赏任何有关如何解决此问题的意见。谢谢 !!!

回答

1

由于您的paylaod是字节缓冲区,你需要显式转换为String或字节[]

<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"/> 

你甚至可以使用TYPE =“java.lang.String中”

请参阅链接http://camel.apache.org/type-converter.html

希望它有帮助...

+0

谢谢。我正在使用,这当然不起作用:P。 – Angel 2014-09-09 16:54:27