Hi 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. http://camel.apache.org/contributing.html On Wed, Feb 18, 2015 at 3:46 AM, Mark Mindenhall <[email protected]> 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 > https://issues.apache.org/jira/browse/CAMEL-8370 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 > <[email protected]> wrote: > >> 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. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/
