cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r752307 - in /cxf/trunk: api/src/main/java/org/apache/cxf/databinding/ common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ rt/databinding/aegis/ rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/ rt/databindin...
Date Tue, 10 Mar 2009 23:50:06 GMT
Author: bimargulies
Date: Tue Mar 10 23:50:06 2009
New Revision: 752307

URL: http://svn.apache.org/viewvc?rev=752307&view=rev
Log:
On the one hand, more work toward schema validation with Aegis. On the other hand, turn it
back off until I have a working
substrate to work from.

Added:
    cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
  (with props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
    cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
    cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
    cxf/trunk/rt/databinding/aegis/pom.xml
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
    cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java Tue Mar
10 23:50:06 2009
@@ -35,6 +35,7 @@
 import org.w3c.dom.Node;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.helpers.DOMUtils;
@@ -61,6 +62,9 @@
     private boolean hackAroundEmptyNamespaceIssue;
     
     protected Bus getBus() {
+        if (bus == null) {
+            return BusFactory.getDefaultBus();
+        }
         return bus;
     }
     

Added: cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java?rev=752307&view=auto
==============================================================================
--- cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
(added)
+++ cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
Tue Mar 10 23:50:06 2009
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.wstx_msv_validation;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+import com.sun.msv.reader.GrammarReaderController;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+/**
+ * Catch error messages and resolve schema locations. 
+ */
+public class ResolvingGrammarReaderController implements GrammarReaderController {
+    private static final Logger LOG = LogUtils.getL7dLogger(ResolvingGrammarReaderController.class);
+
+    private Map<String, InputSource> sources;
+
+    public ResolvingGrammarReaderController(Map<String, InputSource> sources) {
+        this.sources = sources;
+    }
+
+    public void error(Locator[] locs, String msg, Exception nestedException) {
+        /* perhaps throw ? */
+        LOG.log(Level.SEVERE, msg, nestedException);
+        for (Locator loc : locs) {
+            LOG.severe("in " + loc.getSystemId() + " " + loc.getLineNumber() + ":" + loc.getColumnNumber());
+        }
+    }
+
+    public void warning(Locator[] locs, String errorMessage) {
+        LOG.log(Level.WARNING, errorMessage);
+        for (Locator loc : locs) {
+            LOG.warning("in " + loc.getSystemId() + " " + loc.getLineNumber() + ":" + loc.getColumnNumber());
+        }
+
+    }
+
+    public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException {
+        // CXF never trucks with publicId's.
+        return sources.get(systemId);
+    }
+}

Propchange: cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/ResolvingGrammarReaderController.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
(original)
+++ cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
Tue Mar 10 23:50:06 2009
@@ -22,8 +22,9 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.logging.Logger;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -35,10 +36,13 @@
 
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaSerializer;
 import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.codehaus.stax2.XMLStreamReader2;
 import org.codehaus.stax2.validation.XMLValidationSchema;
 
@@ -47,11 +51,21 @@
  * fallback.
  */
 class Stax2ValidationUtils {
+    private static final Logger LOG = LogUtils.getL7dLogger(Stax2ValidationUtils.class);
+    
+    public Stax2ValidationUtils() {
+        throw new RuntimeException("Not ready");
+    }
     
     /** {@inheritDoc}
      * @throws XMLStreamException */
     public void setupValidation(XMLStreamReader reader, 
                                 XmlSchemaCollection schemas) 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.
+        if (reader instanceof DepthXMLStreamReader) {
+            reader = ((DepthXMLStreamReader)reader).getReader();
+        }
         XMLStreamReader2 reader2 = (XMLStreamReader2)reader;
         XMLValidationSchema vs = getValidator(schemas);
         reader2.validateAgainst(vs);
@@ -77,9 +91,16 @@
      * @throws XMLStreamException
      */
     private XMLValidationSchema getValidator(XmlSchemaCollection schemas) throws XMLStreamException
{
-        List<InputSource> sources = new ArrayList<InputSource>();
+        Map<String, InputSource> sources = new TreeMap<String, InputSource>();
         XmlSchemaSerializer serializer = new XmlSchemaSerializer();
+        NamespaceMap namespaceContext = new NamespaceMap();
         for (XmlSchema sch : schemas.getXmlSchemas()) {
+            String uri = sch.getTargetNamespace();
+            LOG.info(uri);
+
+            if (sch.getNamespaceContext() == null) {
+                sch.setNamespaceContext(namespaceContext);
+            }
             Document[] serialized;
             try {
                 serialized = serializer.serializeSchema(sch, false);
@@ -89,13 +110,17 @@
             DOMSource domSource = new DOMSource(serialized[0]);
             Reader schemaReader = getSchemaAsStream(domSource);
             InputSource inputSource = new InputSource(schemaReader);
-            inputSource.setSystemId(sch.getSourceURI());
-            sources.add(inputSource);
+            String schemaSystemId = sch.getSourceURI();
+            if (null == schemaSystemId) {
+                schemaSystemId = sch.getTargetNamespace();
+            }
+            inputSource.setSystemId(schemaSystemId);
+            sources.put(schemaSystemId, inputSource);
         }
         
         W3CMultiSchemaFactory factory = new W3CMultiSchemaFactory();
         XMLValidationSchema vs;
-        vs = factory.loadSchemas(sources.toArray(new InputSource[sources.size()]));
+        vs = factory.loadSchemas(sources);
         return vs;
     }
 

Modified: cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
(original)
+++ cxf/trunk/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
Tue Mar 10 23:50:06 2009
@@ -23,11 +23,12 @@
 
 package org.apache.cxf.wstx_msv_validation;
 
+import java.util.Map;
+
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLStreamException;
 
 import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
 
 import com.ctc.wstx.msv.BaseSchemaFactory;
 import com.ctc.wstx.msv.W3CSchema;
@@ -37,31 +38,6 @@
 
 import org.codehaus.stax2.validation.XMLValidationSchema;
 
-final class MyGrammarController extends com.sun.msv.reader.util.IgnoreController {
-    private String mErrorMsg;
-
-    public MyGrammarController() {
-    }
-
-    // public void warning(Locator[] locs, String errorMessage) { }
-
-    public void error(Locator[] locs, String msg, Exception nestedException) {
-        if (getMErrorMsg() == null) {
-            setMErrorMsg(msg);
-        } else {
-            setMErrorMsg(getMErrorMsg() + "; " + msg);
-        }
-    }
-
-    public void setMErrorMsg(String mErrorMsg) {
-        this.mErrorMsg = mErrorMsg;
-    }
-
-    public String getMErrorMsg() {
-        return mErrorMsg;
-    }
-}
-
 /**
  * 
  */
@@ -70,23 +46,24 @@
     private MultiSchemaReader multiSchemaReader;  
     private SAXParserFactory parserFactory;
     private XMLSchemaReader xmlSchemaReader;
-    private MyGrammarController ctrl = new MyGrammarController();
 
     public W3CMultiSchemaFactory() {
-        super(XMLValidationSchema.SCHEMA_ID_RELAXNG);
+        super(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA);
     }
     
-    public XMLValidationSchema loadSchemas(InputSource[] sources) throws XMLStreamException
{
+    public XMLValidationSchema loadSchemas(Map<String, InputSource> sources) throws
XMLStreamException {
         parserFactory = getSaxFactory();
+        
+        ResolvingGrammarReaderController ctrl = new ResolvingGrammarReaderController(sources);
         xmlSchemaReader = new XMLSchemaReader(ctrl, parserFactory);
         multiSchemaReader = new MultiSchemaReader(xmlSchemaReader);
-        for (InputSource source : sources) {
+        for (InputSource source : sources.values()) {
             multiSchemaReader.parse(source);
         }
         
         XMLSchemaGrammar grammar = multiSchemaReader.getResult();
         if (grammar == null) {
-            throw new XMLStreamException("Failed to load schemas: " + ctrl.getMErrorMsg());
+            throw new XMLStreamException("Failed to load schemas");
         }
         return new W3CSchema(grammar); 
     }

Modified: cxf/trunk/rt/databinding/aegis/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/pom.xml?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/pom.xml (original)
+++ cxf/trunk/rt/databinding/aegis/pom.xml Tue Mar 10 23:50:06 2009
@@ -89,6 +89,12 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-wstx-msv-validation</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
     </dependencies>
 
     <build>

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
Tue Mar 10 23:50:06 2009
@@ -106,6 +106,9 @@
         extension.registerConduitInitiator(SoapBindingConstants.SOAP11_BINDING_ID, localTransport);
 
         bus.setExtension(new WSDLManagerImpl(), WSDLManager.class);
+        //WoodstoxValidationImpl wstxVal = new WoodstoxValidationImpl();
+        
+        
 
         addNamespace("wsdl", SOAPConstants.WSDL11_NS);
         addNamespace("wsdlsoap", SOAPConstants.WSDL11_SOAP_NS);
@@ -210,6 +213,8 @@
                 context.setEnableJDOMMappings(true);
             }
             binding = new AegisDatabinding();
+            // perhaps the data binding needs to do this for itself?
+            binding.setBus(BusFactory.getDefaultBus());
             if (enableJDOM) { // this preserves pre-2.1 behavior.
                 binding.setAegisContext(context);
             }

Modified: cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml?rev=752307&r1=752306&r2=752307&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/resources/org/apache/cxf/aegis/integration/invalidArrayMessage.xml
Tue Mar 10 23:50:06 2009
@@ -21,7 +21,6 @@
                    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <soap-env:Body xmlns:jns0='urn:Array' >
   <jns0:submitW3CArray>
-   <jns0:whoops/>
    <jns0:before>before items</jns0:before>
    <jns0:anything>
        <jns0:anyType><walrus xmlns='uri:iam'>tusks</walrus></jns0:anyType>



Mime
View raw message