Search code examples
jaxbjax-wsnetbeans-7wsimport

Web service client cannot be created by JAXWS:wsimport utility


Whenever i try to create a Webservice from a wsdl url i get an Error window in Netbeans IDE. Where there is no package or reference like this.

enter image description here

Here is my stack trace.

parsing WSDL...

[ERROR] A class/interface with the same name "org.wi.link.action.Exception" is already in use. Use a class customization to resolve this conflict. line 35 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

[ERROR] (Relevant to above error) another "Exception" is generated from here. line 30 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

[ERROR] Two declarations cause a collision in the ObjectFactory class. line 35 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

[ERROR] (Related to above error) This is the other declaration.
line 30 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

[ERROR] Two declarations cause a collision in the ObjectFactory class. line 38 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

[ERROR] (Related to above error) This is the other declaration.
line 32 of file:/D:/Development/source/WebServiceProject/TestProject/src/conf/xml-resources/web-service-references/service/wsdl/urladdress/wionline/services/service.wsdl

D:\Development\source\WebServiceProject\TestProject\nbproject\jaxws-build.xml:225: wsimport failed BUILD FAILED (total time: 2 seconds)

I can also post jaxws-build.xml if required Thanks in advance.


Solution

  • Under the hood wsimport utinilty uses JAXB compiler, so actualy error is relevant to JAXB. As stated in JAXB guide, you have two options - use schemabindings or factoryMethod customization, though that depends on your WSLD and it might be not possible. Another option would be to rename conflicting types in your WSDL document.

    Based on comment below lets assume that this is your schema:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:complexType name="Exception"> 
            <xs:sequence> 
                <xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType"/>
            </xs:sequence>
        </xs:complexType> 
        <xs:element name="Exception"> 
            <xs:complexType> 
                <xs:sequence> 
                    <xs:element minOccurs="0" name="Exception" nillable="true" type="Exception"/> 
                </xs:sequence> 
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    To gernerate same errors you might run xjc compiler:

    /bin/xjc.sh schema.xsd
    

    As mentioned above easyest way to fix this issue would be to rename complex type or element name. But to make things more interesting you might define JAXB customization

    <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      version="1.0">
      <jaxb:bindings schemaLocation="schema.xsd">
        <jaxb:bindings node="//xs:complexType[@name='Exception']">
          <jaxb:factoryMethod name="TypeException"/>
          <jaxb:class name="TypeException" />
        </jaxb:bindings>
      </jaxb:bindings>
    </jaxb:bindings>
    

    And try once more:

    /bin/xjc.sh -b binding.xml schema.xsd
    

    Same binding might be supplied to wsimport utility:

    wsimport myService.wsdl -b binding.xml