You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Muhammad Ichsan <ic...@gmail.com> on 2010/03/09 22:19:05 UTC

Can loop work together with onException?

Dear all

I have a route which is called by <loop> like the following:

<route>
	<from uri="direct:repeatReversal" />
	<to uri="bean:messageUtil?method=markRepeatRequired" />
	<loop>
		<method bean="messageUtil" method="readNumberOfRepeat" />
		<to uri="direct:invoke" />
	</loop>
	<to uri="bean:messageUtil?method=printMsg" />
</route>

<route>
	<from uri="direct:invoke" />

	<onException>
		<exception>my.Exception</exception>
		<handled><constant>true</constant></handled>
   		<to uri="bean:messageUtil?method=markRepeatRequired" />
	</onException>

	<delay>
   		<constant>5000</constant>
	</delay>

	<choice>
		<when>
			<simple>${in.header.repeat} != null</simple>
			<to uri="bean:aBusinessBean?method=invokeWithPossibleMyException" />
			<to uri="bean:messageUtil?method=unmarkRepeatRequired"/>
		</when>
	</choice>
	<to uri="bean:messageUtil?method=printMsg" />
</route>

The problem is, once a MyException arise, the loop stop completely.
How this happened?

Regards

-- 
~The best men are men who benefit to others
http://michsan.web.id

Yang berkualitas memang beda rasanya!
http://rizqi-cookies.com

Re: Can loop work together with onException?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Mar 9, 2010 at 10:19 PM, Muhammad Ichsan <ic...@gmail.com> wrote:
> Dear all
>
> I have a route which is called by <loop> like the following:
>
> <route>
>        <from uri="direct:repeatReversal" />
>        <to uri="bean:messageUtil?method=markRepeatRequired" />
>        <loop>
>                <method bean="messageUtil" method="readNumberOfRepeat" />
>                <to uri="direct:invoke" />
>        </loop>
>        <to uri="bean:messageUtil?method=printMsg" />
> </route>
>
> <route>
>        <from uri="direct:invoke" />
>
>        <onException>
>                <exception>my.Exception</exception>
>                <handled><constant>true</constant></handled>
>                <to uri="bean:messageUtil?method=markRepeatRequired" />
>        </onException>
>
>        <delay>
>                <constant>5000</constant>
>        </delay>
>
>        <choice>
>                <when>
>                        <simple>${in.header.repeat} != null</simple>
>                        <to uri="bean:aBusinessBean?method=invokeWithPossibleMyException" />
>                        <to uri="bean:messageUtil?method=unmarkRepeatRequired"/>
>                </when>
>        </choice>
>        <to uri="bean:messageUtil?method=printMsg" />
> </route>
>
> The problem is, once a MyException arise, the loop stop completely.
> How this happened?
>

onException does *not* work like try .. catch as in regular Java.

You can use doTry .. doCatch for this kind of behavior.

However we have a ticket to consider adding an option to onExeption to
let it "keep running".
https://issues.apache.org/activemq/browse/CAMEL-2253




> Regards
>
> --
> ~The best men are men who benefit to others
> http://michsan.web.id
>
> Yang berkualitas memang beda rasanya!
> http://rizqi-cookies.com
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus