camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Pokrzywinski <>
Subject Log in- and outbound camel http messages
Date Mon, 27 Oct 2014 08:59:42 GMT

Actually I would like to do a simple thing. Log all incoming and outgoing
HTTP Message to a database. However, even camel seems to be the right
choice, it is not so simple to do it.

I read the documentation, but could not find any simple solution for this.
So far my solution is the following:

Camel routes:

        <to uri="direct:saveResponse" />

    <route customId="true" id="test" streamCache="true"  >
        <from uri="servlet:///test?matchOnUriPrefix=true" />
        <wireTap uri="direct:saveRequest"  copy="true"/>
        <to uri=&quot;;
        &lt;camel:wireTap uri=&quot;direct:saveResponse&quot;
copy=&quot;true&quot; />
        <removeHeaders pattern="*" excludePattern="Content-*"/>

    <route customId="true" id="saveRequest">
        <description>Saves the request message.</description>
        <from uri="direct:saveRequest" />
        <setHeader headerName="messageType">
        <to uri="direct:saveMessage" />

    <route customId="true" id="saveResponse">
        <description>Saves the response message.</description>
        <from uri="direct:saveResponse" />
        <setHeader headerName="messageType">
        <to uri="direct:saveMessage" />

    <route customId="true" id="saveMessage">
        <description>Saves the request as API message in the
        <from uri="direct:saveMessage" />
        <log message="Header request UID: ${header[request_UID]}" />
        <process ref="messageToApiRequestProcessor" />
        <to uri="jpa:com.cubic.cumo.mip.model.ApiMessage" />

The route should log all incoming http requests to the test servlet and
after receiving the answer from save the response.
Of course the response should also be stored on exception. And of course the
camel header must be removed, cause this proxy setup shouldn't polute

The MessageToApiMessage Processor converts the exchange message to the
custom ApiMessage. The appropriate code part:

private ApiMessage createApiRequest(Message message) {
    ApiRequest request = new ApiRequest();

    request.setTimestamp(new Date());



    request.setUrl(message.getHeader(Exchange.HTTP_URL, String.class));
    String urlQuery = message.getHeader(Exchange.HTTP_QUERY, String.class);
    return request;
This works fine. For the response part the code looks like this:

private ApiMessage createApiResponse(Message message) {
    ApiResponse response = new ApiResponse();

    response.setTimestamp(new Date());
    return response;
However, the header Exchange.HTTP_SERVLET_REQUEST does not contain the
response header.

How do I get the HTTP response header?

When does camel transform the message header to the http header?

Is there a more simple approach to log http requests and response?

Different question: How can I get the uri from last endpoint. The
ApiResponse should also contain lastEndpoint column and store f.e. the value
"". How to get this?

Thanks and regards


Sorry, I don't know, how to embed code into this post.

This message is a copy of:

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message