在调试期间的某个时刻,通过系统的信息,我被迫观看进入系统的XML格式的数据。为此,我添加了用于记录XML内容的附加行,并且XML内容显示在日志中。
此时系统开始产生将XML内容封送到XML对象的问题。
org.apache.camel.TypeConversionException: Error during type conversion from type: org.apache.camel.component.netty4.http.NettyChannelBufferStreamCache to the required type: com.company.product.customer.generated.XML with value org.apache.camel.
我认为系统中出现了一些新问题,甚至没有想到引入日志字段会引起一些麻烦。经过长达数小时的战斗后,我决定删除日志行,然后又开始无缝地工作了。
日志标记对正文消息有影响吗?为什么会这样?
<post uri="/requestXml"
type="com.company.product.customer.generated.XML"
outType="java.lang.String">
<description>Request</description>
<route>
<to uri="bean:authenticationService?method=checkUser"/>
<!--log loggingLevel="INFO" message="Incomming XML ${body}"/-->
<to uri="bean:messageTranslator?method=XMLRequestToConfiguration"/>
答案 0 :(得分:9)
这与您只能读取一次流的事实有关。
虽然流类型(如StreamSource,InputStream和Reader)是 由于性能原因常用于消息传递,它们也有一个 重要的缺点:它们只能读一次。为了能够 多次处理消息内容,流需要 缓存。
您必须在上下文级别启用流缓存,如下所示:
<camelContext streamCache="true">
有更多可用选项(例如在路由级别启用它)。在此处查看所有可用选项。 http://camel.apache.org/stream-caching.html