Mark Mindenhall created CAMEL-8370:
--------------------------------------
Summary: CamelHttpResponseCode missing from documentation
Key: CAMEL-8370
URL: https://issues.apache.org/jira/browse/CAMEL-8370
Project: Camel
Issue Type: Bug
Components: camel-netty-http, camel-netty4-http
Affects Versions: 2.14.1
Reporter: Mark Mindenhall
Priority: Minor
I sent the following to the [email protected] list earlier today:
{quote}
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?
{quote}
After digging around in the code, it looks like the HTTP status code is set via
the CamelHttpResponseCode message header
(org.apache.camel.component.netty4.http.DefaultNettyHttpBinding, line 308).
However, there is no mention of this message header in either the
camel-netty-http or camel-netty4-http documentation. It would be helpful to
add this header to the list of applicable message headers, and also to include
an example that demonstrates how to set the response status code and body:
Finally, the existing "Access to Netty types" example should be modified to be
clear that only the request can be accessed in this way.
{code}
// specify response body and status
exchange.getOut().setBody(myResponseBody);
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 401);
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)