camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jweathers777 <johnweath...@gmail.com>
Subject Camel 1.6.1 - Capturing parsing errors from Validation Component
Date Wed, 25 Nov 2009 15:14:29 GMT

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: http://old.nabble.com/Camel-1.6.1---Capturing-parsing-errors-from-Validation-Component-tp26514451p26514451.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message