首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在为主体写入日志后,响应体为空

在为主体写入日志后,响应体为空
EN

Stack Overflow用户
提问于 2018-04-02 09:06:17
回答 2查看 346关注 0票数 0

我正在spring上测试fuse63的rest服务,我需要为后端系统代理camel上的rest服务,下面是摘录:

代码语言:javascript
复制
 <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>

这很好,但是如果我在路由的末尾添加日志记录操作:

代码语言:javascript
复制
    <log id="_log_saypost_after_rest3" message="${body}"/>
  </route>

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

诚挚的问候

局域网

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-02 11:14:30

使用流缓存,如

代码语言:javascript
复制
<route streamCache="true">

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

票数 1
EN

Stack Overflow用户

发布于 2022-02-25 14:44:50

事实上,你不必使用directy

代码语言:javascript
复制
<log />

但你得用

代码语言:javascript
复制
<to uri="log: "/>

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49608347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档