Apache Camel HTTP display request and response

点点圈 提交于 2019-12-24 05:53:43

问题


I am using Apache Camel to load data from CSV file to a webservice. Is there anyway I can display request and response. Below is the route configuration..

I split and aggregate 100 items from array to be sent as POST body.

from(fileLocation)
.unmarshal().csv().bean(new CSVConverter(), "process")

.split(body())
.aggregate(constant(true), new GroupedBodyAggregationStrategy())
.completionSize(100)
.completionTimeout(1000)
.marshal().json(JsonLibrary.Jackson)

.setHeader("Authorization", simple(apiKEY))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.HTTP_URI, simple(apiURL))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("https://serivceurl.com/abc");

Please let me know how can I display request and response with above route?


回答1:


You can use camel log component to log headers; properties and body

ex:

.to("log:DEBUG?showBody=true&showHeaders=true")
.to("https://serivceurl.com/abc");
.to("log:DEBUG?showBody=true&showHeaders=true")

For more options pl refer: https://camel.apache.org/log.html

If you are planning to use CXF to invoke web service, out of the box logging feature can be used as below,

<cxf:bus>
  <cxf:features>
    <cxf:logging/>
  </cxf:features>
</cxf:bus>


来源:https://stackoverflow.com/questions/39651918/apache-camel-http-display-request-and-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!