Search code examples
javagroovyapache-camel

How to dump HTTP body and headers sent with HTTP component with Apache Camel


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?


Solution

  • 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
        }
    });