Stacktrace from Camel Context onException

David Wadge picture David Wadge · Jan 23, 2012 · Viewed 21.5k times · Source

I'm trying to retrieve the stacktrace from the onException handler in Apache Camel:

   <onException>
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>

            <setHeader headerName="exception">
                <simple>${exception}</simple>
            </setHeader>
   </onException>

However, the above only shows the exception rather than the entire stacktrace.

I understand that Camel stores the caught exception as a property on the Exchange with the key: Exchange.EXCEPTION_CAUGHT, but how can this be retrieved from the camel context routes file ?

Answer

Claus Ibsen picture Claus Ibsen · Jan 23, 2012

Use exception.stacktrace to get the stacktrace. See the variables listed in the table at this page: http://camel.apache.org/simple

<simple>${exception.stacktrace}</simple>

There is also a ${exception.message} to refer to the exception message itself.