Use <onException> instead of try .. catch as that is better. On Wed, Nov 13, 2013 at 2:15 PM, Goyal, Arpit <[email protected]> wrote: > Any idea how can I achieve the following? > > -----Original Message----- > From: Goyal, Arpit [mailto:[email protected]] > Sent: Wednesday, November 13, 2013 9:42 AM > To: [email protected] > Subject: Try-Catch in choice-when > > Hi All, > > I am trying to use Try-Catch inside 'when' but not sure how to get it right. > I am using BLUEPRINT DSL. Following is my route: > > <camel:route> > <camel:from ref="Sender"/> > > <camel:setHeader headerName="MyHeader"> > <camel:constant>GOOD</camel:constant> > </camel:setHeader> > > <camel:choice> > <camel:when> > <camel:doTry> > <camel:xpath>//MessageId = 'a'</camel:xpath> > <camel:to ref="Receiver1"/> > <camel:doCatch> > > <camel:exception>org.apache.camel.builder.xml.InvalidXPathExpression</camel:exception> > <camel:to > uri="log:TryCatchEval?level=INFO"/> > </camel:doCatch> > </camel:doTry> > </camel:when> > <camel:when> > <camel:simple>${header.MyHeader} == 'GOOD'</camel:simple> > <camel:to ref="Receiver_"/> > </camel:when> > <camel:otherwise/> > </camel:choice> > </camel:route> > > Here the prefix camel stands for > xmlns:camel=http://camel.apache.org/schema/blueprint > > Basically the idea which we want to achieve is, in case my first condition > fails (due to some exception), I want to execute the second condition and > have hard restriction that I can't change my pattern of choice-when. > > As per the camel-blueprint xsd > (http://camel.apache.org/schema/blueprint/camel-blueprint-2.11.2.xsd), > whenDefinition expects first element to be some language element and then > allows Try-Catch. What if the language it-self throws exception? How can I > prevent that? > > Regards, > Arpit.
-- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen
