写入正文日志后响应正文为空

response body is empty after write log for body

我正在 spring dsl 上测试 fuse63 的休息服务,我需要为后端系统代理 camel 上的休息服务,这里是摘录:

 <camelContext id="_camelContext1_rest" xmlns="http://camel.apache.org/schema/spring">
        <restConfiguration component="spark-rest" port="9091"/>
        <rest path="/say">
          <post consumes="application/json" produces="text/plain" uri="/hellopost">
           <to uri="direct:hellopost"/>
          </post> 
...
       <route id="_route_saypost">
            <from id="_from_saypost" uri="direct:hellopost"/>
            <log id="_log_saypost" message="this is hellopost"/>
            <to id="_file_saypost" uri="file:/tmp2/target/messages/hellopost?fileName=${header.fileName}"/>
            <setHeader headerName="camel-test" id="_setHeader1">
                <constant>this is camel</constant>
            </setHeader>
            <setHeader headerName="CamelHttpMethod" id="_setHeader2">
                <constant>POST</constant>
            </setHeader>
            <log id="_log_saypost_before_rest" message="before rest"/>
            <to id="_to1" uri="http4://192.168.56.11:8080/test/httpheader.jsp?bridgeEndpoint=true&amp;synchronous=true"/>
            <setHeader headerName="Content-Type" id="_setHeader2">
                <constant>application/json</constant>
            </setHeader>
        </route>

这工作正常,但如果我在路由末尾添加日志记录操作:

    <log id="_log_saypost_after_rest3" message="${body}"/>
  </route>

来自 camel(localhost:9091/say/hellopost) 的响应主体将是空的,记录操作后响应主体被清除的原因是什么?

此致

局域网

一样使用流缓存
<route streamCache="true">

http://camel.apache.org/why-is-my-message-body-empty.html 回答了您的问题。

事实上你不必使用 directy

<log />

但你必须使用

<to uri="log: "/>

https://camel.apache.org/components/3.15.x/log-component.html