You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2009/03/21 17:31:08 UTC

svn commit: r756967 - in /cxf/trunk: common/xerces-xsd-validation/ common/xerces-xsd-validation/src/main/resources/ common/xerces-xsd-validation/src/main/resources/META-INF/ common/xerces-xsd-validation/src/main/resources/META-INF/cxf/ parent/ rt/front...

Author: bimargulies
Date: Sat Mar 21 16:31:01 2009
New Revision: 756967

URL: http://svn.apache.org/viewvc?rev=756967&view=rev
Log:
Make a property on RSFB to enable validation, including validation of any schemata created by the data binding.

Next trick is to try it out.


Added:
    cxf/trunk/common/xerces-xsd-validation/src/main/resources/
    cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/
    cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/
    cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml   (with props)
Modified:
    cxf/trunk/common/xerces-xsd-validation/   (props changed)
    cxf/trunk/parent/pom.xml
    cxf/trunk/rt/frontend/simple/pom.xml
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/SimpleMessages.properties

Propchange: cxf/trunk/common/xerces-xsd-validation/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Mar 21 16:31:01 2009
@@ -0,0 +1,7 @@
+target
+.settings
+.checkstyle
+.classpath
+.pmd
+.project
+.ruleset

Added: cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml?rev=756967&view=auto
==============================================================================
--- cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml (added)
+++ cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml Sat Mar 21 16:31:01 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<extensions xmlns="http://cxf.apache.org/bus/extension">
+    <extension class="org.apache.cxf.xsdvalidation.XercesXsdValidationImpl"
+           interface="org.apache.cxf.common.xmlschema.XmlSchemaValidationManager"/>
+</extensions>

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/resources/META-INF/cxf/bus-extensions.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=756967&r1=756966&r2=756967&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Sat Mar 21 16:31:01 2009
@@ -1058,6 +1058,12 @@
 		</exclusion>
 	      </exclusions>
 	    </dependency>
+	    <dependency>
+	      <groupId>xerces</groupId>
+	      <artifactId>xercesImpl</artifactId>
+	      <version>2.9.1</version>
+	    </dependency>
+
         </dependencies>
     </dependencyManagement>
 

Modified: cxf/trunk/rt/frontend/simple/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/pom.xml?rev=756967&r1=756966&r2=756967&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/pom.xml (original)
+++ cxf/trunk/rt/frontend/simple/pom.xml Sat Mar 21 16:31:01 2009
@@ -83,6 +83,16 @@
             <version>${project.version}</version>
             <optional>true</optional>
         </dependency>
+
+<!-- if this is present, then the validation feature
+     will check W3C schema if Xerces is available. -->
+        <dependency>
+	  <groupId>org.apache.cxf</groupId>
+	  <artifactId>cxf-xerces-xsd-validation</artifactId>
+	  <version>${project.version}</version>
+	  <optional>true</optional>
+        </dependency>
+
         <dependency>
             <groupId>javax.xml.soap</groupId>
             <artifactId>saaj-api</artifactId>

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=756967&r1=756966&r2=756967&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Sat Mar 21 16:31:01 2009
@@ -52,6 +52,9 @@
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.DOMError;
+import org.w3c.dom.DOMErrorHandler;
+
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.catalog.CatalogXmlSchemaURIResolver;
@@ -62,6 +65,7 @@
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
+import org.apache.cxf.common.xmlschema.XmlSchemaValidationManager;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.databinding.source.mime.MimeAttribute;
 import org.apache.cxf.databinding.source.mime.MimeSerializer;
@@ -157,6 +161,7 @@
     private boolean populateFromClass;
     private boolean anonymousWrappers;
     private boolean qualifiedSchemas = true;
+    private boolean validate;
 
     private List<AbstractFeature> features;
     
@@ -165,8 +170,6 @@
     private String styleCache;
     private Boolean defWrappedCache;
     
-    
-    
     public ReflectionServiceFactoryBean() {
         getServiceConfigurations().add(0, new DefaultServiceConfiguration());
 
@@ -400,12 +403,16 @@
                 }
             }
         }
-        if (LOG.isLoggable(Level.FINE)) {
+        if (LOG.isLoggable(Level.FINE) || isValidate()) {
             ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
             validator.walk();
             String validationComplaints = validator.getComplaints();
             if (!"".equals(validationComplaints)) {
-                LOG.fine(validationComplaints);
+                if (isValidate()) {
+                    LOG.warning(validationComplaints);
+                } else {
+                    LOG.fine(validationComplaints);
+                }
             }
         }
     }
@@ -430,11 +437,21 @@
         } else {
             buildServiceFromClass();
         }
-        // validateServiceModel();
+        
+        if (isValidate()) {
+            validateServiceModel();
+        }
     }
 
     public void validateServiceModel() {
+        
+        XmlSchemaValidationManager xsdValidator = getBus().getExtension(XmlSchemaValidationManager.class);
+        
         for (ServiceInfo si : getService().getServiceInfos()) {
+            if (xsdValidator != null) {
+                validateSchemas(xsdValidator, si.getXmlSchemaCollection());
+            }
+            
             for (OperationInfo opInfo : si.getInterface().getOperations()) {
                 for (MessagePartInfo mpi : opInfo.getInput().getMessageParts()) {
                     assert mpi.getXmlSchema() != null;
@@ -490,6 +507,23 @@
         }
     }
 
+    private void validateSchemas(XmlSchemaValidationManager xsdValidator, 
+                                 SchemaCollection xmlSchemaCollection) {
+        final boolean[] anyErrors = new boolean[1];
+        anyErrors[0] = false;
+        xsdValidator.validateSchemas(xmlSchemaCollection.getXmlSchemaCollection(), new DOMErrorHandler() {
+
+            public boolean handleError(DOMError error) {
+                anyErrors[0] = true;
+                LOG.warning(error.getMessage());
+                return true;
+            }
+        });
+        if (anyErrors[0]) {
+            throw new ServiceConstructionException(new Message("XSD_VALIDATION_ERROR", LOG));
+        }
+    }
+
     public boolean isPopulateFromClass() {
         return populateFromClass;
     }
@@ -2293,4 +2327,17 @@
     public void setFeatures(List<AbstractFeature> f) {
         this.features = f;
     }
+
+    private boolean isValidate() {
+        return validate || System.getProperty("cxf.validateServiceSchemas", "false").equals("true");
+    }
+
+    /**
+     * If 'validate' is true, this class will validate the service. It will report problems
+     * with the service model and the XML schema for the service.
+     * @param validate
+     */
+    public void setValidate(boolean validate) {
+        this.validate = validate;
+    }
 }

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/SimpleMessages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/SimpleMessages.properties?rev=756967&r1=756966&r2=756967&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/SimpleMessages.properties (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/SimpleMessages.properties Sat Mar 21 16:31:01 2009
@@ -30,4 +30,5 @@
   without the JAX-WS service factory bean.
 INTRACTABLE_PART= Message part {0} of Message {1} cannot be processed. This can be caused by the use of JAX-WS-specific types \
  without the JAX-WS service factory bean.
-JAXWS_ANNOTATION_FOUND=A JAX-WS Annotation was found on {0} while using the Simple frontend.  For better results, use the JAX-WS frontend.
\ No newline at end of file
+JAXWS_ANNOTATION_FOUND=A JAX-WS Annotation was found on {0} while using the Simple frontend.  For better results, use the JAX-WS frontend.
+XSD_VALIDATION_ERROR= Error in W3C XML Schema associated with service.
\ No newline at end of file