cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/2] cxf git commit: Remove xerces dep (use xerces built into the JDK) to allow test failures to duplicate in eclipse
Date Fri, 06 Nov 2015 19:35:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ce6923c37 -> ced98c6e9


Remove xerces dep (use xerces built into the JDK) to allow test failures to duplicate in eclipse


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/39851b83
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/39851b83
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/39851b83

Branch: refs/heads/master
Commit: 39851b83af116611ce0efe70c4b9a32ee8491523
Parents: ce6923c
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Nov 6 14:08:30 2015 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Nov 6 14:09:04 2015 -0500

----------------------------------------------------------------------
 core/pom.xml                                    |   7 --
 .../cxf/common/xmlschema/ImportRepairTest.java  | 107 +++++++++++--------
 rt/wsdl/pom.xml                                 |   6 --
 .../factory/XercesSchemaValidationUtils.java    |  88 ++++++++-------
 .../factory/XercesXsdValidationImpl.java        |   2 +
 .../validator/internal/SchemaValidator.java     |   1 +
 6 files changed, 112 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 81abf12..ab6ccbd 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -142,13 +142,6 @@
             <artifactId>woodstox-core-asl</artifactId>
         </dependency>
         <dependency>
-            <!-- this is probably not quite what we want in terms of the behavior of the
other tests
-                 than the schema surgery test. -->
-            <groupId>xerces</groupId>
-            <artifactId>xercesImpl</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-beans</artifactId>
             <optional>true</optional>

http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/core/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java b/core/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
index 95e202f..14e5e25 100644
--- a/core/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
+++ b/core/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.common.xmlschema;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -30,8 +32,10 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMSource;
 
+import org.w3c.dom.DOMConfiguration;
 import org.w3c.dom.DOMError;
 import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 import org.w3c.dom.bootstrap.DOMImplementationRegistry;
 import org.w3c.dom.ls.LSInput;
@@ -52,9 +56,6 @@ import org.apache.ws.commons.schema.XmlSchemaSerializer;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
-import org.apache.xerces.xs.LSInputList;
-import org.apache.xerces.xs.XSImplementation;
-import org.apache.xerces.xs.XSLoader;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -66,24 +67,6 @@ public class ImportRepairTest extends Assert {
 
     static boolean dumpSchemas;
 
-    @SuppressWarnings("rawtypes")
-    private static final class ListLSInput extends ArrayList implements LSInputList {
-        private static final long serialVersionUID = 1L;
-
-        @SuppressWarnings("unchecked")
-        private ListLSInput(List inputs) {
-            super(inputs);
-        }
-
-        public int getLength() {
-            return size();
-        }
-
-        public LSInput item(int index) {
-            return (LSInput)get(index);
-        }
-    }
-
     private static final Logger LOG = LogUtils.getL7dLogger(ImportRepairTest.class);
 
     private static final String IMPORTING_SCHEMA = "urn:importing";
@@ -152,6 +135,15 @@ public class ImportRepairTest extends Assert {
         collection.addCrossImports();
         tryToParseSchemas();
     }
+    
+    Method findMethod(Object o, String name) {
+        for (Method m: o.getClass().getMethods()) {
+            if (m.getName() == name) {
+                return m;
+            }
+        }
+        return null;
+    }
 
     private void tryToParseSchemas() throws Exception {
         // Get DOM Implementation using DOM Registry
@@ -169,34 +161,57 @@ public class ImportRepairTest extends Assert {
             inputs.add(input);
         }
 
-        System.setProperty(DOMImplementationRegistry.PROPERTY,
-                           "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
         DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+        DOMImplementation impl = registry.getDOMImplementation("XS-Loader");
 
-        XSImplementation impl = (XSImplementation)registry.getDOMImplementation("XS-Loader");
-
-        XSLoader schemaLoader = impl.createXSLoader(null);
-        schemaLoader.getConfig().setParameter("validate", Boolean.TRUE);
-        schemaLoader.getConfig().setParameter("error-handler", new DOMErrorHandler() {
-
-            public boolean handleError(DOMError error) {
-                LOG.info("Schema parsing error: " + error.getMessage()
-                         + " " + error.getType()
-                         + " " + error.getLocation().getUri()
-                         + " " + error.getLocation().getLineNumber()
-                         + ":" + error.getLocation().getColumnNumber());
-                throw new DOMErrorException(error);
-            }
-        });
-        schemaLoader.getConfig().setParameter("resource-resolver", new LSResourceResolver()
{
-
-            public LSInput resolveResource(String type, String namespaceURI, String publicId,
-                                           String systemId, String baseURI) {
-                return resolverMap.get(namespaceURI);
+        
+        try {
+            Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
+            DOMConfiguration config = (DOMConfiguration)findMethod(schemaLoader, "getConfig").invoke(schemaLoader);
+            
+            config.setParameter("validate", Boolean.TRUE);
+            try {
+                //bug in the JDK doesn't set this, but accesses it 
+                config.setParameter("http://www.oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager",
+                                    Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager")
+                                        .newInstance());
+                
+                config.setParameter("http://apache.org/xml/properties/security-manager",
+                                    Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityManager")
+                                        .newInstance());
+            } catch (Throwable t) {
+                //ignore
             }
-        });
-
-        schemaLoader.loadInputList(new ListLSInput(inputs));
+            config.setParameter("error-handler", new DOMErrorHandler() {
+    
+                public boolean handleError(DOMError error) {
+                    LOG.info("Schema parsing error: " + error.getMessage()
+                             + " " + error.getType()
+                             + " " + error.getLocation().getUri()
+                             + " " + error.getLocation().getLineNumber()
+                             + ":" + error.getLocation().getColumnNumber());
+                    throw new DOMErrorException(error);
+                }
+            });
+            config.setParameter("resource-resolver", new LSResourceResolver() {
+    
+                public LSInput resolveResource(String type, String namespaceURI, String publicId,
+                                               String systemId, String baseURI) {
+                    return resolverMap.get(namespaceURI);
+                }
+            });
+    
+            Method m = findMethod(schemaLoader, "loadInputList");
+            String name = m.getParameterTypes()[0].getName() + "Impl";
+            name = name.replace("xs.LS", "impl.xs.util.LS");
+            Class<?> c = Class.forName(name);
+            Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE)
+            .newInstance(inputs.toArray(new LSInput[inputs.size()]), inputs.size());
+        
+            findMethod(schemaLoader, "loadInputList").invoke(schemaLoader, inputList);
+        } catch (InvocationTargetException ite) {
+            throw (Exception)ite.getTargetException();
+        }
     }
 
     private void dumpSchema(Document document) throws Exception {

http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/rt/wsdl/pom.xml
----------------------------------------------------------------------
diff --git a/rt/wsdl/pom.xml b/rt/wsdl/pom.xml
index 54af181..719cba3 100644
--- a/rt/wsdl/pom.xml
+++ b/rt/wsdl/pom.xml
@@ -70,12 +70,6 @@
             <artifactId>spring-context</artifactId>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>xerces</groupId>
-            <artifactId>xercesImpl</artifactId>
-            <scope>provided</scope>
-            <optional>true</optional>
-        </dependency>
     </dependencies>
     <build>
         <plugins>

http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesSchemaValidationUtils.java
----------------------------------------------------------------------
diff --git a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesSchemaValidationUtils.java
b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesSchemaValidationUtils.java
index e8366e8..0456671 100644
--- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesSchemaValidationUtils.java
+++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesSchemaValidationUtils.java
@@ -21,6 +21,8 @@ package org.apache.cxf.wsdl.service.factory;
 
 import java.io.InputStream;
 import java.io.Reader;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -29,8 +31,11 @@ import java.util.Map;
 import javax.xml.XMLConstants;
 import javax.xml.transform.TransformerException;
 
+import org.w3c.dom.DOMConfiguration;
 import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
 import org.w3c.dom.ls.LSInput;
 import org.w3c.dom.ls.LSResourceResolver;
 
@@ -38,35 +43,13 @@ import org.apache.cxf.staxutils.StaxUtils;
 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.xerces.dom.DOMXSImplementationSourceImpl;
-import org.apache.xerces.xs.LSInputList;
-import org.apache.xerces.xs.XSImplementation;
-import org.apache.xerces.xs.XSLoader;
 
 /**
  * 
  */
 class XercesSchemaValidationUtils {
 
-    @SuppressWarnings("rawtypes")
-    private static final class ListLSInput extends ArrayList implements LSInputList {
-        private static final long serialVersionUID = 1L;
-
-        @SuppressWarnings("unchecked")
-        private ListLSInput(List inputs) {
-            super(inputs);
-        }
-
-        public int getLength() {
-            return size();
-        }
-
-        public LSInput item(int index) {
-            return (LSInput)get(index);
-        }
-    }
-    
+   
     class DOMLSInput implements LSInput {
         private String systemId;
         private String data;
@@ -150,15 +133,27 @@ class XercesSchemaValidationUtils {
     }
     
     
-    private XSImplementation impl;
+    private DOMImplementation impl;
 
-    XercesSchemaValidationUtils() {
-        DOMXSImplementationSourceImpl source = new org.apache.xerces.dom.DOMXSImplementationSourceImpl();
-        impl = (XSImplementation)source.getDOMImplementation("XS-Loader");
+    XercesSchemaValidationUtils() throws ClassNotFoundException, InstantiationException,
+        IllegalAccessException, ClassCastException {
+        
+        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+        impl = registry.getDOMImplementation("XS-Loader");
     }
 
+    
+    Method findMethod(Object o, String name) {
+        for (Method m: o.getClass().getMethods()) {
+            if (m.getName() == name) {
+                m.setAccessible(true);
+                return m;
+            }
+        }
+        return null;
+    }
     void tryToParseSchemas(XmlSchemaCollection collection, DOMErrorHandler handler)
-        throws XmlSchemaSerializerException, TransformerException {
+        throws Exception {
 
         final List<DOMLSInput> inputs = new ArrayList<DOMLSInput>();
         final Map<String, LSInput> resolverMap = new HashMap<String, LSInput>();
@@ -173,17 +168,30 @@ class XercesSchemaValidationUtils {
             inputs.add(input);
         }
 
-        XSLoader schemaLoader = impl.createXSLoader(null);
-        schemaLoader.getConfig().setParameter("validate", Boolean.TRUE);
-        schemaLoader.getConfig().setParameter("error-handler", handler);
-        schemaLoader.getConfig().setParameter("resource-resolver", new LSResourceResolver()
{
-
-            public LSInput resolveResource(String type, String namespaceURI, String publicId,
-                                           String systemId, String baseURI) {
-                return resolverMap.get(namespaceURI);
-            }
-        });
-
-        schemaLoader.loadInputList(new ListLSInput(inputs));
+        try {
+        
+            Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
+            DOMConfiguration config = (DOMConfiguration)findMethod(schemaLoader, "getConfig").invoke(schemaLoader);
+    
+            config.setParameter("validate", Boolean.TRUE);
+            config.setParameter("error-handler", handler);
+            config.setParameter("resource-resolver", new LSResourceResolver() {
+                public LSInput resolveResource(String type, String namespaceURI, String publicId,
+                                               String systemId, String baseURI) {
+                    return resolverMap.get(namespaceURI);
+                }
+            });
+    
+            
+            Method m = findMethod(schemaLoader, "loadInputList");
+            String name = m.getParameterTypes()[0].getName() + "Impl";
+            name = name.replace("xs.LS", "impl.xs.util.LS");
+            Class<?> c = Class.forName(name);
+            Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE)
+                .newInstance(inputs.toArray(new LSInput[inputs.size()]), inputs.size());
+            m.invoke(schemaLoader, inputList);
+        } catch (InvocationTargetException e) {
+            throw (Exception)e.getTargetException(); 
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesXsdValidationImpl.java
----------------------------------------------------------------------
diff --git a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesXsdValidationImpl.java
b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesXsdValidationImpl.java
index 7715e8b..e2c6c0d 100644
--- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesXsdValidationImpl.java
+++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/XercesXsdValidationImpl.java
@@ -54,6 +54,8 @@ class XercesXsdValidationImpl  {
             LOG.log(Level.WARNING, "XML Schema serialization error", e);
         } catch (TransformerException e) {
             LOG.log(Level.SEVERE, "TraX failure converting DOM to string", e);
+        } catch (Exception e) {
+            LOG.log(Level.SEVERE, "XML failure", e);            
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/39851b83/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
----------------------------------------------------------------------
diff --git a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
index 87bf631..c8e80e1 100644
--- a/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
+++ b/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
@@ -354,6 +354,7 @@ class SchemaResourceResolver implements LSResourceResolver {
     private LSInput loadLSInput(String ns) {
         String path = ToolConstants.CXF_SCHEMAS_DIR_INJAR + NSFILEMAP.get(ns);
         URL url = getClass().getClassLoader().getResource(path);
+        System.out.println(url);
         LSInput lsin = new LSInputImpl();
         lsin.setSystemId(url.toString());
         try {


Mime
View raw message