You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vlad <vl...@gmail.com> on 2015/12/21 14:50:52 UTC

Camel onException behavior with Splitter

Hi!
I have a strange behavior with the onException block.

If I set handled to false, then the SOME MESSAGE log isn't printed, but if I
change the handled value to true - everything is logged. Could someone
please explain what's happening? As far as I understand the log should be
printed in both cases.

/<camelContext ..>
    <onException>
        <exception>java.lang.Exception</exception>
        <handled>
            <constant>false</constant>
        </handled>
        <log message="SOME MESSAGE"/>
    </onException> 

    <route>
        <from uri="timer://foo?repeatCount=1"/>

        
        <to uri="bean:utils?method=setBody"/>

        <split shareUnitOfWork="true" stopOnException="true">
            <simple>${body}</simple>

            <to uri="direct:handleSplit"/>
        </split>
    </route>

    <route>
        <from uri="direct:handleSplit"/>
        <throwException ref="myException"/>
    </route>   
</camelContext>/



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-onException-behavior-with-Splitter-tp5775324.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel onException behavior with Splitter

Posted by vlad <vl...@gmail.com>.
Hi Sundar,

I appreciate your answer, but I'm afraid it's not the case. 

According to the Apache Camel documentation, "handled" option only defines
if the exception should be propagated out of the current error handler. But
the error handler body still should be executed (in my example - the /<log
message="SOME MESSAGE"/>/ must be executed regardless of the handled value).

As for my example, I suspect that the Splitter's /shareUnitOfWork="true"/
somehow corrupts the exchange and it's not being properly handled in case of
some exception. If you remove this /shareUnitOfWork/ option then the SOME
MESSAGE is being printed regardless of the handled value.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-onException-behavior-with-Splitter-tp5775324p5775368.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel onException behavior with Splitter

Posted by Sundar Moorthy <su...@gmail.com>.
Once the exception is caught and see's a handled(true) , it tells camel not
to propagate the error back to the handler but that it will be handled  ,
in this case  it is handled as you have specified by logging the message
SOME MESSAGE . Now if you wanted to check the exception and send a custom
message you can do that here by converting the message. You can add this to
the log ${exception} and you can see the actual message printed.

Once the handled is turned to false , the message is propagated back to the
handler and that is why you see the complete message being printed.

Regards
Sundar M R

On Mon, Dec 21, 2015 at 8:50 AM, vlad <vl...@gmail.com> wrote:

> Hi!
> I have a strange behavior with the onException block.
>
> If I set handled to false, then the SOME MESSAGE log isn't printed, but if
> I
> change the handled value to true - everything is logged. Could someone
> please explain what's happening? As far as I understand the log should be
> printed in both cases.
>
> /<camelContext ..>
>     <onException>
>         <exception>java.lang.Exception</exception>
>         <handled>
>             <constant>false</constant>
>         </handled>
>         <log message="SOME MESSAGE"/>
>     </onException>
>
>     <route>
>         <from uri="timer://foo?repeatCount=1"/>
>
>
>         <to uri="bean:utils?method=setBody"/>
>
>         <split shareUnitOfWork="true" stopOnException="true">
>             <simple>${body}</simple>
>
>             <to uri="direct:handleSplit"/>
>         </split>
>     </route>
>
>     <route>
>         <from uri="direct:handleSplit"/>
>         <throwException ref="myException"/>
>     </route>
> </camelContext>/
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-onException-behavior-with-Splitter-tp5775324.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Sundar M R