Details
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
<?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>
<?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>
<?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>
<?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.
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"));".
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.