Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 660
Archer Avatar asked Nov 14 '13 11:11

Archer


People also ask

What is camel SetHeader?

The SetHeader EIP is used for setting a message header.

What is https4?

The http4: component provides HTTP based endpoints for calling external HTTP resources (as a client to call external servers using HTTP).

What is endpoint in Apache Camel?

Camel supports the Message Endpoint pattern using the Endpoint interface. Endpoints are created by a Component and these endpoints are referred to in the DSL via their endpoint URIs.


2 Answers

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
    }
});
like image 141
Kalpak Gadre Avatar answered Sep 22 '22 20:09

Kalpak Gadre


This will help , use this in log message :

${headers}

Or

${in.headers}

This will print any incoming headers .

Checkout here : http://camel.apache.org/simple.html

Example :

like image 22
gnanagurus Avatar answered Sep 22 '22 20:09

gnanagurus