Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用ApacheCamel转储HTTP组件发送的HTTP正文和标头_Java_Groovy_Apache Camel - Fatal编程技术网

Java 如何使用ApacheCamel转储HTTP组件发送的HTTP正文和标头

Java 如何使用ApacheCamel转储HTTP组件发送的HTTP正文和标头,java,groovy,apache-camel,Java,Groovy,Apache Camel,如何使用此路由转储与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_TYP

如何使用此路由转储与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中的骆驼DSL代码。可能吗?

你试过类似的方法吗

from("direct:abc")
 .to("http://domain.com/")
 .to("log:DEBUG?showBody=true&showHeaders=true")
还建议您可以从exchange中提取
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
    }
});

尝试使用一个HttpClient记录器记录标题和内容

如(本例中为3.x版)所述

我正在使用具有以下名称的记录器:

  • httpclient.wire
  • org.apache.commons.httpclient.HttpConnection
这给了我如下输出:

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.
o.a.c.httpclient.HttpConnection-打开到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->“路径:http://0.0.0.0:65432/some/other/path[\r][\n]“
httpclient.wire.header->“用户代理:雅加达公用httpclient/3.1[\r][\n]”
httpclient.wire.header->“主机:0.0.0.0:12454[\r][\n]”
httpclient.wire.header->“内容长度:117[\r][\n]”
httpclient.wire.header->“[\r][\n]”
httpclient.wire.content->“{”a:“afeaafe”,“b:{”c:“53413”},“d:{”e:“vSegefawawr”}”

httpclient.wire.header-这将有所帮助,请在日志消息中使用此选项:

${headers}

${in.headers}

这将打印任何传入的标题

在此处签出:


示例:

第一个解决方案不打印请求正文。第二种解决方案似乎提供了这种能力,但这不应该是处理器,而是类型转换器。我将修复您的回复并接受它。在上述情况下如何读取HttpServletResponse头和正文,因为HttpServletResponse类没有getInputStream()方法。