如何使用 Apache Camel 转储与 HTTP 组件一起发送的 HTTP 正文和标头
如何使用此路由转储 Apache Camel HTTP 组件发送的 HTTP 正文和标头:
How to dump HTTP body and headers sent with Apache Camel HTTP component using this route:
from('direct:abc').
setHeader(Exchange.HTTP_URI, constant("${config.gnutch.solr.coreUrl}/select")).
setHeader(Exchange.HTTP_QUERY, constant("q=${q}&wt=xml")).
setHeader(Exchange.CONTENT_TYPE, constant('application/xml')).
setHeader(Exchange.HTTP_METHOD, constant('GET')).
setBody(constant(null)).
to("http://null")
这是 groovy 中的 Camel DSL 代码.这可能吗?
This is Camel DSL code in groovy. Is that possible?
推荐答案
你有没有尝试过类似的方法
Have you tried something like
from("direct:abc")
.to("http://domain.com/")
.to("log:DEBUG?showBody=true&showHeaders=true")
HTTP 组件文档 建议您可以提取 HttpServletRequest
来自交流之类的,
Also the HTTP Component Documentation suggests that you can extract the HttpServletRequest
from the exchange like,
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
你也可以这样做,
from("direct:abc").to("http://domain.com").process(new Processor() {
public void process(Exchange exchange) throws Exception {
HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
// Log request parameters
}
});
相关文章