HTTP组件发送的HTTP正文和头文件

HTTP组件发送的HTTP正文和头文件

本文介绍了如何使用Apache Camel转储HTTP组件发送的HTTP正文和头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用此路由转储使用Apache Camel HTTP组件发送的HTTP正文和头文件: $(b
$ b

  from('direct:abc )。 
setHeader(Exchange.HTTP_URI,常量($ {config.gnutch.solr.coreUrl} / select))。
setHeader(Exchange.HTTP_QUERY,常量(q = $ {q}& wt = xml))。
setHeader(Exchange.CONTENT_TYPE,常量('application / xml'))。
setHeader(Exchange.HTTP_METHOD,常量('GET'))。
setBody(常量(空))。
到(http:// null)

这是常规的Camel DSL代码。这是可能的吗?

解决方案

您是否尝试过类似于

<$ p $ (direct:abc)
.to(http://domain.com/)
.to(log:DEBUG?showBody = true& showHeaders = true)

另外建议您可以从交换机中提取 HttpServletRequest ,例如

  HttpServletRequest request = exchange.getIn()。getBody(HttpServletRequest.class); 

然后你可以做,

<$ p (direct:abc).to(http://domain.com).process(new Processor(){
public void process(Exchange exchange)throws异常{
HttpServletRequest请求= exchange.getIn()。getBody(HttpServletRequest.class);
//日志请求参数
}
});


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")

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")

Also the HTTP Component Documentation suggests that you can extract the HttpServletRequest from the exchange like,

HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);

You can then alternatively do,

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正文和头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:48