camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Camel 1.6.1 - Capturing parsing errors from Validation Component
Date Wed, 25 Nov 2009 15:47:14 GMT

And if you wrote a little unit test you could just add a processor and
use a debugger to check what the Exchange contains of data and find
what you are looking for.

Also you can use the Tracer which also exists for 1.x. it can output
what the Exchange contains at runtime to a log. Then you will find
that caught exception somewhere

On Wed, Nov 25, 2009 at 4:44 PM, Claus Ibsen <> wrote:
> Hi
> Yeah unfortunately the wiki documentation is not divided between 1.6 and 2.x.
> Confluence kinda sucks for that.
> Anyway the the validator wiki page has an example
> However the catch in Camel 1.x does not carry that caught exception.
> That one is avail in 2.0.
> So you cannot use that.
> However the onException has it so you just need to look the right place.
> Its stored in a header with the key
> Exception cause =
> exchange.getIn().getHeader(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER,
> Exception.class);
> And you gotta use handled(true) in this case if you want to handle
> this failure yourself and write a new message to that file:error
> On Wed, Nov 25, 2009 at 4:14 PM, jweathers777 <> wrote:
>> I have a simple pair of routes that look like this:
>> from("file:///input?delete=true").convertBodyTo(String.class).to("direct:validation");
>> from("direct:validation").to("validator:test.xsd").to("file:///output");
>> I've been trying all sorts of ways to trap the SchemaValidationException so
>> that I can extract the parsing errors in an invalid XML file and combine
>> them with the original message into a wrapper message to be routed to
>> another endpoint "file:///error".
>> Among the many ways that I have tried is this one:
>> onException(SchemaValidationException.class).handled(false)
>>   .process(new ErrorBundler()).to("file:///error");
>> Then, in my Processor, I try construct my wrapper message from the passed in
>> exchange, but no matter what I do, the Exception is null and so I cannot
>> access the parse errors.
>> I've tried exchange.getException(), exchange.getFault(), and
>> exchange.getProperty(Exchange.EXCEPTION_HANDLED_PROPERTY, Throwable).
>> All of them have NULL.
>> One very ugly way that I managed to obtain the desired effect was to replace
>> my validation route with this:
>> from("direct:validation").to("validator:test.xsd").process(new
>> HackProcessor());
>> My processor's body uses a Java try catch block to wrap a block of code
>> where I use exchange.getContext().createProducerTemplate() to manually send
>> an exchange to the validator endpoint and then send the successful result to
>> my output file endpoint. In the case where the exception is thrown, I
>> construct my wrapper message and can successfully examine the Exception
>> message and data in order to send my wrapper message on to my error
>> endpoint.
>> While the above "works", it feels like a hack and I suspect that I must be
>> missing something with the normal Camel onException mechanism.
>> --
>> View this message in context:
>> Sent from the Camel - Users mailing list archive at
> --
> Claus Ibsen
> Apache Camel Committer
> Author of Camel in Action:
> Open Source Integration:
> Blog:
> Twitter:

Claus Ibsen
Apache Camel Committer

Author of Camel in Action:
Open Source Integration:

View raw message