Exception classes generated using Axis2 wsdl2java don't extend Exception

爷,独闯天下 提交于 2019-12-08 11:31:36

问题


I'm trying to generate a client using wsdl2java. The wsdl is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://admin.ws.csd.rsa.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://admin.ws.csd.rsa.com" xmlns:intf="http://admin.ws.csd.rsa.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)-->
    <wsdl:types>
        <schema elementFormDefault="qualified" targetNamespace="http://admin.ws.csd.rsa.com" xmlns="http://www.w3.org/2001/XMLSchema">
            <element name="getUserStatus">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <complexType name="GenericRequest">
                <sequence>
                    <element name="adminID" nillable="true" type="xsd:string"/>
                    <element name="orgName" nillable="true" type="xsd:string"/>
                    <element name="userName" nillable="true" type="xsd:string"/>
                </sequence>
            </complexType>
            <complexType name="AdminRequest">
                <complexContent>
                    <extension base="impl:GenericRequest">
                        <sequence>
                            <element name="userStatus" nillable="true" type="xsd:string"/>
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>
            <element name="getUserStatusResponse">
                <complexType>
                    <sequence>
                        <element name="getUserStatusReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
            <complexType name="GenericResponse">
                <sequence>
                    <element name="status" nillable="true" type="xsd:string"/>
                </sequence>
            </complexType>
            <complexType name="UserChange">
                <sequence>
                    <element name="date" nillable="true" type="xsd:string"/>
                    <element name="description" nillable="true" type="xsd:string"/>
                    <element name="type" nillable="true" type="xsd:string"/>
                </sequence>
            </complexType>
            <complexType name="ArrayOfUserChange">
                <sequence>
                    <element maxOccurs="unbounded" minOccurs="0" name="userChangeHistory" type="impl:UserChange"/>
                </sequence>
            </complexType>
            <complexType name="AdminResponse">
                <complexContent>
                    <extension base="impl:GenericResponse">
                        <sequence>
                            <element name="userChangeHistory" nillable="true" type="impl:ArrayOfUserChange"/>
                            <element name="userStatus" nillable="true" type="xsd:string"/>
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>
            <complexType name="AdminServiceException">
                <sequence/>
            </complexType>
            <element name="fault" type="impl:AdminServiceException"/>
            <element name="unlockUser">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <element name="unlockUserResponse">
                <complexType>
                    <sequence>
                        <element name="unlockUserReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
            <element name="deleteUser">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <element name="deleteUserResponse">
                <complexType>
                    <sequence>
                        <element name="deleteUserReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
            <element name="getUserChangeHistory">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <element name="getUserChangeHistoryResponse">
                <complexType>
                    <sequence>
                        <element name="getUserChangeHistoryReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
            <element name="lockUser">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <element name="lockUserResponse">
                <complexType>
                    <sequence>
                        <element name="lockUserReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
            <element name="setUserStatus">
                <complexType>
                    <sequence>
                        <element name="in0" type="impl:AdminRequest"/>
                    </sequence>
                </complexType>
            </element>
            <element name="setUserStatusResponse">
                <complexType>
                    <sequence>
                        <element name="setUserStatusReturn" type="impl:AdminResponse"/>
                    </sequence>
                </complexType>
            </element>
        </schema>
    </wsdl:types>
    <wsdl:message name="lockUserRequest">
        <wsdl:part element="impl:lockUser" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="unlockUserRequest">
        <wsdl:part element="impl:unlockUser" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="setUserStatusRequest">
        <wsdl:part element="impl:setUserStatus" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="getUserStatusResponse">
        <wsdl:part element="impl:getUserStatusResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="getUserStatusRequest">
        <wsdl:part element="impl:getUserStatus" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="getUserChangeHistoryResponse">
        <wsdl:part element="impl:getUserChangeHistoryResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="getUserChangeHistoryRequest">
        <wsdl:part element="impl:getUserChangeHistory" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="AdminServiceException">
        <wsdl:part element="impl:fault" name="fault"/>
    </wsdl:message>
    <wsdl:message name="lockUserResponse">
        <wsdl:part element="impl:lockUserResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="deleteUserRequest">
        <wsdl:part element="impl:deleteUser" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="deleteUserResponse">
        <wsdl:part element="impl:deleteUserResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="unlockUserResponse">
        <wsdl:part element="impl:unlockUserResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="setUserStatusResponse">
        <wsdl:part element="impl:setUserStatusResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:portType name="UserAdminService">
        <wsdl:operation name="getUserStatus">
            <wsdl:input message="impl:getUserStatusRequest" name="getUserStatusRequest"/>
            <wsdl:output message="impl:getUserStatusResponse" name="getUserStatusResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
        <wsdl:operation name="unlockUser">
            <wsdl:input message="impl:unlockUserRequest" name="unlockUserRequest"/>
            <wsdl:output message="impl:unlockUserResponse" name="unlockUserResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
        <wsdl:operation name="deleteUser">
            <wsdl:input message="impl:deleteUserRequest" name="deleteUserRequest"/>
            <wsdl:output message="impl:deleteUserResponse" name="deleteUserResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
        <wsdl:operation name="getUserChangeHistory">
            <wsdl:input message="impl:getUserChangeHistoryRequest" name="getUserChangeHistoryRequest"/>
            <wsdl:output message="impl:getUserChangeHistoryResponse" name="getUserChangeHistoryResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
        <wsdl:operation name="lockUser">
            <wsdl:input message="impl:lockUserRequest" name="lockUserRequest"/>
            <wsdl:output message="impl:lockUserResponse" name="lockUserResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
        <wsdl:operation name="setUserStatus">
            <wsdl:input message="impl:setUserStatusRequest" name="setUserStatusRequest"/>
            <wsdl:output message="impl:setUserStatusResponse" name="setUserStatusResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="AdaptiveAuthenticationAdminSoapBinding" type="impl:UserAdminService">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="getUserStatus">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="getUserStatusRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="getUserStatusResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="unlockUser">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="unlockUserRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="unlockUserResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="deleteUser">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="deleteUserRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="deleteUserResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="getUserChangeHistory">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="getUserChangeHistoryRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="getUserChangeHistoryResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="lockUser">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="lockUserRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="lockUserResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="setUserStatus">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="setUserStatusRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="setUserStatusResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="UserAdminServiceService">
        <wsdl:port binding="impl:AdaptiveAuthenticationAdminSoapBinding" name="AdaptiveAuthenticationAdmin">
            <wsdlsoap:address location="http://myserver:83/AdaptiveAuthenticationAdmin/services/AdaptiveAuthenticationAdmin"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

The issue I'm finding if that want to unpack the classes (using option -u), the class AdminServiceException does not extend java.lang.Exception, and therefore the code doesn't compile, since that it can not throw that class. So the situation is like this:

If I pack the classes(no option -u), the class is defined as follows:

    public class AdminServiceException extends java.lang.Exception{....}

but if I use option -u, the class is generated as follows:

    public  class AdminServiceException
    implements org.apache.axis2.databinding.ADBBean{....}

which is not correct, since it can not be thrown. Any ideas?

EDIT:

I just modified the WSDL to make it simplier. It's as follows:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://admin.ws.csd.rsa.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://admin.ws.csd.rsa.com" xmlns:intf="http://admin.ws.csd.rsa.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)-->
    <wsdl:types>
        <schema elementFormDefault="qualified" targetNamespace="http://admin.ws.csd.rsa.com" xmlns="http://www.w3.org/2001/XMLSchema">

            <element name="myRequest">
                <complexType>
                    <sequence>
                        <element name="userName" nillable="true" type="xsd:string"/>
                    </sequence>
                </complexType>
            </element>

            <element name="myResponse">
                <complexType>
                    <sequence>
                        <element name="userStatus" nillable="true" type="xsd:string"/>
                    </sequence>
                </complexType>
            </element>

            <complexType name="AdminServiceException">
                <sequence/>
            </complexType>
            <element name="fault" type="impl:AdminServiceException"/>

        </schema>
    </wsdl:types>

    <wsdl:message name="getUserStatusResponse">
        <wsdl:part element="impl:myResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="getUserStatusRequest">
        <wsdl:part element="impl:myRequest" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="AdminServiceException">
        <wsdl:part element="impl:fault" name="fault"/>
    </wsdl:message>

    <wsdl:portType name="UserAdminService">
        <wsdl:operation name="getUserStatus">
            <wsdl:input message="impl:getUserStatusRequest" name="getUserStatusRequest"/>
            <wsdl:output message="impl:getUserStatusResponse" name="getUserStatusResponse"/>
            <wsdl:fault message="impl:AdminServiceException" name="AdminServiceException"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="AdaptiveAuthenticationAdminSoapBinding" type="impl:UserAdminService">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="getUserStatus">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="getUserStatusRequest">
                <wsdlsoap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="getUserStatusResponse">
                <wsdlsoap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="AdminServiceException">
                <wsdlsoap:fault name="AdminServiceException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>

    </wsdl:binding>
    <wsdl:service name="UserAdminServiceService">
        <wsdl:port binding="impl:AdaptiveAuthenticationAdminSoapBinding" name="AdaptiveAuthenticationAdmin">
            <wsdlsoap:address location="http://server:83/AdaptiveAuthenticationAdmin/services/AdaptiveAuthenticationAdmin"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

I created the code using wsdl2java as follows:

/opt/eco/ecoprd/axis2-1.6.1/bin >> ./wsdl2java.sh  -u -uri test2.wsdl -or
 Using AXIS2_HOME: /opt/eco/ecoprd/axis2-1.6.1
 Using JAVA_HOME:  /usr/local/jdk1.6.0_16
Retrieving document at 'test2.wsdl'.

But when I try to compile the code:

/opt/eco/ecoprd/axis2-1.6.1/bin >> javac -cp $CLASSPATH  src/com/rsa/csd/ws/admin/*.java
src/com/rsa/csd/ws/admin/Fault.java:95: cannot find symbol
symbol  : method serialize(javax.xml.namespace.QName,javax.xml.stream.XMLStreamWriter)
location: class com.rsa.csd.ws.admin.AdminServiceException
                                 localFault.serialize(MY_QNAME,xmlWriter);
                                           ^
src/com/rsa/csd/ws/admin/Fault.java:278: cannot find symbol
symbol  : method getPullParser(javax.xml.namespace.QName)
location: class com.rsa.csd.ws.admin.AdminServiceException
                return localFault.getPullParser(MY_QNAME);
                                 ^
src/com/rsa/csd/ws/admin/Fault.java:326: cannot find symbol
symbol  : variable Factory
location: class com.rsa.csd.ws.admin.AdminServiceException
                                                object.setFault(com.rsa.csd.ws.admin.AdminServiceException.Factory.parse(reader));
                                                                                                          ^
src/com/rsa/csd/ws/admin/ExtensionMapper.java:28: cannot find symbol
symbol  : variable Factory
location: class com.rsa.csd.ws.admin.AdminServiceException
                            return  com.rsa.csd.ws.admin.AdminServiceException.Factory.parse(reader);
                                                                              ^
Note: src/com/rsa/csd/ws/admin/UserAdminServiceServiceStub.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

回答1:


I tried generating client with your 2nd wsdl using Eclipse IDE. It generated and compiled all well. That means wsdl is good to go. Generated AdminServiceException.java

public class AdminServiceException extends java.lang.Exception{

    private static final long serialVersionUID = 1333311238212L;

    private com.rsa.csd.ws.admin.UserAdminServiceServiceStub.Fault faultMessage;


        public AdminServiceException() {
            super("AdminServiceException");
        }

        public AdminServiceException(java.lang.String s) {
           super(s);
        }

        public AdminServiceException(java.lang.String s, java.lang.Throwable ex) {
          super(s, ex);
        }

        public AdminServiceException(java.lang.Throwable cause) {
            super(cause);
        }


    public void setFaultMessage(com.rsa.csd.ws.admin.UserAdminServiceServiceStub.Fault msg){
       faultMessage = msg;
    }

    public com.rsa.csd.ws.admin.UserAdminServiceServiceStub.Fault getFaultMessage(){
       return faultMessage;
    }
}

For command line use : ./wsdl2java.sh -g -ssi -uri test2.wsdl You don't have to mention -u, it will generate seperate classes for databinders implementing binding you have used.




回答2:


wsdl2java should have generated a skeleton class and/or interface for the service class. Check the skeleton to see how the relevant service functions are declared. You'll probably find that they are declared to throw something like AdminServiceExceptionException. For some reason, Axis2 creates one class based on the definition of the fault in the WSDL, then another class extending Exception which acts as a container for the first class.




回答3:


Just in case you are using JAXB data binding (JAXBRI), you have to make sure that your wsdl:message name (AdminServiceException) in the following element:

<wsdl:message name="AdminServiceException">
        <wsdl:part element="impl:fault" name="fault"/>
</wsdl:message> 

is different from element name (impl:fault). In your case they actually are different.

Otherwise you will get your "AdminServiceException does not extend java.lang.Exception" error.



来源:https://stackoverflow.com/questions/9828442/exception-classes-generated-using-axis2-wsdl2java-dont-extend-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!