开发者

WSDLs generated by Axis2 services can't be read by SoapUI or WSDL2Java

开发者 https://www.devze.com 2022-12-23 12:13 出处:网络
I\'m converting some services from Apache SOAP to Axis2, so the Java service classes already exist. I created a new project in Eclipse, imported the source, made sure that the Axis2 project facets wer

I'm converting some services from Apache SOAP to Axis2, so the Java service classes already exist. I created a new project in Eclipse, imported the source, made sure that the Axis2 project facets were installed, and Axis2 emitter properties are correct. Then, in Eclipse, I selected the service class and chose "Create Web Service," choosing the Axis2 runtime. The service is up and running on my PC, and when I append "?wsdl" to the service's path, I do indeed get a WSDL that I save locally. Attempting to import this into SoapUI to build a client gives the error:

ERROR:org.apache.xmlbeans.XmlException: C:\projects\soapUI\Axis2\DALService.wsdl:0: error: src-resolve: type 'SOAPException@http://www.w3.org/2001/XMLSchema' not found.

The type it's referring to (SOAP开发者_运维百科Exception) is a holdover from the Apache SOAP services, and in the service code, I changed all "import" references in the service code (not the WSDL) from org.apache.soap.SOAPException (the old Apache SOAP package name) to javax.xml.soap.SOAPException (the Axis2 location). The code compiles and works, once I can access it, but I can't access it without generating a client. Any thoughts as to why changing the namespace of an object would keep the generated WSDLs from having the proper namespace references?


Just use the "xxx?wsdl" URL which showed up the WSDL directly in SOAP UI, looks like some XSD schemas referred in the WSDL are not being found by the SOAP UI tool, generally these tools search the schema's in the same folder, also as you have org.apache.soap.SOAPException to javax.xml.soap.SOAPException, this might have changed the namespace.

Just try using the complete URL and see the result.


Let me be the first to say I have no idea WHY any of this is the case, but my guess is the exact content of the namespace may not matter so long as they're all the same. We're not even using any special features of SOAPException, because it only blindly extends the regular Exception. Anyhow, I was able to get SoapUI to build clients from the XML by doing three things.

First, I added a section to represent the SOAPException itself, as so:

    <xs:schema xmlns:test="http://service.PROJECT.DEPARTMENT.COMPANY.com" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://DEPARTMENT.COMPANY.com/xsd">
        <xs:import namespace="http://service.PROJECT.DEPARTMENT.COMPANY.com"/>
        <xs:complexType name="SOAPException">
            <xs:complexContent>
                <xs:extension base="ns:Exception">
                    <xs:sequence/>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:schema>

Second, I added the following namespace to the wsdl:definitions block:

xmlns:im="http://DEPARTMENT.COMPANY.com/xsd"

Third, I changed the namespace referenced to the SOAPException base type (fron ns to im here) wherever it was previously referenced:

    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.ims.im.sa.homedepot.com/xsd">
        <xs:complexType name="SOAPLocatorException">
            <xs:complexContent>
                <xs:extension base="im:SOAPException">
                    <xs:sequence>
                        <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
                        <xs:element minOccurs="0" name="messageCode" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
    </xs:schema>

The XML file still doesn't validate cleanly in XMLSpy, but only because of a more esoteric reason that doesn't affect me directly (the operations, which have faults defined for the Soap11 and Soap12 bindings, don't have faults defined for the raw HTTP bindings).

Even though it works, I'm still a bit confused about the following:

  • If Axis2 knew about the SOAPException type (and it did, because it mentioned it as the base class of the other exceptions), why didn't it define it in an xs:schema block?
  • Along those same lines, why did it reference the class from an incorrect namespace when using it as the base class for another type?
  • Why do I have to set a namespace for this type as DEPARTMENT.COMPANY.com and not either an Axis2 package or the package of the service object that uses it?
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号