Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 219431787C for ; Wed, 18 Feb 2015 07:05:48 +0000 (UTC) Received: (qmail 15883 invoked by uid 500); 18 Feb 2015 07:05:46 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 15838 invoked by uid 500); 18 Feb 2015 07:05:46 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 15826 invoked by uid 99); 18 Feb 2015 07:05:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2015 07:05:46 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.213.173 as permitted sender) Received: from [209.85.213.173] (HELO mail-ig0-f173.google.com) (209.85.213.173) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2015 07:05:22 +0000 Received: by mail-ig0-f173.google.com with SMTP id a13so34906837igq.0 for ; Tue, 17 Feb 2015 23:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=P6oLeSXIW/DMbzm3BO55/EYo0RsgxgUyCbu4PyTUBYc=; b=eOJuG1cJ3BJLctpelegadX3SCP5qJkvXJ7aKpM3N3drAXsFh81ea6jFWg7HYfOWOo9 fJE1cLAA+gxANKvdSkzp77oxDFLVZUjh76BUDAA0O9izumP71wBjC2TZaeadkv1z57KQ USjc6/hqTk29rqBNjA2ONx4vNxq/A69zNyrxgsQx4gaFbDUtZIrkGUunIXAY84J6TSkA tjOPLadUhi0Nu66JGU2NrXlHp2NOb0yuawb2si33K1c5iMz8yXgzAqHs2tBBK5rjQ70G IO5Ok4bSWP5SaCwiTE8NmVGyXA9R79d73vRkgldG0mdSpiFFMKOh0su25dVdUAX/7Gn3 aytA== X-Received: by 10.107.18.22 with SMTP id a22mr26125155ioj.48.1424243120333; Tue, 17 Feb 2015 23:05:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.149.2 with HTTP; Tue, 17 Feb 2015 23:05:00 -0800 (PST) In-Reply-To: <2326BA57-1A8B-48B9-ABCF-15BC0CAAA60E@machineshop.io> References: <2326BA57-1A8B-48B9-ABCF-15BC0CAAA60E@machineshop.io> From: Claus Ibsen Date: Wed, 18 Feb 2015 08:05:00 +0100 Message-ID: Subject: Re: camel-netty4-http access to response To: "users@camel.apache.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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 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=E2=80=99s no mention of that header i= n the camel-netty-http or camel-netty4-http documentation (I opened https:/= /issues.apache.org/jira/browse/CAMEL-8370 to address that). So the followi= ng 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 wrote: > >> I=E2=80=99m using the camel-netty4-http (latest 2.14.2-SNAPSHOT) compone= nt to create an endpoint that receives an HTTP POST from a device, translat= es the message from binary to JSON, then sends it along to a kafka topic fo= r further processing. When there are errors in validating or translating t= he incoming message, I need to be able to return a HTTP response code and r= esponse body. >> >> The camel-netty4-http documentation has an =E2=80=9CAccess to Netty type= s=E2=80=9D 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 =3D exchange.getIn(NettyHttpMessage.class).get= HttpResponse(); >> >> Regardless of where I access the exchange within the route, getHttpRespo= nse() is always returning null. On the "happy path=E2=80=9D I can return 2= 00 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=E2=80=99m t= rying to do? >> >> Thanks, >> Mark >> > --=20 Claus Ibsen ----------------- Red Hat, Inc. Email: cibsen@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/