// Transform first so that the input source will be parsed only once
// if it is a StreamSource
getMessageTransformer().transform(exchange, in, out);
try {
SourceTransformer sourceTransformer = new SourceTransformer();
// Only DOMSource and SAXSource are allowed for validating
// See http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
// 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();
// set the schema and source document as properties on the fault
fault.setProperty("org.apache.servicemix.schema", schema);
fault.setProperty("org.apache.servicemix.xml", src);
/*
* 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() +