// As we expect a DOMResult as output, we must ensure that the input is a
// DOMSource
DOMSource src = sourceTransformer.toDOMSource(out.getContent());
doValidation(validator,src,result);
if (errorHandler.hasErrors()) {
Fault fault = exchange.createFault();
// Dont set the schema and source document as properties on the fault
// because they are not serializable
//fault.setProperty("org.apache.servicemix.xml", src);
// Dont set the schema because it contains an instance of
// com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaImpl that
// is not serializable
//fault.setProperty("org.apache.servicemix.schema", schema);
/*
* check if this error handler supports the capturing of
* error messages.
*/
if (errorHandler.capturesMessages()) {
/*
* In descending order of preference select a format to use. If
* neither DOMSource, StringSource or String are supported throw
* a messaging exception.
*/
if (errorHandler.supportsMessageFormat(DOMSource.class)) {
fault.setContent(
(DOMSource)errorHandler.getMessagesAs(DOMSource.class));
} else if (errorHandler.supportsMessageFormat(StringSource.class)) {
fault.setContent(sourceTransformer.toDOMSource(
(StringSource)errorHandler.getMessagesAs(StringSource.class)));
} else if (errorHandler.supportsMessageFormat(String.class)) {
fault.setContent(
sourceTransformer.toDOMSource(
new StringSource(
(String)errorHandler.getMessagesAs(String.class))));
} else {
throw new MessagingException("MessageAwareErrorHandler implementation " +
errorHandler.getClass().getName() +
" does not support a compatible error message format.");
}
} else {
/*
* we can't do much here if the ErrorHandler implementation does
* not support capturing messages
*/
fault.setContent(new DOMSource(result.getNode(), result.getSystemId()));
}
if (!handlingErrorMethod.equalsIgnoreCase(FAULT_FLOW)) {
// HANDLE AS JBI FAULT
throw new FaultException("Failed to validate against schema: " + schema, exchange, fault);
} else {