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 CFD7B105DA for ; Tue, 2 Dec 2014 12:17:45 +0000 (UTC) Received: (qmail 58756 invoked by uid 500); 2 Dec 2014 12:17:45 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 58714 invoked by uid 500); 2 Dec 2014 12:17:45 -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 58702 invoked by uid 99); 2 Dec 2014 12:17:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Dec 2014 12:17:44 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.223.179 as permitted sender) Received: from [209.85.223.179] (HELO mail-ie0-f179.google.com) (209.85.223.179) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Dec 2014 12:17:20 +0000 Received: by mail-ie0-f179.google.com with SMTP id rp18so11018322iec.24 for ; Tue, 02 Dec 2014 04:16:34 -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; bh=uPnvoG/opQlEHkvWCUrFkUcSP7SzW/AwseQIFTZ9DI0=; b=SpH1dMAsMSK/d1CRenqjvred5e2y2L/ZQ4+O2xpjI/CmrIo2d8OwpAATW5pwvWjkX1 ua+PVdZGNI84Lefl8oWttpy3v6jMdlPWdDu4onNyrTTxsKPlu83thx926URi8X08L8CW 4rvcGGTud8F6J6Ip/ku9e3IG9Ug69naztxNl4saKhR1iVffuonXP/wEfItVR3qV/NU6k DM44znKNcCOBgTMiDhuVdU3WZL2KyYfR/mU33R1i1gtmfTRWPVSGFG2pEB50Npe8gJAS Ez2dbggQgysxUPOR6geEKnOVRvzDYCLGKlIk2jv98/6jUs3IoR+cjgTbg1Ipvv3Vm50H Kujw== X-Received: by 10.107.6.144 with SMTP id f16mr56206794ioi.77.1417522593876; Tue, 02 Dec 2014 04:16:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.126.136 with HTTP; Tue, 2 Dec 2014 04:16:13 -0800 (PST) In-Reply-To: References: <1417440312542-5759864.post@n5.nabble.com> From: Claus Ibsen Date: Tue, 2 Dec 2014 13:16:13 +0100 Message-ID: Subject: Re: Rest DSL - OutType in case of error message problem To: "users@camel.apache.org" Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Hi I logged, and fixed this for next release https://issues.apache.org/jira/browse/CAMEL-8104 On Tue, Dec 2, 2014 at 11:38 AM, Claus Ibsen wrote: > Hi > > Yeah well spotted. We should improve rest-dsl to support these > use-cases where you prepare a response message yourself and set the > http status code to some error code etc. > > I guess if the status code is >= 300+ then we should assume its an > error, and use the message body as-is as the response. > > On Mon, Dec 1, 2014 at 2:25 PM, panzerhans wrote: >> I have a setup with Swagger and the Rest DSL. Swagger uses the >> OutType(MyType.class) to annotate the API with the return type. However, >> there are times when I wish to return something else to the caller, e.g. an >> error message with a HTTP response code. >> >> Take the following Route as an example: >> >> RestDefinition privateAPI = >> rest(ServiceConstants.PRIVATE_API_VERSION_1).description("Private (internal) >> REST services for MyServices."); >> >> privateAPI.get("/fetchsomething").description("Lists stuff from some >> service") >> .outTypeList(MyPojoForSomething.class) >> .route().routeId("A descriptive ID") >> .choice() >> >> .when(header(ServiceConstants.REQUEST_VALIDATED).isEqualTo("TRUE")) >> .bean(GoAheadAndFillAMyPojoForSomething-into-body.class) >> .otherwise().bean(ErrorMessageConstructor.class); >> >> ------- >> >> * An Interceptor validates the incoming message and sets the Header constant >> to TRUE or FALSE. >> * The ErrorMessageConstructor constructs a proper message and puts it as a >> String into the body together with a correct HTTP code (E.g. Not-Found). >> >> Problem: The marshaller, uses outTypeList to determine the way to convert >> the Message body to Json. If in the above example, the request was "FALSE", >> the marshaller (I am using Jackson) tries to marshall a String to a >> MyPojoForSomething.class. >> >> The content of the String I have constructed for the error is in this case: >> "Missing properties in HTTP Header." >> >> This results in an error: >> com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Missing': >> was expecting ('true', 'false' or 'null') >> at [Source: java.io.ByteArrayInputStream@67618968; line: 1, column: 9] >> at >> com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419) >> ........ >> >> >> >> -- >> View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-OutType-in-case-of-error-message-problem-tp5759864.html >> Sent from the Camel - Users mailing list archive at Nabble.com. > > > > -- > 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/ -- 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/