Tuscany
  1. Tuscany
  2. TUSCANY-4072

Tuscany fails to retrieve XSD type/element for nested WSDL with diff namespace(wsdl resolver issue)

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: Java-SCA-2.0-Beta3
    • Fix Version/s: None
    • Labels:
      None

      Description

      This issue is found on WAS8.5 while we used tunscany wsdl model resolver to resolve one nested WSDL(diff Namespace) case:

      org.apache.tuscany.sca.interfacedef.wsdl.impl.InvalidWSDLException: Element cannot be resolved:

      {http://OrderService/OrderService/importwsdl}

      retrieveOrder
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl$WSDLPart.<init>(WSDLOperationIntrospectorImpl.java:276)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl.getMessageType(WSDLOperationIntrospectorImpl.java:194)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl.getInputType(WSDLOperationIntrospectorImpl.java:145)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLOperationIntrospectorImpl.getOperation(WSDLOperationIntrospectorImpl.java:214)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLInterfaceIntrospectorImpl.getOperation(WSDLInterfaceIntrospectorImpl.java:87)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLInterfaceIntrospectorImpl.introspectOperations(WSDLInterfaceIntrospectorImpl.java:67)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLInterfaceIntrospectorImpl.introspectPortType(WSDLInterfaceIntrospectorImpl.java:78)
      at org.apache.tuscany.sca.interfacedef.wsdl.impl.WSDLFactoryImpl.createWSDLInterface(WSDLFactoryImpl.java:56)
      at com.ibm.bpmsdk.scaruntime.sca.binding.jaxws.nestedwsdl.multi.inlineschemas.NestedInlineSchemasWSDLResolverTestCase.testCreateInterfaceContract(NestedInlineSchemasWSDLResolverTestCase.java:138)
      at com.ibm.bpmsdk.scaruntime.sca.binding.jaxws.nestedwsdl.multi.inlineschemas.NestedInlineSchemasWSDLResolverTestCase.testNestedWSDLMultiInlineSchemasParsing(NestedInlineSchemasWSDLResolverTestCase.java:124)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at junit.framework.TestCase.runTest(TestCase.java:168)
      at junit.framework.TestCase.runBare(TestCase.java:134)
      at junit.framework.TestResult$1.protect(TestResult.java:110)
      at junit.framework.TestResult.runProtected(TestResult.java:128)
      at junit.framework.TestResult.run(TestResult.java:113)
      at junit.framework.TestCase.run(TestCase.java:124)
      at junit.framework.TestSuite.runTest(TestSuite.java:232)
      at junit.framework.TestSuite.run(TestSuite.java:227)
      at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

        Activity

        Hide
        ant elder added a comment -

        Thanks for the update Robin, I've committed the updated fix and test after the IM chat we had. I do still get some asserts failing in the test even with the fix applied so i've commented them out with the comment "// TODO: fails", could you take a look and see why they are failing? The testcase is at: https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/testing/itest/nested-wsdl/

        Show
        ant elder added a comment - Thanks for the update Robin, I've committed the updated fix and test after the IM chat we had. I do still get some asserts failing in the test even with the fix applied so i've commented them out with the comment "// TODO: fails", could you take a look and see why they are failing? The testcase is at: https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/testing/itest/nested-wsdl/
        Hide
        Robin Yu added a comment -

        I have fixed this issue by changing WSDLModelResolver a little, following is my code changes:
        — WSDLModelResolver.2.java 2012-11-01 12:57:07.126258951 +0800
        +++ WSDLModelResolver.2.java.new 2012-10-30 10:01:16.000000000 +0800
        @@ -22,6 +22,7 @@
        import java.io.IOException;
        import java.io.InputStream;
        import java.net.URI;
        +import java.net.URISyntaxException;
        import java.net.URL;
        import java.util.ArrayList;
        import java.util.Arrays;
        @@ -493,7 +494,7 @@
        reader.setExtensionRegistry(wsdlExtensionRegistry); // use a custom registry

        // Collection of namespace,location for wsdl:import definition

        • Map<String, String> wsdlImports = indexRead(artifactURL);
          + Map<String, String> wsdlImports = indexRead(artifactURL, context);
          wsdlImports.putAll(wsdlDef.getWsdliLocations());
          WSDLLocatorImpl locator = new WSDLLocatorImpl(context, artifactURL, is, wsdlImports);
          Definition definition = reader.readWSDL(locator);
          @@ -641,7 +642,7 @@
        • @throws IOException
        • @throws XMLStreamException
          */
        • protected Map<String, String> indexRead(URL doc) throws IOException, XMLStreamException {
          + protected Map<String, String> indexRead(URL doc, ProcessorContext context) throws IOException, XMLStreamException {

        Map<String, String> wsdlImports = new HashMap<String, String>();
        InputStream is = doc.openStream();
        @@ -653,12 +654,31 @@
        XMLStreamReader reader = inputFactory.createXMLStreamReader(wsdlSource);

        int eventType = reader.getEventType();
        + int index = 0;
        while (true) {
        if (eventType == XMLStreamConstants.START_ELEMENT) {
        if (WSDL11_IMPORT.equals(reader.getName()))

        { String ns = reader.getAttributeValue(null, "namespace"); String loc = reader.getAttributeValue(null, "location"); wsdlImports.put(ns, loc); + }

        else if (WSDLDocumentProcessor.XSD.equals(reader.getName())) {
        + String tns = reader.getAttributeValue(null, "targetNamespace");
        + XSDefinition xsd = xsdFactory.createXSDefinition();
        + xsd.setUnresolved(true);
        + xsd.setNamespace(tns);
        + try

        { + xsd.setLocation(URI.create(doc.toURI() + "#" + index)); + }

        catch (URISyntaxException e)

        { + //TODO + e.printStackTrace(); + }

        + index ++;
        + // The definition is marked as resolved but not loaded
        + xsd.setUnresolved(false);
        + xsd.setSchema(null);
        + if (contribution != null)

        { + contribution.getModelResolver().addModel(xsd, context); + }

        }
        }
        if (reader.hasNext())

        { @@ -667,6 +687,17 @@ break; }

        }
        + if (index == 0) {
        + XSDefinition xsd = xsdFactory.createXSDefinition();
        + xsd.setUnresolved(true);
        + xsd.setNamespace("http://www.w3.org/2001/XMLSchema");
        + xsd.setUnresolved(false);
        + xsd.setSchema(null);
        + if (contribution != null)

        { + contribution.getModelResolver().removeModel(xsd, context); + contribution.getModelResolver().addModel(xsd, context); + }

        + }
        return wsdlImports;
        } finally {
        is.close();

        Show
        Robin Yu added a comment - I have fixed this issue by changing WSDLModelResolver a little, following is my code changes: — WSDLModelResolver.2.java 2012-11-01 12:57:07.126258951 +0800 +++ WSDLModelResolver.2.java.new 2012-10-30 10:01:16.000000000 +0800 @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -493,7 +494,7 @@ reader.setExtensionRegistry(wsdlExtensionRegistry); // use a custom registry // Collection of namespace,location for wsdl:import definition Map<String, String> wsdlImports = indexRead(artifactURL); + Map<String, String> wsdlImports = indexRead(artifactURL, context); wsdlImports.putAll(wsdlDef.getWsdliLocations()); WSDLLocatorImpl locator = new WSDLLocatorImpl(context, artifactURL, is, wsdlImports); Definition definition = reader.readWSDL(locator); @@ -641,7 +642,7 @@ @throws IOException @throws XMLStreamException */ protected Map<String, String> indexRead(URL doc) throws IOException, XMLStreamException { + protected Map<String, String> indexRead(URL doc, ProcessorContext context) throws IOException, XMLStreamException { Map<String, String> wsdlImports = new HashMap<String, String>(); InputStream is = doc.openStream(); @@ -653,12 +654,31 @@ XMLStreamReader reader = inputFactory.createXMLStreamReader(wsdlSource); int eventType = reader.getEventType(); + int index = 0; while (true) { if (eventType == XMLStreamConstants.START_ELEMENT) { if (WSDL11_IMPORT.equals(reader.getName())) { String ns = reader.getAttributeValue(null, "namespace"); String loc = reader.getAttributeValue(null, "location"); wsdlImports.put(ns, loc); + } else if (WSDLDocumentProcessor.XSD.equals(reader.getName())) { + String tns = reader.getAttributeValue(null, "targetNamespace"); + XSDefinition xsd = xsdFactory.createXSDefinition(); + xsd.setUnresolved(true); + xsd.setNamespace(tns); + try { + xsd.setLocation(URI.create(doc.toURI() + "#" + index)); + } catch (URISyntaxException e) { + //TODO + e.printStackTrace(); + } + index ++; + // The definition is marked as resolved but not loaded + xsd.setUnresolved(false); + xsd.setSchema(null); + if (contribution != null) { + contribution.getModelResolver().addModel(xsd, context); + } } } if (reader.hasNext()) { @@ -667,6 +687,17 @@ break; } } + if (index == 0) { + XSDefinition xsd = xsdFactory.createXSDefinition(); + xsd.setUnresolved(true); + xsd.setNamespace("http://www.w3.org/2001/XMLSchema"); + xsd.setUnresolved(false); + xsd.setSchema(null); + if (contribution != null) { + contribution.getModelResolver().removeModel(xsd, context); + contribution.getModelResolver().addModel(xsd, context); + } + } return wsdlImports; } finally { is.close();
        Hide
        Robin Yu added a comment -

        This is UT codes which can help to reproduce the issue.

        Show
        Robin Yu added a comment - This is UT codes which can help to reproduce the issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Robin Yu
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development