Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 51961 invoked from network); 2 Mar 2009 08:56:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Mar 2009 08:56:28 -0000 Received: (qmail 87840 invoked by uid 500); 2 Mar 2009 08:56:27 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 87812 invoked by uid 500); 2 Mar 2009 08:56:27 -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 87801 invoked by uid 99); 2 Mar 2009 08:56:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2009 00:56:27 -0800 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.220.176 as permitted sender) Received: from [209.85.220.176] (HELO mail-fx0-f176.google.com) (209.85.220.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2009 08:56:16 +0000 Received: by fxm24 with SMTP id 24so1831465fxm.20 for ; Mon, 02 Mar 2009 00:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=StmJ367xWjAeE+Ch1EWjKfA3A6o9OtYJe6TchkhQUB0=; b=jytMWsIs/3ara45EwZap4TdK3KcESIOKuIyRguVARiO306od92K2M8tEC7mS+7MyeJ iRmHMwbup5lurvMeZsVn4f6P9Jw3VDn2Jm3FHCx0x4ubbtmOP42nzTXZR9DPxlZPCF/B bE8ol9fM13Sh/ddmNk751ixPDE4T+b8a7eX4Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=A+C94is8aKoJR6XFZ+R7pG5mqph6DaQA8VayGw55DVQ+LbOkcvLJW553f3U9tN01oU bhMRdbTjtzSPP4TC8cjevNDoe1+axDoLjYq3WYOdQa40Bck1mNwR3mtD48co223JV7N3 MsLtfYbG3QGNG5mA8zkAZoufIMrOz5DXaiHGA= MIME-Version: 1.0 Received: by 10.223.118.9 with SMTP id t9mr5722593faq.20.1235984156143; Mon, 02 Mar 2009 00:55:56 -0800 (PST) In-Reply-To: <22283427.post@talk.nabble.com> References: <22249110.post@talk.nabble.com> <22283427.post@talk.nabble.com> Date: Mon, 2 Mar 2009 09:55:56 +0100 Message-ID: <5380c69c0903020055u4092a3acldd23e94d63863768@mail.gmail.com> Subject: Re: Camel Routing based on bean return object From: Claus Ibsen To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On Mon, Mar 2, 2009 at 9:47 AM, ee7arh wrote: > > Hi Markus, > > Thanks for advice. Yes that would work but as you pointed out it's not ideal > since it's then not possible to see where the message will end up just by > reading the Routing definition. I would like to make my RouteBuilder as > readable as possible. > > Does you know whether it's possible to cast the "body()" of a message to > it's base object? > > Perhaps this would work? > > from("jms:queue:queue1").to("bean:myBeanMethod1").choice() > .when(body().convertTo(MyReturnCodeEnum.class).isEqualTo(MyReturnCodeEnum.ERROR_CODE_1)) > .to("jms:queue:error1Queue") > .when(body().convertTo(MyReturnCodeEnum.class).isEqualTo(MyReturnCodeEnum.ERROR_CODE_2)) > .to("jms:queue:error2Queue") > > I assumed in above example that the actual object on the "from" queue is the > MyReturnCodeEnum object now rather than the wrapping object MyReturnObj1 Ah now I got the issue. The predicate being tested using isEqualTo does not automatic convert to same types. I worked on that a bit, but then realized we cant make a safe assumption which side of the operator RIGHT or LEFT should be converter to the other type. How should camel know which types is correct. An example: The left type (= body) can be an Integer with a value of 1. And the left side is the enum with the ERROR_CODE_1 value. The two types are not directly comparable so we need to convert it. But which type is the best? - Integer - Enum In this case it should be enum, but there could be other situations where the predicate should test for reverse. Maybe its possible to add tests for all combinations and return true if there is a match in one of them? So you can do the body stuff you do, but I think there is a shorthand when(body(MyReturnCodeEnum.class).isEqualTo(ERROR_CODE_1) And do a static import of your enum so its shorter to write. > > Thanks > Andrew > > > ee7arh wrote: >> >> Hi, >> >> I'm getting quite into using the Camel DSL router and got quite far but >> now have this situation: >> >> I have a bean method (myBeanMethod1()) which returns not a boolean but a >> real object (MyReturnObj1). This object contains an Enum return code >> (myReturnCode) and I want to do some routing based on this returncode. >> >> e.g. >> >> // Bean Method >> public MyReturnObj1 myBeanMethod1(); >> >> The definition of MyReturnObj1 is >> >> public class MyReturnObj1 { >> >> protected Enum myReturnCode; >> >> } >> >> I want to do some routing like this: >> >> from("jms:queue:queue1").to("bean:myBeanMethod1").choice() >> .when(myErrorCode=myReturnCode.ERRROR1).to("jms:queue:error1Queue") >> .when(myErrorCode=myReturnCode.ERROR2).to("jms:queue:error2Queue") >> .otherwise().to("jms:queue:unknownErrorQueue"); >> >> Is it possible to somehow do routing based on bean which returns an >> object? If I set my "returnCode" into the JMS Header field I could use the >> header() method to get the values as seen in many examples on Camel >> website. >> >> Advice greatly appreciated. >> >> Andrew >> >> > > -- > View this message in context: http://www.nabble.com/Camel-Routing-based-on-bean-return-object-tp22249110p22283427.html > Sent from the Camel - Users (activemq) mailing list archive at Nabble.com. > > -- Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/