1

I've been working for a few days on a problem with a WSDL we've defined. We are using wsimport to generate code from the WSDL and then using that to run a service. During WSImport, 2 elements cannot be resolved somehow which throws warnings. Runtime however, these warnings turn into errors and we cannot run our service. How can we get rid of these warnings and therefore errors?

All pointers will be greatly appreciated.

We are using Metro 2.3 and Java 7.

The WSDL is using xsds from the HR-XML specification, but I trimmed them down to display the problem clearer.

wsimport is reporting:

    MacBook-Pro-van-Martin:WSDL-problem sunsear$ wsimport -Xnocompile -s generated "file:DummyService.wsdl"
    parsing WSDL...


    [WARNING] src-resolve: Cannot resolve the name 'hr:Assignment' to a(n) 'element declaration' component.
    line 14 of file:xsd/AssignmentRequestElement.xsd

    [WARNING] src-resolve: Cannot resolve the name 'hr:HumanResource' to a(n) 'element declaration' component.
    line 15 of file:xsd/AssignmentRequestElement.xsd


    Generating code...

WSimport is complaining about hr:Assignment and hr:HumanResource which are referenced in the AssignmentRequestElement.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://personnel.services.com/services/2013-10"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:hr="http://ns.hr-xml.org/2007-04-15"
            targetNamespace="http://personnel.services.com/services/2013-10"
            elementFormDefault="qualified" version="2013-10">

    <xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/Assignment.xsd"/>
    <xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/HumanResource.xsd"/>

    <xsd:element name="AssignmentRequestElement">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="hr:Assignment"/>
                <xsd:element ref="hr:HumanResource" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

HumanResource looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15"
            targetNamespace="http://ns.hr-xml.org/2007-04-15" elementFormDefault="qualified" version="2007-04-15">
    <xsd:complexType name="HumanResourceType">
        <xsd:sequence>
            <xsd:element name="HumanResourceId" type="xsd:string" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="HumanResource" type="HumanResourceType"/>
</xsd:schema>

Assignment looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ns.hr-xml.org/2007-04-15" elementFormDefault="qualified" version="2007-04-15">
    <xsd:complexType name="AssignmentType">
        <xsd:sequence>
            <xsd:element name="AssignmentId" type="xsd:string" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Assignment" type="AssignmentType"/>
</xsd:schema>

For completeness, this is the WSDL itself:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns="http://personnel.services.com/services/2013-10"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:hr="http://ns.hr-xml.org/2007-04-15" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  targetNamespace="http://personnel.services.com/services/2013-10">
    <wsdl:types>
        <xsd:schema
                    elementFormDefault="qualified">
            <xsd:import namespace="http://ns.hr-xml.org/2007-04-15"
                        schemaLocation="xsd/HR-XML-2_5/CPO/Acknowledgement.xsd"/>
            <xsd:import namespace="http://personnel.services.com/services/2013-10"
                        schemaLocation="xsd/AssignmentRequestElement.xsd"/>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="AssignmentRequest">
        <wsdl:documentation>A generic request of type Assignment (A) or Assignment+HumanResource (A+HR).
        </wsdl:documentation>
        <wsdl:part name="input" element="tns:AssignmentRequestElement"/>
    </wsdl:message>
    <wsdl:message name="Response">
        <wsdl:documentation>A generic response of type Acknowledgement.</wsdl:documentation>
        <wsdl:part name="output" element="hr:Acknowledgement"/>
    </wsdl:message>
    <wsdl:portType name="DummyService">
        <wsdl:operation name="ProcessAssignment">
            <wsdl:documentation>ProcessAssignment is used to send details of an Assignment
                The request message is an Assignment (A) or
                an Assignment+HumanResource (A+HR) message.
            </wsdl:documentation>
            <wsdl:input message="tns:AssignmentRequest"/>
            <wsdl:output message="tns:Response"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="SoapServiceHttpBinding" type="tns:DummyService">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="ProcessAssignment">
            <wsdlsoap:operation soapAction="https://dummy.personnel.services.com/ws/DummySoapService/ProcessAssignment"
                                style="document"/>
            <wsdl:input>
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="DummySoapService">
        <wsdl:port name="DummyServicesEndpoint" binding="tns:SoapServiceHttpBinding">
            <wsdlsoap:address location="https://dummy.personnel.services.com/ws/DummySoapService"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

The WSDL and XSDs are correct according to SoapUI and XMLSpy, they validate messages correctly.

The wsdl and xsds can be downloaded here:

https://www.dropbox.com/sh/t8klaoodjfsd772/G2MBGZxLE_

SunSear
  • 230
  • 4
  • 9
  • Ouch, going forward with this, it seems the order in which the imports are done is critical for wsimport to understand the WSDL. – SunSear Jan 03 '14 at 16:07
  • I have also many warning during wsimport, but these warnings not occured any problem. How these warnings turn into errors? What validate these files Eclipse, server etc.? – herry Jan 03 '14 at 17:33
  • 1
    We use the generated classes from wsimport to run with the Metro runtime. It generates a WSDL on the fly from the Generated classes. That WSDL is not the same as the original WSDL and causes an element to change namespace, which is incorrect. When we use the original WSDL instead of the re-generated WSDL, the Metro runtime validates the WSDL on startup and fails to parse it correctly giving the exact same errors that wsimport throws as warnings. It then does not start up correctly. – SunSear Jan 03 '14 at 18:12

1 Answers1

3

You have assigned 2 different schema-locations to the same namespaces URL. That could be the reason of this error, because now wsimport does not know where to search for hr: objects.

<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/Assignment.xsd"/>
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/HumanResource.xsd"/>

Have a look at this stackoverflow question for solving this problem: SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component

Community
  • 1
  • 1
Edwin
  • 2,671
  • 2
  • 19
  • 24
  • The use of multiple imports is one of the things I was looking at earlier, couldn't find any solution to it though. The schemas we're using are pretty darn complex and I couldn't find any way out. The feature http://apache.org/xml/features/honour-all-schemaLocations sounds like a good solution. Gonna look at how to enable this in wsimport and the Metro stack. Thanks so far! – SunSear Jan 03 '14 at 18:42
  • Argh, ok so the Xerces feature thing is not going to work, I have no access to the DocumentBuilders etc, so I cannot set that. But, this is definitely the direction, even though it's frigging hard to fix. We have 1 massive namespace (HR-xml) that contains elements that use our namespace, but our namespace also uses their elements. It's impossible to untangle. Going to have to come up with something else for this. Time for weekend now, this was really helpful so far! – SunSear Jan 03 '14 at 19:17
  • OK, the double import was definitely the cause. I had to put quite some work into the WSDLs and XSDs and the reuse in schemas is definitely not as nice now. It works though and that is requirement 1 :-D – SunSear Jan 06 '14 at 08:32