If route threw exception and handled is set to true, only first processor in doFinally is executed

2.9k views Asked by At

I've got a Camel Blueprint definition with two Camel contexts containing one route each.

First contexts route is invoked and in turn calls the route of the second context. Now if in the second route an Exception is thrown and the onException sets handled=true, in the first routes doFinally block only the first processor is invoked.

Here is my Blueprint definition:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:camel="http://camel.apache.org/schema/blueprint"
          xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
      http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="myException" class="java.lang.RuntimeException">
        <argument value="Booom" />
    </bean>

    <camelContext id="firstContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="firstRoute">
            <from uri="direct-vm:start"/>
            <doTry>
                <to uri="log:FIRST_TRY"/>
                <to uri="direct-vm:generateException"/>
                <to uri="log:SECOND_TRY"/>
                <doFinally>
                    <to uri="log:FIRST_FINALLY"/>
                    <to uri="log:SECOND_FINALLY"/>
                </doFinally>
            </doTry>
            <log message="The message contains ${body}"/>
            <to uri="mock:result"/>
        </route>
    </camelContext>

    <camelContext id="secondContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <onException>
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>
        </onException>
        <route id="secondRoute">
            <from uri="direct-vm:generateException"/>
            <throwException ref="myException"/>
        </route>
    </camelContext>

</blueprint>

Only the <to uri="log:FIRST_FINALLY"/> gets printed out. I cannot see the <to uri="log:SECOND_FINALLY"/>. Am I missing something here? Any help is appreciated.

I am using Camel 2.10.6 inside Apache Servicemix 4.5.2.

Regards Dominik

1

There are 1 answers

0
Henryk Konsek On BEST ANSWER

You can consider using multicast [1] as a workaround for this issue.

<doFinally>
  <multicast>
    <to uri="log:FIRST_FINALLY"/>
    <to uri="log:SECOND_FINALLY"/>
  </multicast>
</doFinally>

This is not the same as pipeline processing of course, but in some cases doFinally block can just send two messages independently.

[1] http://camel.apache.org/multicast