You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/10/29 20:47:45 UTC

svn commit: r1536867 - in /cxf/branches/2.7.x-fixes: api/src/main/java/org/apache/cxf/io/ common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ rt/core/src/main/java/org/apache/cxf/databinding/source/ rt/databinding/aegis/src/mai...

Author: dkulp
Date: Tue Oct 29 19:47:44 2013
New Revision: 1536867

URL: http://svn.apache.org/r1536867
Log:
Merged revisions 1536861 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1536861 | dkulp | 2013-10-29 15:34:26 -0400 (Tue, 29 Oct 2013) | 2 lines

  Updates to cache the Woodstox schema grammer

........

Modified:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/io/StaxValidationManager.java
    cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
    cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/WoodstoxValidationImpl.java
    cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
    cxf/branches/2.7.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisSchemaValidationInInterceptor.java

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/io/StaxValidationManager.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/io/StaxValidationManager.java?rev=1536867&r1=1536866&r2=1536867&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/io/StaxValidationManager.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/io/StaxValidationManager.java Tue Oct 29 19:47:44 2013
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.service.model.ServiceInfo;
 
 /**
@@ -36,7 +37,7 @@ public interface StaxValidationManager {
      * @param serviceInfo - the Service to pull the schema from
      * @throws XMLStreamException 
      */
-    boolean setupValidation(XMLStreamReader reader, ServiceInfo serviceInfo) throws XMLStreamException;
+    boolean setupValidation(XMLStreamReader reader, Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException;
     
     /**
      * Install the schemas onto the writer for validation.
@@ -44,6 +45,6 @@ public interface StaxValidationManager {
      * @param serviceInfo - the Service to pull the schema from
      * @throws XMLStreamException 
      */
-    boolean setupValidation(XMLStreamWriter writer, ServiceInfo serviceInfo) throws XMLStreamException;
+    boolean setupValidation(XMLStreamWriter writer, Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException;
 
 }

Modified: cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java?rev=1536867&r1=1536866&r2=1536867&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java (original)
+++ cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java Tue Oct 29 19:47:44 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.wstx_msv_validati
 
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.XMLConstants;
@@ -32,6 +33,7 @@ import org.w3c.dom.Element;
 
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
@@ -49,6 +51,7 @@ import org.codehaus.stax2.validation.XML
  */
 class Stax2ValidationUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(Stax2ValidationUtils.class);
+    private static final String KEY = XMLValidationSchema.class.getName();
 
     public Stax2ValidationUtils() {
         new W3CMultiSchemaFactory(); // will throw if wrong woodstox.
@@ -59,7 +62,9 @@ class Stax2ValidationUtils {
      * 
      * @throws XMLStreamException
      */
-    public void setupValidation(XMLStreamReader reader, ServiceInfo serviceInfo) throws XMLStreamException {
+    public boolean setupValidation(XMLStreamReader reader, Endpoint endpoint, ServiceInfo serviceInfo) 
+        throws XMLStreamException {
+        
         // Gosh, this is bad, but I don't know a better solution, unless we're willing
         // to require the stax2 API no matter what.
         XMLStreamReader effectiveReader = reader;
@@ -67,7 +72,10 @@ class Stax2ValidationUtils {
             effectiveReader = ((DepthXMLStreamReader)reader).getReader();
         }
         final XMLStreamReader2 reader2 = (XMLStreamReader2)effectiveReader;
-        XMLValidationSchema vs = getValidator(serviceInfo);
+        XMLValidationSchema vs = getValidator(endpoint, serviceInfo);
+        if (vs == null) {
+            return false;
+        }
         reader2.setValidationProblemHandler(new ValidationProblemHandler() {
 
             public void reportProblem(XMLValidationProblem problem) throws XMLValidationException {
@@ -76,11 +84,17 @@ class Stax2ValidationUtils {
             }
         });
         reader2.validateAgainst(vs);
+        return true;
     }
 
-    public void setupValidation(XMLStreamWriter writer, ServiceInfo serviceInfo) throws XMLStreamException {
+    public boolean setupValidation(XMLStreamWriter writer, Endpoint endpoint, ServiceInfo serviceInfo) 
+        throws XMLStreamException {
+        
         XMLStreamWriter2 writer2 = (XMLStreamWriter2)writer;
-        XMLValidationSchema vs = getValidator(serviceInfo);
+        XMLValidationSchema vs = getValidator(endpoint, serviceInfo);
+        if (vs == null) {
+            return false;
+        }
         writer2.setValidationProblemHandler(new ValidationProblemHandler() {
 
             public void reportProblem(XMLValidationProblem problem) throws XMLValidationException {
@@ -88,6 +102,7 @@ class Stax2ValidationUtils {
             }
         });
         writer2.validateAgainst(vs);
+        return true;
     }
 
     /**
@@ -97,32 +112,45 @@ class Stax2ValidationUtils {
      * @return
      * @throws XMLStreamException
      */
-    private XMLValidationSchema getValidator(ServiceInfo serviceInfo) throws XMLStreamException {
-        Map<String, EmbeddedSchema> sources = new TreeMap<String, EmbeddedSchema>();
-
-        for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
-            XmlSchema sch = schemaInfo.getSchema();
-            String uri = sch.getTargetNamespace();
-            if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri)) {
-                continue;
+    private XMLValidationSchema getValidator(Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException {
+        synchronized (endpoint) {
+            XMLValidationSchema ret = (XMLValidationSchema)endpoint.get(KEY);
+            if (ret == null) {
+                if (endpoint.containsKey(KEY)) {
+                    return null;
+                }
+                Map<String, EmbeddedSchema> sources = new TreeMap<String, EmbeddedSchema>();
+        
+                for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
+                    XmlSchema sch = schemaInfo.getSchema();
+                    String uri = sch.getTargetNamespace();
+                    if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri)) {
+                        continue;
+                    }
+                    LOG.info(uri);
+        
+                    Element serialized = schemaInfo.getElement();
+                    String schemaSystemId = sch.getSourceURI();
+                    if (null == schemaSystemId) {
+                        schemaSystemId = sch.getTargetNamespace();
+                    }
+        
+                    EmbeddedSchema embeddedSchema = new EmbeddedSchema(schemaSystemId, serialized);
+                    sources.put(sch.getTargetNamespace(), embeddedSchema);
+                }
+        
+                W3CMultiSchemaFactory factory = new W3CMultiSchemaFactory();
+                // I don't think that we need the baseURI.
+                try {
+                    ret = factory.loadSchemas(null, sources);
+                    endpoint.put(KEY, ret);
+                } catch (XMLStreamException ex) {
+                    LOG.log(Level.INFO, "Problem loading schemas. Falling back to slower method.", ret);
+                    endpoint.put(KEY, null);
+                }
             }
-            LOG.info(uri);
-
-            Element serialized = schemaInfo.getElement();
-            String schemaSystemId = sch.getSourceURI();
-            if (null == schemaSystemId) {
-                schemaSystemId = sch.getTargetNamespace();
-            }
-
-            EmbeddedSchema embeddedSchema = new EmbeddedSchema(schemaSystemId, serialized);
-            sources.put(sch.getTargetNamespace(), embeddedSchema);
+            return ret;
         }
-
-        W3CMultiSchemaFactory factory = new W3CMultiSchemaFactory();
-        XMLValidationSchema vs;
-        // I don't think that we need the baseURI.
-        vs = factory.loadSchemas(null, sources);
-        return vs;
     }
 
 }

Modified: cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/WoodstoxValidationImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/WoodstoxValidationImpl.java?rev=1536867&r1=1536866&r2=1536867&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/WoodstoxValidationImpl.java (original)
+++ cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/WoodstoxValidationImpl.java Tue Oct 29 19:47:44 2013
@@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamWriter;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.io.StaxValidationManager;
 import org.apache.cxf.service.model.ServiceInfo;
 
@@ -62,18 +63,19 @@ public class WoodstoxValidationImpl impl
     /** {@inheritDoc}
      * @throws XMLStreamException */
     public boolean setupValidation(XMLStreamReader reader,
-                                ServiceInfo serviceInfo) throws XMLStreamException {
+                                   Endpoint endpoint,
+                                   ServiceInfo serviceInfo) throws XMLStreamException {
         if (utils != null && reader != null) {
-            utils.setupValidation(reader, serviceInfo);
-            return true;
+            return utils.setupValidation(reader, endpoint, serviceInfo);
         }
         return false;
     }
 
-    public boolean setupValidation(XMLStreamWriter writer, ServiceInfo serviceInfo) throws XMLStreamException {
+    public boolean setupValidation(XMLStreamWriter writer,
+                                   Endpoint endpoint,
+                                   ServiceInfo serviceInfo) throws XMLStreamException {
         if (utils != null && writer != null) {
-            utils.setupValidation(writer, serviceInfo);
-            return true;
+            return utils.setupValidation(writer, endpoint, serviceInfo);
         }
         return false;
     }

Modified: cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=1536867&r1=1536866&r2=1536867&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java (original)
+++ cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java Tue Oct 29 19:47:44 2013
@@ -23,7 +23,6 @@ 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;
@@ -220,7 +219,6 @@ public class XMLStreamDataReader impleme
         boolean stax = false;
         if (svm != null) {
             //filter xop node
-            
             XMLStreamWriter nullWriter = StaxUtils.createXMLStreamWriter(new NUllOutputStream());
             if (svm.setupValidation(nullWriter, message.getExchange().getService().getServiceInfos().get(0))) {
                 XMLStreamReader reader = StaxUtils.createXMLStreamReader(ds);

Modified: cxf/branches/2.7.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisSchemaValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisSchemaValidationInInterceptor.java?rev=1536867&r1=1536866&r2=1536867&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisSchemaValidationInInterceptor.java (original)
+++ cxf/branches/2.7.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisSchemaValidationInInterceptor.java Tue Oct 29 19:47:44 2013
@@ -66,7 +66,7 @@ public class AegisSchemaValidationInInte
         if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
             StaxValidationManager mgr = bus.getExtension(StaxValidationManager.class);
             if (mgr != null) {
-                mgr.setupValidation(reader, service);
+                mgr.setupValidation(reader, message.getExchange().getEndpoint(), service);
             }
         }
     }