Skip to content
Permalink
Browse files
[CXF-5365] Part 1: if woodstox cannot process the schemas, fallback t…
…o slower method.

Part 2: If element doesn't have XOP elements, still validate.

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1536860 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Oct 29, 2013
1 parent d48dd90 commit 79f8fca14a252eb9688693b4b4a06de59dccab3d
Showing 1 changed file with 20 additions and 10 deletions.
@@ -23,6 +23,7 @@
import java.io.OutputStream;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.activation.DataSource;
@@ -225,7 +226,18 @@ private Element validate(XMLStreamReader input) throws XMLStreamException, IOExc
}

WoodstoxValidationImpl impl = new WoodstoxValidationImpl();
if (impl.canValidate()) {
XMLStreamWriter nullWriter = null;
boolean canValidate = impl.canValidate();
if (canValidate) {
nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
try {
impl.setupValidation(nullWriter, message.getExchange().getService().getServiceInfos().get(0));
} catch (Throwable t) {
LOG.log(Level.FINE, "Trouble setting up validation.", t);
canValidate = false;
}
}
if (canValidate) {
//Can use the MSV libs and woodstox to handle the schema validation during
//parsing and processing. Much faster and single traversal
//filter xop node
@@ -234,15 +246,13 @@ private Element validate(XMLStreamReader input) throws XMLStreamException, IOExc
StaxUtils.createFilteredReader(reader,
new StaxStreamFilter(new QName[] {XOP}));

XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());

impl.setupValidation(nullWriter, message.getExchange().getService().getServiceInfos().get(0));
StaxUtils.copy(filteredReader, nullWriter);
} else {
//MSV not available, use a slower method of cloning the data, replace the xop's, validate
LOG.fine("NO_MSV_AVAILABLE");
Element newElement = rootElement;
if (DOMUtils.hasElementWithName(rootElement, "http://www.w3.org/2004/08/xop/include", "Include")) {
Element newElement = (Element)rootElement.cloneNode(true);
newElement = (Element)rootElement.cloneNode(true);
List<Element> elems = DOMUtils.findAllElementsByTagNameNS(newElement,
"http://www.w3.org/2004/08/xop/include",
"Include");
@@ -253,11 +263,11 @@ private Element validate(XMLStreamReader input) throws XMLStreamException, IOExc
//set the fake base64Binary to validate instead of reading the attachment from message
parentNode.setTextContent(javax.xml.bind.DatatypeConverter.printBase64Binary(cid.getBytes()));
}
try {
schema.newValidator().validate(new DOMSource(newElement));
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
try {
schema.newValidator().validate(new DOMSource(newElement));
} catch (SAXException e) {
throw new XMLStreamException(e);
}
}
return rootElement;

0 comments on commit 79f8fca

Please sign in to comment.