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 735514A3F for ; Thu, 2 Jun 2011 13:12:49 +0000 (UTC) Received: (qmail 87184 invoked by uid 500); 2 Jun 2011 13:12:49 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 87155 invoked by uid 500); 2 Jun 2011 13:12:49 -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 87147 invoked by uid 99); 2 Jun 2011 13:12:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 13:12:49 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.160.45 as permitted sender) Received: from [209.85.160.45] (HELO mail-pw0-f45.google.com) (209.85.160.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 13:12:44 +0000 Received: by pwi6 with SMTP id 6so579904pwi.32 for ; Thu, 02 Jun 2011 06:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=gUPXXE/Ld29VV1vTUYInr9i1N7Cl15BqKSfpuspqu78=; b=uwVIYobxfJJYXoBzNja6rvVEORvPx7xeKkx/yxB4uvb+n3HUAoipkZOZcOjlD9slDh QQjpYCnbjwZ6DJrtpnol6oI2h3YR37nhQbLp0KjExD+Wy9J6T5J3plw7OVwyoYdzhi6B 3puKF2EswPifGD3z3nMcy1UY4ChamFsLjhsBU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=f8T/b8rrq1J7yA30ekgUZW560dC/5BhHXNzbcFfh053/8c+4AL95hduyxZ5qJTb97I YvoqaL/omP/cLaCTZFbEk0Q/4IqE6UdIl9hpDeWQpYeZLD/VSRB1IDepdbG9b3ZO5ujH OSncxDwO+Y+HSgc0uoUmNFraAP2bwLqecsKuQ= Received: by 10.68.28.137 with SMTP id b9mr230932pbh.191.1307020344186; Thu, 02 Jun 2011 06:12:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.66.35 with HTTP; Thu, 2 Jun 2011 06:12:04 -0700 (PDT) In-Reply-To: <4DDF70E0.7000202@yp5.be> References: <4DDF70E0.7000202@yp5.be> From: Claus Ibsen Date: Thu, 2 Jun 2011 15:12:04 +0200 Message-ID: Subject: Re: CXFRS custom response To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi I have created a ticket to track this https://issues.apache.org/jira/browse/CAMEL-4039 On Fri, May 27, 2011 at 11:37 AM, Bruno Dusausoy wr= ote: > Hi, > > As previously stated[1] I'm creating a RESTful webservice, defined by thi= s : > > public class RestComputationService implements ComputationService { > > =A0 =A0@POST > =A0 =A0@Path("/computation") > =A0 =A0@Consumes("text/xml") > =A0 =A0@Produces("text/xml") > =A0 =A0@Override > =A0 =A0public Response compute(Request request) { > =A0 =A0 =A0 =A0return null; > =A0 =A0} > } > > Request and Response are quite misleading, they are *not* the one found i= n > the JAXRS package, they are generated from a schema. > > I'd like to handle an exception like I would in CXF, that is something li= ke > this : > > Category cat =3D (Category) getCategoryDAO().getCategory(id); > =A0if (cat =3D=3D null) { > =A0 =A0ResponseBuilder builder =3D > =A0 =A0Response.status(Status.BAD_REQUEST); > =A0 =A0builder.type("application/xml"); > =A0 =A0builder.entity("Category Not Found"); > =A0 =A0throw new WebApplicationException(builder.build()); > =A0} > > I've read in "Camel in Action" that a possible way to do this is to use > something similar to this : > > public class FailureResponseProcessor implements Processor { > =A0public void process(Exchange exchange) throws Exception { > =A0 =A0String body =3D exchange.getIn().getBody(String.class); > =A0 =A0Exception e =3D exchange.getProperty(Exchange.EXCEPTION_CAUGHT, > Exception.class); > =A0 =A0StringBuilder sb =3D new StringBuilder(); > =A0 =A0sb.append("ERROR: "); > =A0 =A0sb.append(e.getMessage()); > =A0 =A0sb.append("\nBODY: "); > =A0 =A0sb.append(body); > =A0 =A0exchange.getIn().setBody(sb.toString()); > =A0} > } > > But if I do this with my CXFRS webservice, I get a CamelExecutionExceptio= n > caused by a InvalidPayloadException caused itself by a > NoTypeConversionAvailableException. > Indeed, what I put in the body (that is, a String) cannot be transformed = to > an object of type Response by JAXB. > > So, question, how can I return a custom response ? > Can I bypass JAXB and directly access the CXF rsServer in order to respon= d > to the client and tell Camel that it doesn't have to do anything else - i= n > other words, telling Camel its work is finished for this request ? > Am I doing right or is my design completely flawed ? > > Regards. > [1] > http://camel.465427.n5.nabble.com/CXFRS-and-XML-validation-td4428899.html > -- > Bruno Dusausoy > YP5 Software > -- > Pensez environnement : limitez l'impression de ce mail. > Please don't print this e-mail unless you really need to. > --=20 Claus Ibsen ----------------- FuseSource Email: cibsen@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/