使用Axis2生成的异常类wsdl2java不会扩展Exception

时间:2012-03-22 18:37:58

标签: exception axis2 wsdl2java

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

    <?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,因此代码不能编译,因为它不能抛出那个班。所以情况是这样的:

如果我打包类(没有选项-u),则该类定义如下:

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

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

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

这是不正确的,因为它不能被抛出。有什么想法吗?

编辑:

我刚刚修改了WSDL以使其更简单。它如下:

<?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创建了代码,如下所示:

/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'.

但是当我尝试编译代码时:

/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

3 个答案:

答案 0 :(得分:0)

wsdl2java应该已经为服务类生成了一个框架类和/或接口。检查骨架以查看相关服务功能的声明方式。您可能会发现他们被宣布为抛出AdminServiceExceptionException之类的东西。出于某种原因,Axis2根据WSDL中的错误定义创建了一个类,然后是另一个扩展Exception的类,它充当第一个类的容器。

答案 1 :(得分:0)

我尝试使用Eclipse IDE为您的第二个wsdl生成客户端。它生成并编译得很好。这意味着wsdl很不错。 生成 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,它将为实现您已使用的绑定的数据工具生成单独的类。

答案 2 :(得分:0)

如果您使用的是JAXB数据绑定(JAXBRI),则必须确保以下元素中的wsdl:message name(AdminServiceException):

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

与元素名称(impl:fault)不同。在你的情况下他们实际上是不同的。

否则您将得到“AdminServiceException不会扩展java.lang.Exception”错误。