| Commit in servicemix/base/src/main/java/org/servicemix/components/validation on MAIN | |||
| ValidateComponent.java | +8 | -3 | 1.5 -> 1.6 |
Fix SM-47 : ValidateComponent tries to validate a StreamSource - which is not allowed Ensure that the StreamSource is only parsed once by transforming the input message first and validating the ouput
servicemix/base/src/main/java/org/servicemix/components/validation
diff -u -r1.5 -r1.6 --- ValidateComponent.java 10 Oct 2005 09:23:33 -0000 1.5 +++ ValidateComponent.java 10 Oct 2005 09:49:18 -0000 1.6 @@ -44,7 +44,7 @@
* and returning a fault if the document does not conform to the schema * otherwise the message is passed on its way. *
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class ValidateComponent extends TransformComponentSupport {
private Schema schema;
@@ -114,12 +114,15 @@
CountingErrorHandler errorHandler = new CountingErrorHandler();
validator.setErrorHandler(errorHandler);
DOMResult result = new DOMResult();
+ // Transform first so that the input source will be parsed only once + // if it is a StreamSource + getMessageTransformer().transform(exchange, in, out);
try {
// 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
- Source src = "" SourceTransformer().toDOMSource(in.getContent());
+ Source src = "" SourceTransformer().toDOMSource(out.getContent());
validator.validate(src, result);
if (errorHandler.hasErrors()) {
Fault fault = exchange.createFault();
@@ -128,7 +131,9 @@
throw new FaultException("Failed to validate against schema: " + schema, exchange, fault);
}
else {
- getMessageTransformer().transform(exchange, in, out);
+ // Retrieve the ouput of the validation + // as it may have been changed by the validator + out.setContent(new DOMSource(result.getNode(), result.getSystemId()));
return true;
}
}
