2014-09-04 102 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