cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1536861 - in /cxf/trunk/core/src/main/java/org/apache/cxf: databinding/source/ staxutils/validation/
Date Tue, 29 Oct 2013 19:34:26 GMT
Author: dkulp
Date: Tue Oct 29 19:34:26 2013
New Revision: 1536861

URL: http://svn.apache.org/r1536861
Log:
Updates to cache the Woodstox schema grammer

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/WoodstoxValidationImpl.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=1536861&r1=1536860&r2=1536861&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:34:26 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;
@@ -227,17 +226,13 @@ public class XMLStreamDataReader impleme
 
         WoodstoxValidationImpl impl = new WoodstoxValidationImpl();
         XMLStreamWriter nullWriter = null;
-        boolean canValidate = impl.canValidate();
-        if (canValidate) {
+        if (impl.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;
-            }
+            impl.setupValidation(nullWriter, message.getExchange().getEndpoint(),
+                                 message.getExchange().getService().getServiceInfos().get(0));
         }
-        if (canValidate) {
+        //check if the impl can still validate after the setup, possible issue loading schemas
or similar
+        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

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java?rev=1536861&r1=1536860&r2=1536861&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtils.java
Tue Oct 29 19:34:26 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.staxutils.validat
 
 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/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java?rev=1536861&r1=1536860&r2=1536861&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationInInterceptor.java
Tue Oct 29 19:34:26 2013
@@ -56,7 +56,8 @@ public class StaxSchemaValidationInInter
             try {
                 WoodstoxValidationImpl mgr = new WoodstoxValidationImpl();
                 if (mgr.canValidate()) {
-                    mgr.setupValidation(reader, message.getExchange().getService().getServiceInfos().get(0));
+                    mgr.setupValidation(reader, message.getExchange().getEndpoint(),
+                                        message.getExchange().getService().getServiceInfos().get(0));
                 }
             } catch (Throwable t) {
                 //likely no MSV or similar

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java?rev=1536861&r1=1536860&r2=1536861&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/StaxSchemaValidationOutInterceptor.java
Tue Oct 29 19:34:26 2013
@@ -56,7 +56,8 @@ public class StaxSchemaValidationOutInte
             try {
                 WoodstoxValidationImpl mgr = new WoodstoxValidationImpl();
                 if (mgr.canValidate()) {
-                    mgr.setupValidation(writer, message.getExchange().getService().getServiceInfos().get(0));
+                    mgr.setupValidation(writer, message.getExchange().getEndpoint(),
+                                        message.getExchange().getService().getServiceInfos().get(0));
                 }
             } catch (Throwable t) {
                 //likely no MSV or similar

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/WoodstoxValidationImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/WoodstoxValidationImpl.java?rev=1536861&r1=1536860&r2=1536861&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/WoodstoxValidationImpl.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/validation/WoodstoxValidationImpl.java
Tue Oct 29 19:34:26 2013
@@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.service.model.ServiceInfo;
 
 /**
@@ -54,15 +55,18 @@ public class WoodstoxValidationImpl {
     /** {@inheritDoc}
      * @throws XMLStreamException */
     public void setupValidation(XMLStreamReader reader, 
+                                Endpoint endpoint,
                                 ServiceInfo serviceInfo) throws XMLStreamException {
-        if (utils != null && reader != null) {
-            utils.setupValidation(reader, serviceInfo);
+        if (utils != null && reader != null && !utils.setupValidation(reader,
endpoint, serviceInfo)) {
+            utils = null;
         }
     }
 
-    public void setupValidation(XMLStreamWriter writer, ServiceInfo serviceInfo) throws XMLStreamException
{
-        if (utils != null && writer != null) {
-            utils.setupValidation(writer, serviceInfo);
+    public void setupValidation(XMLStreamWriter writer, 
+                                Endpoint endpoint,
+                                ServiceInfo serviceInfo) throws XMLStreamException {
+        if (utils != null && writer != null && !utils.setupValidation(writer,
endpoint, serviceInfo)) {
+            utils = null;
         }
     }
 }



Mime
View raw message