cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1519782 - in /cxf/trunk/core/src/main/java/org/apache/cxf: databinding/source/Messages.properties databinding/source/XMLStreamDataReader.java helpers/DOMUtils.java
Date Tue, 03 Sep 2013 18:21:36 GMT
Author: dkulp
Date: Tue Sep  3 18:21:35 2013
New Revision: 1519782

URL: http://svn.apache.org/r1519782
Log:
[CXF-5169] If MSV is not available, drop down to the much slower method Jim originally had.
(no MSV OSGi bundles available yet)

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
    cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
    cxf/trunk/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties?rev=1519782&r1=1519781&r2=1519782&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties Tue
Sep  3 18:21:35 2013
@@ -22,4 +22,4 @@ COULD_NOT_READ_XML_STREAM = Could not pa
 COULD_NOT_WRITE_XML_STREAM = Could not generate the XML stream.
 COULD_NOT_READ_XML_STREAM_CAUSED_BY = Could not parse the XML stream caused by: {0}: {1}.
 COULD_NOT_WRITE_XML_STREAM_CAUSED_BY = Could not generate the XML stream caused by: {0}:
{1}.
-COULD_NOT_VALIDATE_XML_STREAM = Failed to initialize MSV validator and validate the XMLStream
+NO_MSV_AVAILABLE = Failed to initialize MSV validator, using slower validation routing.

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=1519782&r1=1519781&r2=1519782&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 Sep  3 18:21:35 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.activation.DataSource;
@@ -37,11 +38,15 @@ import javax.xml.validation.Schema;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxInEndingInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
@@ -210,7 +215,7 @@ public class XMLStreamDataReader impleme
         return input;
     }
 
-    private Element validate(XMLStreamReader input) throws XMLStreamException {
+    private Element validate(XMLStreamReader input) throws XMLStreamException, IOException
{
         DOMSource ds = read(input);
         Element rootElement = null;
         if (ds.getNode() instanceof Document) {
@@ -219,20 +224,41 @@ public class XMLStreamDataReader impleme
             rootElement = (Element)ds.getNode();
         }
 
-        //filter xop node
-        XMLStreamReader reader = StaxUtils.createXMLStreamReader(ds);
-        XMLStreamReader filteredReader = 
-            StaxUtils.createFilteredReader(reader, 
-                                           new StaxStreamFilter(new QName[] {XOP}));
-        
-        XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
-        //TODO: expensive to create WoodstoxValidationImpl ?
         WoodstoxValidationImpl impl = new WoodstoxValidationImpl();
         if (impl.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
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(ds);
+            XMLStreamReader filteredReader = 
+                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 {
-            throw new Fault("COULD_NOT_VALIDATE_XML_STREAM", LOG);
+            //MSV not available, use a slower method of cloning the data, replace the xop's,
validate
+            LOG.fine("NO_MSV_AVAILABLE");
+            if (DOMUtils.hasElementWithName(rootElement, "http://www.w3.org/2004/08/xop/include",
"Include")) {
+                Element newElement = (Element)rootElement.cloneNode(true);
+                List<Element> elems = DOMUtils.findAllElementsByTagNameNS(newElement,

+                                                                          "http://www.w3.org/2004/08/xop/include",
+                                                                          "Include");
+                for (Element include : elems) {
+                    Node parentNode = include.getParentNode();
+                    parentNode.removeChild(include);
+                    String cid = DOMUtils.getAttribute(include, "href");
+                    //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);
+                }
+            }
         }
         return rootElement;        
     }

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=1519782&r1=1519781&r2=1519782&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java Tue Sep  3 18:21:35
2013
@@ -734,6 +734,20 @@ public final class DOMUtils {
             elem = getNextElement(elem);
         }
     }
+    public static boolean hasElementWithName(Element el, String nameSpaceURI, String localName)
{
+        if (el.getNamespaceURI() != null && localName.equals(el.getLocalName())
+            && nameSpaceURI.contains(el.getNamespaceURI())) {
+            return true;
+        }
+        Element elem = getFirstElement(el);
+        while (elem != null) {
+            if (hasElementWithName(elem, nameSpaceURI, localName)) {
+                return true;
+            }
+            elem = getNextElement(elem);
+        }
+        return false;
+    }
     public static boolean hasElementInNS(Element el, String namespace) {
 
         if (namespace.equals(el.getNamespaceURI())) {



Mime
View raw message