I think the closest test to what you want is at
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java?view=markup
as you say, there is no reference to the exception but it is on the
exchange when it is handled.
adding:
assertTrue("Handled exception available on exchange",
exceptionEndpoint.getExchanges().get(0).getException()
instanceof IllegalArgumentException);
to the end of the testExceptionWithHandler() case will verify that the
exception is accessible.
The EXCEPTION_CAUSE_PROPERTY could/should used to hold the exception
as a property of the exchange while it is begin handled such that
another pipe/route can be used to handle the exception reporting and
it can fail independently.
But it looks like this is not correctly implemented or is not the
intended behaviour. In a test I find that another private property is
used to hold the exception during processing:
In a processor placed in the handier chain for an exception I find
that the following works:
{code}
final Processor exceptionStackTraceHandler = new Processor() {
public void process(Exchange exchange) throws Exception {
assertNull("no ex on exchange in handler",
exchange.getException());
//a public accessor property should be there
//Throwable ex = (Throwable)
exchange.getProperty(DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY);
Throwable ex = (Throwable)
exchange.getProperty("org.apache.camel.processor.DeadLetterChannel.FAILURE_HANDLED");
exchange.getIn().setHeader("my.stackTrace", stackToString(ex));
}
{code}
>From what I understand, the exception handler are another form of
error handler, so if no exception error handler matches, the default
dead letter error handler is in effect.
The exception cause should be easily available through a property,
either the existing public property should be used or the private
property should be made public. I think this warrants a jira.
On 10/03/2008, Magnus Heino <[EMAIL PROTECTED]> wrote:
> Did anyone come up with a working solution for this?
>
> DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY is not used or tested anywhere.
> And even if that was not the case, dead letter channel isn't the same as
> exception() and tryBlock(), right?
>
> I also looked through all the
> org.apache.camel.processor.Validation*Testtests, but none of them
> expose or use the actual exception.
>
> Is this possible? It seems weird to have a xml schema validation component
> if it's impossible to get hold of the actual error message...
>
> /Magnus
>
>
> On Fri, Feb 29, 2008 at 5:39 PM, cmdr <[EMAIL PROTECTED]> wrote:
>
> >
> > Here is an example of code that work as I aspected.:-(
> > Here is an example of code that works as I wanted.
> > I fail to get the exception using setHeader("exception",
> > header("CamelCauseException")).
> > Can you provide a piece of code?
> >
> > When should we use exchange.getIn().setBody() or
> > exchange.getOut().setBody()?
> >
> >
> > public class ExceptionTest extends ContextTestSupport
> > {
> > MockEndpoint endEndpoint;
> >
> > @Override
> > protected void setUp() throws Exception
> > {
> > super.setUp();
> > endEndpoint = getMockEndpoint("mock:end");
> > }
> >
> > @Override
> > protected RouteBuilder createRouteBuilder() throws Exception
> > {
> > return new RouteBuilder()
> > {
> > @Override
> > public void configure() throws Exception
> > {
> > from("direct:start").process
> > ( new Processor()
> > {
> > public void
> > process(Exchange exchange) throws Exception
> > {
> > try
> > {
> > throw new
> > Exception("Test exception");
> > }
> > catch (Exception e)
> > {
> >
> > StringWriter stringWritter = new StringWriter();
> > PrintWriter
> > printWritter = new PrintWriter(stringWritter, true);
> >
> > e.printStackTrace(printWritter);
> >
> > printWritter.flush();
> >
> > stringWritter.flush();
> >
> >
> > exchange.getIn().setBody(stringWritter.toString());
> >
> >
> > template.send("activemq:queue:Exception", exchange);
> > }
> > }
> > }
> > );
> > }
> > };
> > }
> >
> > public void testException() throws InterruptedException
> > {
> > endEndpoint.expectedMessageCount(1);
> >
> > template.sendBody("direct:start", "test Exception");
> >
> > MockEndpoint.assertIsSatisfied(endEndpoint);
> > }
> > }
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/exception-trace-in-message-tp15740418s22882p15762404.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
> >
>
>
>
> --
>
>
> /Magnus Heino
>