Hi,

I'm currently facing a problem trying to handle an exception thrown in a sub
route invoked from a REST endpoint.

The following route context defines the sub-route:
        <routeContext id="routeContext"
xmlns="http://camel.apache.org/schema/spring";>
                <route id="testInner" errorHandlerRef="noErrorHandler">
                        <from uri="direct:testInner" />
                        <transacted ref="jpaTransactionRequiredPolicy" />
                        <throwException exceptionType="java.lang.Exception" 
message="error" />
                </route>
        </routeContext>

And the following REST context defines the endpoint that invokes the
sub-route via "direct":
        <restContext id="restContext"
xmlns="http://camel.apache.org/schema/spring";>
                <rest path="/test">
                        <post id="testOuter" type="test.CSearchParameter">
                                <route>
                                        <onException>
                                                
<exception>java.lang.Exception</exception>
                                                <handled>
                                                        
<constant>true</constant>
                                                </handled>
                                                <log loggingLevel="ERROR" 
logName="test" message="Exception:
${property.CamelExceptionCaught}" />
                                                <setHeader 
headerName="CamelHttpResponseCode">
                                                        <constant>500</constant>
                                                </setHeader>
                                        </onException>

                                        <log loggingLevel="WARN" logName="test" 
message="Before" />
                                        <to uri="direct:testInner" />
                                        <log loggingLevel="WARN" logName="test" 
message="After" />
                                        <setHeader 
headerName="CamelHttpResponseCode">
                                                <constant>200</constant>
                                        </setHeader>
                                </route>
                        </post>
                </rest>
        </restContext>

Both are included in the same camel context.

What I want to achieve, is that the onException block of the REST endpoint
route "testOuter" handles the exception thrown in the route "testInner".

After invoking the above REST endpoint via SwaggerUI, the log file contains
the line with "Before", followed by an ERROR logged from an
TransactionErrorHandler, followed by a line stating the transaction
rollback.
What I do not see, is the log line beginnging with "Exception:" from the
defined onException handler.

I already tried without the errorHandlerRef="noErrorHandler" on the inner
route, but the result is effectively the same. The ERROR and rollback log
line are written by a DefaultErrorHandler, but still no "Exception:" line
from the defined onException block.


What did I miss? How to handle the sub-route exception in the onException
handler of the REST route?

Btw., I'm currently using Camel 2.17.0, just in case it matters.

Regards
Holger



--
View this message in context: 
http://camel.465427.n5.nabble.com/Exception-handling-with-transactional-sub-routes-tp5787726.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to