Author: dkulp
Date: Tue Oct 29 19:33:19 2013
New Revision: 1536860
URL: http://svn.apache.org/r1536860
Log:
[CXF-5365] Part 1: if woodstox cannot process the schemas, fallback to slower
method.
Part 2: If element doesn't have XOP elements, still validate.
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=1536860&r1=1536859&r2=1536860&view=diff
==============================================================================
---
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
(original)
+++
cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
Tue Oct 29 19:33:19 2013
@@ -23,6 +23,7 @@ import java.io.InputStream;
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 @@ public class XMLStreamDataReader impleme
}
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 @@ public class XMLStreamDataReader impleme
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 @@ public class XMLStreamDataReader impleme
//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;