【发布时间】:2020-08-30 13:08:48
【问题描述】:
我正在使用 Camel 版本 3.2.0 和 Spring Boot 版本 2.2.6.RELEASE 。
我正在使用 camel-http 组件来使用一个以 JSON 格式返回产品列表的休息服务。
我正在尝试存储在 csv 文件中。因为在out里没有设置http响应,所以body是空的。
我正在使用以下路线。
<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
}
它是第一次打印正文,但不是后续时间通过处理器或日志组件。
我不确定为什么没有在正文中设置响应。请帮忙。
【问题讨论】:
标签: spring-boot apache-camel spring-camel