驼峰 HTTP 组件未在交换体中设置响应



我正在使用Camel版本3.2.0和Spring Boot Version 2.2.6.RELEASE。

我正在使用 camel-http 组件来使用一个以 JSON 格式返回产品列表的休息服务。
我正在尝试存储在csv文件中。 由于 http 响应未在 out 中设置交换,因此正文为空。

我正在使用以下路线。

<route id="getProducts">
<from uri="quartz://groupName/timerName?cron=0 0/2 * 1/1 * ? *" />
<setHeader name="CamelHttpMethod">
<constant>GET</constant>
</setHeader>
<to uri="http://localhost:8080/product"></to>
<log message=" before processor n Body ${body} n headers ${headers}"/>
<!-- <process ref="processor" /> -->
<log message=" before convert n Body ${body} n headers ${headers}"/>
<marshal>
<bindy type="Csv"  classType="com.basf.vo.Product"   />
</marshal>
<log message=" after convert n Body ${body}"/>
<to uri="file:balachandar?fileName=abc.csv"/>
<log message="Products Received n ============================= n"/>
</route>

<log message=" before processor n Body ${body} n headers ${headers}"/> => It is printing Body {"productId":1,"name":"Pink Ralph Lauren Polo Shirt","category":"Dress"} in the console
<log message=" before convert n Body ${body} n headers ${headers}"/>  => It is not printing the body. Body is empty.
I used custom processor to know the body.
public void process(Exchange exchange) throws Exception {
String msg = exchange.getIn().getBody(String.class);
String msg1 = exchange.getMessage(String.class);
System.out.println("Rest Response is:->" + msg);   //  Rest Response is:->
System.out.println("Rest Response is:->" + msg1);  //  Rest Response is:->null
}

它是第一次打印正文,但不是通过处理器或日志组件打印后续时间。
我不确定为什么没有在身体中设置响应。 请帮忙。

响应类型为流。当您第一次使用该流时记录响应时,数据已消失。您可以启用流缓存或将流转换为字符串 (<convertBodyTo type="java.lang.String"/>(,然后再对消息正文执行任何其他操作。

使用 exchange.getOut((.getBody(String.class( 获取响应正文。

请参考链接: https://camel.apache.org/components/latest/http-component.html#_message_body

最新更新