如何使用 Apache Camel 转储通过 HTTP 组件发送的 HTTP 正文和标头 [英] How to dump HTTP body and headers sent with HTTP component with Apache Camel
本文介绍了如何使用 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
}
});
这篇关于如何使用 Apache Camel 转储通过 HTTP 组件发送的 HTTP 正文和标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文