使用Axis2 wsdl2java生成的异常类不会扩展Exception [英] Exception classes generated using Axis2 wsdl2java don't extend Exception

查看:96
本文介绍了使用Axis2 wsdl2java生成的异常类不会扩展Exception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wsdl2java生成客户端。 wsdl如下:

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>

我要查找的问题是要解压缩类(使用选项-u), AdminServiceException类不会扩展java.lang.Exception,因此代码无法编译,因为它无法抛出该类。因此情况是这样的:

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:

如果我打包这些类(无选项-u),则该类的定义如下:

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

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

但是如果我使用选项-u,则生成类如下:

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?

编辑:

我刚刚修改了WSDL,使其更加简单。如下:

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>

我使用wsdl2java创建了代码,如下所示:

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


推荐答案

我尝试使用您的第二个wsdl使用Eclipse IDE。它生成并编译得很好。这意味着wsdl很好。
生成的 AdminServiceException.java

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;
    }
}

用于命令行 :./ wsdl2java.sh -g -ssi -uri test2.wsdl
您不必提及-u,它将为实现您所使用的绑定的数据绑定器生成单独的类。

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.

这篇关于使用Axis2 wsdl2java生成的异常类不会扩展Exception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆