如何使用此路由转储使用Apache Camel HTTP组件发送的HTTP正文和标头:
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代码。这可能吗?
答案 0 :(得分:8)
你有没有试过像
这样的东西from("direct:abc")
.to("http://domain.com/")
.to("log:DEBUG?showBody=true&showHeaders=true")
此外,HTTP Component Documentation表示您可以从交换中提取HttpServletRequest
,例如
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
}
});
答案 1 :(得分:5)
答案 2 :(得分:4)
尝试使用HttpClient记录器之一记录标题和内容。
在Logging Practices(本例中为3.x版)中描述了。
我正在使用名称为
的记录器这给我的输出如下:
o.a.c.httpclient.HttpConnection - Open connection to 0.0.0.0:12454
httpclient.wire.header - >> "POST /some/path HTTP/1.1[\r][\n]"
httpclient.wire.header - >> "breadcrumbId: ID-localhost-55077[\r][\n]"
httpclient.wire.header - >> "path: http://0.0.0.0:65432/some/other/path[\r][\n]"
httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
httpclient.wire.header - >> "Host: 0.0.0.0:12454[\r][\n]"
httpclient.wire.header - >> "Content-Length: 117[\r][\n]"
httpclient.wire.header - >> "[\r][\n]"
httpclient.wire.content - >> "{"a":"afeaafe","b":{"c":"53413"},"d":{"e":"vsegefawawewr"}}"
httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
httpclient.wire.header - << "Date: Fri, 08 Apr 2016 07:24:24 GMT[\r][\n]"
httpclient.wire.header - << "Content-Type: application/octet-stream[\r][\n]"
httpclient.wire.header - << "Date: Fri, 08 Apr 2016 07:24:24 GMT[\r][\n]"
httpclient.wire.header - << "Content-Length: 7[\r][\n]"
httpclient.wire.header - << "Server: Jetty(9.2.10.v20150310)[\r][\n]"
httpclient.wire.header - << "[\r][\n]"
httpclient.wire.content - << "Success"
o.a.c.httpclient.HttpConnection - Releasing connection back to connection manager.