我正在尝试使用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
我尝试使用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,它将为实现您所使用的绑定的数据绑定器生成单独的类。
wsdl2java
应该已经为服务类生成了一个骨架类和/或接口。检查骨架以查看相关服务函数是如何声明的。您可能会发现,它们被声明为抛出类似AdminServiceExceptionException
的东西。出于某种原因,Axis2基于WSDL中错误的定义创建了一个类,然后创建了另一个扩展Exception的类,作为第一个类的容器。
如果您使用JAXB数据绑定(JAXBRI),您必须确保以下元素中的wsdl:message名称(AdminServiceException):
<wsdl:message name="AdminServiceException">
<wsdl:part element="impl:fault" name="fault"/>
</wsdl:message>
与元素名称不同(impl:fault)。在你的情况下,它们实际上是不同的。
否则,您将得到"AdminServiceException未扩展java.lang.Exception"错误。