cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r587966 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/wsdl11/ systests/src/test/java/org/apache/cxf/systest/wsdl/ systests/src/test/resources/
Date Wed, 24 Oct 2007 18:55:17 GMT
Author: bimargulies
Date: Wed Oct 24 11:55:16 2007
New Revision: 587966

URL: http://svn.apache.org/viewvc?rev=587966&view=rev
Log:
CXF-1103. Add missing cross-schema imports.


Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
    incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java?rev=587966&r1=587965&r2=587966&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XMLUtils.java Wed
Oct 24 11:55:16 2007
@@ -156,8 +156,7 @@
             it.setOutputProperty(OutputKeys.ENCODING, charset);
             it.transform(src, new StreamResult(os));
         } catch (TransformerException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new RuntimeException("Failed to configure TRaX", e);
         }
 
     }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=587966&r1=587965&r2=587966&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
Wed Oct 24 11:55:16 2007
@@ -25,6 +25,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+
 import javax.wsdl.Binding;
 import javax.wsdl.BindingFault;
 import javax.wsdl.BindingInput;
@@ -48,6 +49,7 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -57,6 +59,7 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.AbstractPropertiesHolder;
 import org.apache.cxf.service.model.BindingFaultInfo;
@@ -72,6 +75,7 @@
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
 
 /**
  * Consume a set of service definitions and produce a WSDL model. The ServiceInfo objects
@@ -82,7 +86,7 @@
  * the code creates a new definition element (i.e., Definition object), and imports it into
  * the top-level object.
  */
-public final class ServiceWSDLBuilder {
+public class ServiceWSDLBuilder {
     
     private final Map<String, String> ns2prefix;
     private Definition definition;
@@ -224,6 +228,39 @@
             }
         }
     }
+    
+    /**
+     * For a schema, require all namespace with prefixes to be imported. In theory,
+     * if a namespace has a prefix but is not used, the import is not needed, and could
+     * cause a problem. In practice, the code generating these schemas should not be adding
+     * spurious prefixes. Hypothetically, we could check that, in the overall WSDL, that
+     * all of the schemas that we are importing are accounted for. However, that's a validation
+     * that is best left to the validator.
+     * @param schemaInfo Schema to process.
+     */
+    protected void addRequiredSchemaImports(SchemaInfo schemaInfo) {
+        Element schemaElement = schemaInfo.getElement();
+        // we need an import for every namespace except the main one.
+        String schemaNamespace = schemaInfo.getNamespaceURI();
+        Map<String, String> queryPrefixMap = new HashMap<String, String>();
+        queryPrefixMap.put("xs", WSDLConstants.NU_SCHEMA_XSD);
+        XPathUtils xpu = new XPathUtils(queryPrefixMap);
+        NamespacePrefixList schemaPrefixes = schemaInfo.getSchema().getNamespaceContext();
+        for (String prefix : schemaPrefixes.getDeclaredPrefixes()) {
+            String namespace = schemaPrefixes.getNamespaceURI(prefix);
+            if (!namespace.equals(schemaNamespace) 
+                && !namespace.equals(WSDLConstants.NU_SCHEMA_XSD)
+                && !xpu.isExist("xs:import[@namespace='" + namespace + "']", 
+                                 schemaElement, 
+                                 XPathConstants.NODE)) {
+                Element importElement = XMLUtils.createElementNS(schemaElement.getOwnerDocument(),

+                                                                 WSDLConstants.NU_SCHEMA_XSD,
+                                                                 "import");
+                importElement.setAttribute("namespace", namespace);
+                schemaElement.insertBefore(importElement, schemaElement.getFirstChild());
+            }
+        }
+    }
 
     protected void buildTypes(final Collection<SchemaInfo> schemas,
                               final Map<String, SchemaInfo> imports,
@@ -261,6 +298,8 @@
                                
                 imports.put(name, schemaInfo);
             }
+            // add imports for those schemata which are inlined.
+            addRequiredSchemaImports(schemaInfo);
         }
         if (useSchemaImports) {
             SchemaImpl schemaImpl = new SchemaImpl();

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java?rev=587966&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/wsdl/TestCrossSchemaImports.java
Wed Oct 24 11:55:16 2007
@@ -0,0 +1,62 @@
+/**
+ * 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.systest.wsdl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.test.TestUtilities;
+import org.junit.Test;
+import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+
+
+public class TestCrossSchemaImports extends AbstractDependencyInjectionSpringContextTests
{
+
+    private TestUtilities testUtilities;
+
+    public TestCrossSchemaImports() {
+        setAutowireMode(AbstractDependencyInjectionSpringContextTests.AUTOWIRE_BY_NAME);
+        testUtilities = new TestUtilities(getClass());
+    }
+
+    @Test
+    public void testJaxbCrossSchemaImport() throws Exception {
+        testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
+        testUtilities.addDefaultNamespaces();
+        Server s = testUtilities.getServerForService(new QName("http://apache.org/type_test/doc",

+                                                               "TypeTestPortTypeService"));
+        Document wsdl = testUtilities.getWSDLDocument(s);
+        testUtilities.
+             assertValid("//xsd:schema[@targetNamespace='http://apache.org/type_test/doc']/"
+                         + "xsd:import[@namespace='http://apache.org/type_test/types1']",
wsdl);
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations()
+     */
+    @Override
+    protected String[] getConfigLocations() {
+        return new String[] {"classpath:crossSchemaBeans.xml"};
+    }
+}

Added: incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml?rev=587966&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml (added)
+++ incubator/cxf/trunk/systests/src/test/resources/crossSchemaBeans.xml Wed Oct 24 11:55:16
2007
@@ -0,0 +1,43 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:http="http://cxf.apache.org/transports/http/configuration"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
+						
+
+		
+	<!-- CXF -->
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+
+	<!-- Services -->
+	<jaxws:server id="JaxbTestServer" 
+                   serviceClass="org.apache.type_test.doc.TypeTestPortType" 
+	               address="local://TestService">
+	</jaxws:server>
+</beans>
+



Mime
View raw message