jbossfuse

response body is empty after write log for body


I am testing fuse63 on spring dsl for rest service, I need to proxy a rest service on camel for back end system, here is excerpt:

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

This works fine, but if I add the logging action at the end of the route:

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

the response body from camel(localhost:9091/say/hellopost) will be empty, What's the reason for the response body being cleared after a logging action?

Best regards

Lan


Solution

  • Use Stream caching like

    <route streamCache="true">
    

    This http://camel.apache.org/why-is-my-message-body-empty.html answers to your question.