Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel HTTP display request and response

I am using Apache Camel to load data from CSV file to a webservice. Is there anyway I can display request and response. Below is the route configuration..

I split and aggregate 100 items from array to be sent as POST body.

from(fileLocation)
.unmarshal().csv().bean(new CSVConverter(), "process")

.split(body())
.aggregate(constant(true), new GroupedBodyAggregationStrategy())
.completionSize(100)
.completionTimeout(1000)
.marshal().json(JsonLibrary.Jackson)

.setHeader("Authorization", simple(apiKEY))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.HTTP_URI, simple(apiURL))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("https://serivceurl.com/abc");

Please let me know how can I display request and response with above route?

like image 509
user1637487 Avatar asked Oct 19 '25 02:10

user1637487


2 Answers

You can use camel log component to log headers; properties and body

ex:

.to("log:DEBUG?showBody=true&showHeaders=true")
.to("https://serivceurl.com/abc");
.to("log:DEBUG?showBody=true&showHeaders=true")

For more options pl refer: https://camel.apache.org/log.html

If you are planning to use CXF to invoke web service, out of the box logging feature can be used as below,

<cxf:bus>
  <cxf:features>
    <cxf:logging/>
  </cxf:features>
</cxf:bus>
like image 156
Gnana Guru Avatar answered Oct 22 '25 05:10

Gnana Guru


If you take a look into the org.apache.camel.component.http.HttpProducer class you'll see that there is some logging implemented.

        try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing http {} method: {}", method.getName(), method.getURI());
        }
        int responseCode = executeMethod(method);
        LOG.debug("Http responseCode: {}", responseCode);

So if you configure your logging framework (like logback) to the correct LoggingLevel you'll see what the HTTP-Component exactly does. If you want to log it yourself you can try with the log component or the log dsl like mentioned in the other answer.

like image 32
the hand of NOD Avatar answered Oct 22 '25 04:10

the hand of NOD