camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: camel-netty4-http access to response
Date Wed, 18 Feb 2015 07:05:00 GMT

Thanks for sharing your solution.

Its a common header in Camel that all the http components (that has a
consumer to act as the HTTP server) uses for allowing to control the
HTTP status code.

We love contributions and ppl is certainly welcome to help any way,
also with docs.

On Wed, Feb 18, 2015 at 3:46 AM, Mark Mindenhall
<> wrote:
> Figured it out; just replying to my own message in case someone else runs into the same
problem (or in case I forget later ;)  ).
> I dug around in the code, and discovered that the HTTP response code can be set via the
CamelHttpResponseCode message header (defined as a constant: Exchange.HTTP_RESPONSE_CODE).
 There’s no mention of that header in the camel-netty-http or camel-netty4-http documentation
(I opened to address that).  So the following
code works to set the response code and message body:
>       exchange.getOut().setBody(myResponseBody);
>       exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 401);
> On Feb 17, 2015, at 11:34 AM, Mark Mindenhall <>
>> I’m using the camel-netty4-http (latest 2.14.2-SNAPSHOT) component to create an
endpoint that receives an HTTP POST from a device, translates the message from binary to JSON,
then sends it along to a kafka topic for further processing.  When there are errors in validating
or translating the incoming message, I need to be able to return a HTTP response code and
response body.
>> The camel-netty4-http documentation has an “Access to Netty types” section, which
says that I should be able to do the following to access the instance of io.netty.handler.codec.http.HttpResponse:
>>     HttpResponse response = exchange.getIn(NettyHttpMessage.class).getHttpResponse();
>> Regardless of where I access the exchange within the route, getHttpResponse() is
always returning null.  On the "happy path” I can return 200 by calling exchange.getOut().setBody(myResponse),
but I have been unable to figure out how to return another response code.
>> Is this a bug?  Or is there another way to accomplish what I’m trying to do?
>> Thanks,
>> Mark

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:

View raw message