cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1519830 - in /cxf/branches/2.6.x-fixes: api/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/databinding/source/
Date Tue, 03 Sep 2013 20:07:57 GMT
Author: dkulp
Date: Tue Sep  3 20:07:57 2013
New Revision: 1519830

URL: http://svn.apache.org/r1519830
Log:
Merged revisions 1519824 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1519824 | dkulp | 2013-09-03 16:00:09 -0400 (Tue, 03 Sep 2013) | 11 lines

  Merged revisions 1519782 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1519782 | dkulp | 2013-09-03 14:21:35 -0400 (Tue, 03 Sep 2013) | 3 lines

    [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/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/helpers/DOMUtils.java
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=1519830&r1=1519829&r2=1519830&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/helpers/DOMUtils.java Tue Sep
 3 20:07:57 2013
@@ -754,6 +754,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())) {

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties?rev=1519830&r1=1519829&r2=1519830&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/Messages.properties
Tue Sep  3 20:07:57 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.
 Make sure cxf-wstx-msv-validation and the MSV libraries are found.
+NO_MSV_AVAILABLE = Failed to initialize MSV validator, using slower validation routing.

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=1519830&r1=1519829&r2=1519830&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
Tue Sep  3 20:07:57 2013
@@ -22,7 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
-import java.util.logging.Level;
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.activation.DataSource;
@@ -38,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.io.CachedOutputStream;
 import org.apache.cxf.io.StaxValidationManager;
@@ -203,7 +207,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,11 +223,31 @@ public class XMLStreamDataReader impleme
                 StaxUtils.createFilteredReader(reader, 
                                                new StaxStreamFilter(new QName[] {XOP}));
             
-            XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
       
+            XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
+            
             svm.setupValidation(nullWriter, message.getExchange().getService().getServiceInfos().get(0));
             StaxUtils.copy(filteredReader, nullWriter);
         } else {
-            LOG.log(Level.WARNING, "COULD_NOT_VALIDATE_XML_STREAM");
+            //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;        
     }



Mime
View raw message