Author: gnodet
Date: Thu Sep 27 07:04:51 2007
New Revision: 580017

URL: http://svn.apache.org/viewvc?rev=580017&view=rev
Log:
SM-1011: WSDLFlattenner / SchemaCollection do not handle nested schemas 
inclusions properly

Added:
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd
   (with props)
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd
   (with props)
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd
   (with props)
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd
   (with props)
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd
   (with props)
    
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl
   (with props)
Modified:
    
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/tools/wsdl/SchemaCollection.java
    
incubator/servicemix/trunk/common/servicemix-common/src/test/java/org/apache/servicemix/common/tools/wsdl/WSDLFlattenerTest.java

Modified: 
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/tools/wsdl/SchemaCollection.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/tools/wsdl/SchemaCollection.java?rev=580017&r1=580016&r2=580017&view=diff
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/tools/wsdl/SchemaCollection.java
 (original)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/tools/wsdl/SchemaCollection.java
 Thu Sep 27 07:04:51 2007
@@ -147,7 +147,14 @@
         for (Iterator<Element> iter = includes.iterator(); iter.hasNext();) {
             Element ce = iter.next();
                String location = ce.getAttribute("schemaLocation");
-            schema.getRoot().removeChild(ce);
+            Node parentNode = ce.getParentNode();
+            Element root = schema.getRoot();
+            if (root == parentNode) { 
+                log.debug("Removing child include node: " + ce);
+                schema.getRoot().removeChild(ce);
+            } else {
+                log.warn("Skipping child include node removal: " + ce);
+            }
                if (location != null && !"".equals(location)) {
                    read(location, baseUri);
                }

Modified: 
incubator/servicemix/trunk/common/servicemix-common/src/test/java/org/apache/servicemix/common/tools/wsdl/WSDLFlattenerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/java/org/apache/servicemix/common/tools/wsdl/WSDLFlattenerTest.java?rev=580017&r1=580016&r2=580017&view=diff
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/java/org/apache/servicemix/common/tools/wsdl/WSDLFlattenerTest.java
 (original)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/java/org/apache/servicemix/common/tools/wsdl/WSDLFlattenerTest.java
 Thu Sep 27 07:04:51 2007
@@ -65,6 +65,32 @@
         PortType portType = (PortType) 
newFlat.getPortTypes().values().iterator().next();
         assertNotNull(portType);
     }
+
+    public void testIncludes() throws Exception {
+        URL resource = 
getClass().getClassLoader().getResource("includes/service.wsdl");
+        WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+        Definition definition = reader.readWSDL(null, resource.toString());
+        WSDLFlattener flattener = new WSDLFlattener(definition);
+
+        Definition flat = flattener.getDefinition(new 
QName("http://mycompany.com/nested/";, "ServiceInterface"));
+        assertNotNull(flat);
+
+        // Check that the definition is really standalone
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
+        writer.writeWSDL(flat, baos);
+
+        logger.info(baos.toString());
+
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        Document description = factory.newDocumentBuilder().parse(new 
ByteArrayInputStream(baos.toByteArray()));
+        Definition newFlat = 
WSDLFactory.newInstance().newWSDLReader().readWSDL(null, description);
+        assertNotNull(newFlat);
+        assertEquals(1, newFlat.getPortTypes().size());
+        PortType portType = (PortType) 
newFlat.getPortTypes().values().iterator().next();
+        assertNotNull(portType);
+    }
     
     public void testResolve() throws Exception {
         URI base = 
URI.create("jar:file:/C:/java/servicemix/servicemix-assembly/target/incubator-servicemix-3.0-SNAPSHOT/bin/incubator-servicemix-3.0-SNAPSHOT/bin/../lib/optional/servicemix-wsn2005-3.0-SNAPSHOT.jar!/org/apache/servicemix/wsn/wsn.wsdl");

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+       targetNamespace="http://mycompany.com/nested/types";
+       xmlns:tns="http://mycompany.com/nested/types";
+       elementFormDefault="qualified">
+       <include schemaLocation="nested-b1.xsd" />
+    <include schemaLocation="nested-b2.xsd" />
+    <include schemaLocation="nested-b3.xsd" />
+       <complexType name="response">
+               <sequence>
+                       <element name="person" type="tns:person"></element>
+                       <element name="approved" type="boolean"></element>
+               </sequence>
+       </complexType>
+</schema>
\ No newline at end of file

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-a1.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+       targetNamespace="http://mycompany.com/nested/types";
+       xmlns:tns="http://mycompany.com/nested/types";
+       elementFormDefault="qualified">
+       <include schemaLocation="nested-c1.xsd" />
+       <complexType name="request">
+               <sequence>
+                       <element name="targetPerson" 
type="tns:person"></element>
+                       <element name="date" type="date"></element>
+               </sequence>
+       </complexType>
+</schema>
\ No newline at end of file

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b1.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+       targetNamespace="http://mycompany.com/nested/types";
+       xmlns:tns="http://mycompany.com/nested/types";
+       elementFormDefault="qualified">
+       <complexType name="car">
+               <sequence>
+                       <element name="color" type="string"></element>
+                       <element name="make" type="string"></element>
+               </sequence>
+       </complexType>
+</schema>
\ No newline at end of file

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b2.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+       targetNamespace="http://mycompany.com/nested/types";
+       xmlns:tns="http://mycompany.com/nested/types";
+       elementFormDefault="qualified">
+       <complexType name="pet">
+               <sequence>
+                       <element name="name" type="string"></element>
+                       <element name="kind" type="string"></element>
+               </sequence>
+       </complexType>
+</schema>
\ No newline at end of file

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-b3.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+       targetNamespace="http://mycompany.com/nested/types";
+       xmlns:tns="http://mycompany.com/nested/types";
+       elementFormDefault="qualified">
+       <complexType name="person">
+               <sequence>
+                       <element name="firstName" type="string"></element>
+                       <element name="lastName" type="string"></element>
+               </sequence>
+       </complexType>
+</schema>
\ No newline at end of file

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/nested-c1.xsd
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl?rev=580017&view=auto
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl
 Thu Sep 27 07:04:51 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
+       xmlns:tns="http://mycompany.com/nested/";
+       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema"; name="NestedExampleService"
+       xmlns:typens="http://mycompany.com/nested/types";
+       targetNamespace="http://mycompany.com/nested/";>
+       <wsdl:types>
+               <xsd:schema targetNamespace="http://mycompany.com/nested/";>
+                       <xsd:import 
namespace="http://mycompany.com/nested/types";
+                               schemaLocation="nested-a1.xsd" />
+                       <xsd:element name="exampleRequest" 
type="typens:request"/>
+                       <xsd:element name="exampleResponse" 
type="typens:response"/>
+               </xsd:schema>
+       </wsdl:types>
+
+       <wsdl:message name="request">
+               <wsdl:part name="parameters" 
element="tns:exampleRequest"></wsdl:part>
+       </wsdl:message>
+       <wsdl:message name="response">
+               <wsdl:part name="parameters" 
element="tns:exampleResponse"></wsdl:part>
+       </wsdl:message>
+
+       <wsdl:portType name="ServiceInterface">
+               <wsdl:operation name="exampleOperation">
+                       <wsdl:input message="tns:request" />
+                       <wsdl:output message="tns:response" />
+               </wsdl:operation>
+
+       </wsdl:portType>
+       <wsdl:binding name="serviceSOAP" type="tns:ServiceInterface">
+               <soap:binding style="document"
+                       transport="http://schemas.xmlsoap.org/soap/http"; />
+               <wsdl:operation name="exampleOperation">
+                       <soap:operation
+                               
soapAction="http://mycompany.com/nested/exampleOperation"; />
+                       <wsdl:input>
+                               <soap:body use="literal" />
+                       </wsdl:input>
+                       <wsdl:output>
+                               <soap:body use="literal" />
+                       </wsdl:output>
+               </wsdl:operation>
+       </wsdl:binding>
+       <wsdl:service name="NestedExampleService">
+               <wsdl:port binding="tns:serviceSOAP" name="serviceSOAP">
+                       <soap:address location="http://localhost:8192/nested/"; 
/>
+               </wsdl:port>
+
+       </wsdl:service>
+</wsdl:definitions>

Propchange: 
incubator/servicemix/trunk/common/servicemix-common/src/test/resources/includes/service.wsdl
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to