Hi Claus,

Tried two approach but neither of them worked for me (based out of the URL - 
http://camel.apache.org/exception-clause.html) What I need is when the first 
When fails, camel should continue to execute the second When. Could you let me 
know where I am going wrong?

Option 1: Defined the onException clause after the camel:xpath expression. 
Getting exception " OnException[[class 
org.apache.camel.builder.xml.InvalidXPathExpression] -> []] is not configured. "

<camel:route>

<camel:from ref="Sender"/>
<camel:setHeader headerName="MyHeader">
<camel:constant>GOOD</camel:constant>
</camel:setHeader>
<camel:choice>

<camel:when>
<camel:xpath>//MessageId = 'a'</camel:xpath>

<camel:onException>
<camel:exception>org.apache.camel.builder.xml.InvalidXPathExpression</camel:exception>
<camel:continued><camel:constant>true</camel:constant></camel:continued>
</camel:onException>

<camel:to ref="Receiver1_"/>
</camel:when>

<camel:when>
<camel:simple>${header.MyHeader} == 'GOOD'</camel:simple>
<camel:to ref="Receiver_"/>
</camel:when>

<camel:otherwise/>

</camel:choice>
</camel:route>

Option 2: Define the onException clause inside the camel context. Here two it 
doesn't work. After exception occurs, the processing stops successfully. 
Instead I need the second condition to be evaluated.

<camel:camelContext id="TryCatchEval">
<camel:onException>
        
<camel:exception>org.apache.camel.builder.xml.InvalidXPathExpression</camel:exception>
        <camel:continued><camel:constant>true</camel:constant></camel:continued>
</camel:onException>

<camel:route>

<camel:from ref="Sender"/>

<camel:setHeader headerName="MyHeader">
<camel:constant>GOOD</camel:constant>
</camel:setHeader>

<camel:choice>

<camel:when>
<camel:xpath>//MessageId = 'a'</camel:xpath>
<camel:to ref="Receiver1_"/>
</camel:when>

<camel:when>
<camel:simple>${header.MyHeader} == 'GOOD'</camel:simple>
<camel:to ref="Receiver_"/>
</camel:when>

<camel:otherwise/>

</camel:choice>

</camel:route>
</camel:camelContext>

Regards,
Arpit
-----Original Message-----
From: Claus Ibsen [mailto:claus.ib...@gmail.com] 
Sent: Thursday, November 14, 2013 2:58 PM
To: users@camel.apache.org
Subject: Re: Try-Catch in choice-when

Use <onException> instead of try .. catch as that is better.

On Wed, Nov 13, 2013 at 2:15 PM, Goyal, Arpit <arpit.go...@sap.com> wrote:
> Any idea how can I achieve the following?
>
> -----Original Message-----
> From: Goyal, Arpit [mailto:arpit.go...@sap.com]
> Sent: Wednesday, November 13, 2013 9:42 AM
> To: users@camel.apache.org
> 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: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to