Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6413

WSDL Import SchemaLocation Error on Relative Path

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.11, 2.7.13, 3.1
    • Fix Version/s: 2.7.18, 3.0.7
    • Component/s: Core
    • Labels:
      None
    • Environment:

      Wildfly 8.1; Windows 7

    • Estimated Complexity:
      Moderate
    • Flags:
      Important

      Description

      When importing multiple levels of XSDs in a WSDL, the schemaLocation attribute produces an error in the translated URL.

      Folder Structure:

      wsdl
      |
      +--UserService wsdl
      |
      +--schema
           |
           +--type
           |    |
           |    +-- user
           |         |
           |         +--user xsd
           |    +-- phone
           |         |
           |         +--phone xsd
           +--xsd
               |
               +--UserService xsd
      
      UserService.wsdl
      <?xml version='1.0' encoding='UTF-8'?>
      <wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://test.com.br/integration/services/user"
      	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
      	xmlns:sch="http://test.com.br/integration/schema"
      	name="UserServiceService" targetNamespace="http://test.com.br/integration/services/user">
      	<wsdl:types>
      		<xsd:schema>
      			<xsd:import namespace="http://test.com.br/integration/schema"  schemaLocation="../schema/xsd/UserService.xsd" />
      		</xsd:schema>
      	</wsdl:types>
      
      	<wsdl:message name="helloResponse">
      		<wsdl:part element="sch:helloResponse" name="parameters" />
      	</wsdl:message>
      	<wsdl:message name="hello">
      		<wsdl:part element="sch:hello" name="parameters" />
      	</wsdl:message>
      	<wsdl:portType name="UserService">
      		<wsdl:operation name="hello">
      			<wsdl:input message="tns:hello" name="hello" />
      			<wsdl:output message="tns:helloResponse" name="helloResponse" />
      		</wsdl:operation>
      	</wsdl:portType>
      	<wsdl:binding name="UserServiceServiceSoapBinding" type="tns:UserService">
      		<soap:binding style="document"
      			transport="http://schemas.xmlsoap.org/soap/http" />
      		<wsdl:operation name="hello">
      			<soap:operation soapAction="" style="document" />
      			<wsdl:input name="hello">
      				<soap:body use="literal" />
      			</wsdl:input>
      			<wsdl:output name="helloResponse">
      				<soap:body use="literal" />
      			</wsdl:output>
      		</wsdl:operation>
      	</wsdl:binding>
      	<wsdl:service name="UserServiceService">
      		<wsdl:port binding="tns:UserServiceServiceSoapBinding" name="UserServicePort">
      			<soap:address location="http://localhost:8080/SchemaLocation/UserService" />
      		</wsdl:port>
      	</wsdl:service>
      </wsdl:definitions>
      
      UserService.xsd
      <?xml version='1.0' encoding='UTF-8'?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      	xmlns:tns="http://test.com.br/integration/schema" xmlns:ns2="http://test.com.br/integration/schema/user"
      	elementFormDefault="unqualified" targetNamespace="http://test.com.br/integration/schema"
      	version="1.0">
      
      	<xs:import namespace="http://test.com.br/integration/schema/user" schemaLocation="../type/user/user.xsd" />
      
      	<xs:element name="hello" type="tns:hello" />
      
      	<xs:element name="helloResponse" type="tns:helloResponse" />
      
      	<xs:complexType name="hello">
      		<xs:sequence>
      			<xs:element minOccurs="0" name="arg0" type="ns2:user" />
      		</xs:sequence>
      	</xs:complexType>
      
      	<xs:complexType name="helloResponse">
      		<xs:sequence>
      			<xs:element minOccurs="0" name="return" type="xs:string" />
      		</xs:sequence>
      	</xs:complexType>
      
      </xs:schema>
      
      user.xsd
      <?xml version='1.0' encoding='UTF-8'?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      	xmlns:ns1="http://test.com.br/integration/schema/phone"
      	targetNamespace="http://test.com.br/integration/schema/user" version="1.0">
      
      	<xs:import namespace="http://test.com.br/integration/schema/phone" schemaLocation="../phone/phone.xsd" />
      
      	<xs:complexType name="user">
      		<xs:sequence>
      			<xs:element minOccurs="0" name="name" type="xs:string" />
      			<xs:element minOccurs="0" name="lastName" type="xs:string" />
      			<xs:element minOccurs="0" name="phone" type="ns1:phone" />
      		</xs:sequence>
      	</xs:complexType>
      
      </xs:schema>
      
      phone.xsd
      <?xml version='1.0' encoding='UTF-8'?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      	targetNamespace="http://test.com.br/integration/schema/phone" version="1.0">
      
      	<xs:complexType name="phone">
      		<xs:sequence>
      			<xs:element minOccurs="0" name="countryCode" type="xs:int" />
      			<xs:element minOccurs="0" name="areaCode" type="xs:int" />
      			<xs:element minOccurs="0" name="number" type="xs:long" />
      		</xs:sequence>
      	</xs:complexType>
      
      </xs:schema>
      

      Error:

      When running on started server, the schemaLocation attribute in UserService.xsd don't resolve the absolute path, causing error.

      WSDLGetUtils.java

      In 2.7.7 version of CXF library, mapUri() method resolves correctly.

      mapUri()
      protected String mapUri(String base, Map<String, SchemaReference> smp, String loc)
      			throws UnsupportedEncodingException {
      		SchemaReference ref = (SchemaReference) smp.get(URLDecoder.decode(loc, "utf-8"));
      		if (ref != null) {
      			return new StringBuilder().append(base).append("?xsd=")
      					.append(ref.getSchemaLocationURI().replace(" ", "%20")).toString();
      		}
      		return null;
      	}
      

      After 2.7.7 version, for example 3.1.0 version, mapUri() was changed. The "loc" parameter is changed in this line "key = new URI(xsd).resolve(loc).toString();". After that change, the imported XSD is not found on the map "SchemaReference ref = (SchemaReference)smp.get(URLDecoder.decode(key, "utf-8"));".

      mapUri() with problem
        protected String mapUri(String base, Map<String, SchemaReference> smp, String loc, String xsd) throws UnsupportedEncodingException
        {
          String key = loc;
          try {
            boolean absoluteLocUri = new URI(loc).isAbsolute();
            if ((!absoluteLocUri) && (xsd != null)) {
              key = new URI(xsd).resolve(loc).toString();
            }
            if ((!absoluteLocUri) && (xsd == null))
              key = new URI(".").resolve(loc).toString();
          }
          catch (URISyntaxException e)
          {
          }
          SchemaReference ref = (SchemaReference)smp.get(URLDecoder.decode(key, "utf-8"));
          if (ref != null) {
            return new StringBuilder().append(base).append("?xsd=").append(key.replace(" ", "%20")).toString();
          }
          return null;
        }
      

      This error is blocking WSDL first aproach development using JBoss AS and JAX-WS.

        Attachments

        1. SchemaLocation.zip
          10 kB
          Jader da Silva Santos

          Issue Links

            Activity

              People

              • Assignee:
                asoldano Alessio Soldano
                Reporter:
                jaderss Jader da Silva Santos
              • Votes:
                2 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: