轴 ClassNotFoundException
Axis ClassNotFoundException
当我尝试 return 使用 Axis web 服务的自定义对象时出现以下错误:
aug 22, 2017 12:11:52 PM org.apache.axis.deployment.wsdd.WSDDService deployTypeMapping
SEVERE: Unable to deploy typemapping: {http://server}Case
java.lang.ClassNotFoundException: server._case
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.axis.utils.ClassUtils.run(ClassUtils.java:187)
网络服务似乎找不到我的案例class,但它在 wsdl 中定义。
这是我的代码:
案例:
package server;
import java.io.Serializable;
public class Case implements Serializable {
private static final long serialVersionUID = -1549174508068625157L;
private String id;
public Case() {
}
public Case(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
CaseServiceImpl:
package server;
public class CaseServiceImpl implements CaseService {
//This one works
@Override
public String hello(String message) {
return message;
}
//This one doesn't show up
@Override
public Case test() {
return new Case("TR-1");
}
}
CaseServiceImpl.wsdl(自动生成):
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://server" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://server" xmlns:intf="http://server" 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://server" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="test">
<complexType/>
</element>
<element name="testResponse">
<complexType>
<sequence>
<element name="testReturn" type="impl:Case"/>
</sequence>
</complexType>
</element>
<complexType name="Case">
<sequence>
<element name="id" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="hello">
<complexType>
<sequence>
<element name="message" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="helloResponse">
<complexType>
<sequence>
<element name="helloReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="testResponse">
<wsdl:part element="impl:testResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part element="impl:helloResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="helloRequest">
<wsdl:part element="impl:hello" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="testRequest">
<wsdl:part element="impl:test" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="CaseServiceImpl">
<wsdl:operation name="test">
<wsdl:input message="impl:testRequest" name="testRequest">
</wsdl:input>
<wsdl:output message="impl:testResponse" name="testResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdl:input message="impl:helloRequest" name="helloRequest">
</wsdl:input>
<wsdl:output message="impl:helloResponse" name="helloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CaseServiceImplSoapBinding" type="impl:CaseServiceImpl">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="test">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="testRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="testResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="helloRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="helloResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CaseServiceImplService">
<wsdl:port binding="impl:CaseServiceImplSoapBinding" name="CaseServiceImpl">
<wsdlsoap:address location="http://localhost:8080/MORPOC_SOAP/services/CaseServiceImpl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我觉得我错过了什么,但又不知道是什么。有人能指出我正确的方向吗?
显然我不能为我的 class 使用名称 Case,因为 case
是保留的并且它在某些时候会被取消资本化。重命名后 class 它起作用了。
看来您已经找到了解决问题的方法,但我会 post 为潜在读者提供详细步骤。希望它也有助于改进您的解决方案,因为我不确定您的问题不在于实体的命名。
先决条件:
- Ant 已安装
- Axis2 已下载并且 AXIS_HOME 环境变量已正确
在环境变量中设置
- 任何应用程序都可用于部署轴。在我的例子中,我使用了 Tomcat
Apache Tomcat/7.0.41
。要部署轴,您只需将之前下载的轴文件夹添加到 TOMCAT_HOME\webapps
文件夹中。
我使用了相同的 bean 和服务实现。所以:
Case.java
package server;
import java.io.Serializable;
public class Case implements Serializable {
private static final long serialVersionUID = -1549174508068625157L;
private String id;
public Case() {
}
public Case(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
CaseService.java
package server;
interface CaseService {
String hello(String message);
Case test();
}
CaseServiceImpl.java
package server;
public class CaseServiceImpl implements CaseService {
//This one works
@Override
public String hello(String message) {
return message;
}
//This one doesn't show up
@Override
public Case test() {
return new Case("TR-1");
}
}
创建此基础架构后,您可以根据您的服务接口生成 wsdl。转到存放编译文件的文件夹的上一级(Case.class
、CaseService.class
、CaseServiceImpl.class
)。在我们的例子中是:
和运行以下命令:
%AXIS2_HOME%\bin\java2wsdl.bat -cp . -cn server.CaseService -of CaseService.wsdl
结果如下:
将创建新文件 CaseService.wsdl
。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://server" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ax21="http://server/xsd" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" targetNamespace="http://server">
<wsdl:types>
<xs:schema xmlns:ax22="http://server/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://server">
<xs:import namespace="http://server/xsd"/>
<xs:element name="test">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="testResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax22:Case"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hello">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="helloResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://server/xsd">
<xs:complexType name="Case">
<xs:sequence>
<xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="testRequest">
<wsdl:part name="parameters" element="ns:test"/>
</wsdl:message>
<wsdl:message name="testResponse">
<wsdl:part name="parameters" element="ns:testResponse"/>
</wsdl:message>
<wsdl:message name="helloRequest">
<wsdl:part name="parameters" element="ns:hello"/>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part name="parameters" element="ns:helloResponse"/>
</wsdl:message>
<wsdl:portType name="CaseServicePortType">
<wsdl:operation name="test">
<wsdl:input message="ns:testRequest" wsaw:Action="urn:test"/>
<wsdl:output message="ns:testResponse" wsaw:Action="urn:testResponse"/>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdl:input message="ns:helloRequest" wsaw:Action="urn:hello"/>
<wsdl:output message="ns:helloResponse" wsaw:Action="urn:helloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CaseServiceSoap11Binding" type="ns:CaseServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="test">
<soap:operation soapAction="urn:test" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<soap:operation soapAction="urn:hello" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CaseServiceSoap12Binding" type="ns:CaseServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="test">
<soap12:operation soapAction="urn:test" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<soap12:operation soapAction="urn:hello" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CaseServiceHttpBinding" type="ns:CaseServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="test">
<http:operation location="test"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<http:operation location="hello"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CaseService">
<wsdl:port name="CaseServiceHttpSoap11Endpoint" binding="ns:CaseServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
<wsdl:port name="CaseServiceHttpSoap12Endpoint" binding="ns:CaseServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
<wsdl:port name="CaseServiceHttpEndpoint" binding="ns:CaseServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
现在我们可以生成 WS 组件了。从生成 CaseService.wsdl
的文件夹中执行以下命令:
%AXIS2_HOME%\bin\WSDL2Java -uri CaseService.wsdl -d adb -s -ss -sd -ssi -o service
结果如下:
并且会生成新文件夹service
。此命令还会为您的 WS 方法生成一个框架,其中应该实现的方法。所以打开 CaseServiceSkeleton.java
并实现 hello
和 test
方法。结果应该是这样的:
package server;
public class CaseServiceSkeleton implements CaseServiceSkeletonInterface {
public HelloResponse hello(Hello hello0) {
CaseService caseService = new CaseServiceImpl();
String hello = caseService.hello(hello0.getArgs0());
HelloResponse helloResponse = new HelloResponse();
helloResponse.set_return(hello);
return helloResponse;
}
public TestResponse test(Test test2) {
CaseService caseService = new CaseServiceImpl();
Case test = caseService.test();
server.xsd.Case aCase = new server.xsd.Case();
aCase.setId(test.getId());
TestResponse testResponse = new TestResponse();
testResponse.set_return(aCase);
return testResponse;
}
}
因为您依赖于 CaseService
、CaseServiceImpl
和 Case
(它们是在步骤 #1 中生成的),请将这些文件复制到 CaseServiceSkeleton.java
所在的同一文件夹中被生成。
现在您已准备好生成 *.aar
文件。它将用于 WS 部署。导航到新生成的 service
文件夹并执行 ant 命令:
ant -buildfile build.xml
结果如下:
并在 build\lib\
文件夹中创建 CaseService.aar
。
由于某些原因 Test.class
没有自动包含到 *.aar
文件中,因此需要手动添加 - 只需将 Test.class
从 build/classes
文件夹复制到新生成的 CaseService.aar
到 server
文件夹。在所有这些步骤之后 CaseService.aar\server
文件夹应该如下所示:
现在您可以将其部署到 axis - 只需将其复制到 axis Web 应用程序中的 WEB-INF\services\
。一个你启动应用程序服务器的新服务应该出现。转到 http://your_host:your_port/axis_application_name/services/listServices
。如果部署成功,应出现以下页面:
服务调用
调用所提供服务的方法有很多种。在我们的例子中,我们将使用生成的客户端存根。要生成客户端,请使用带有 wsdl 文件的文件夹中的以下命令:
%AXIS2_HOME%\bin\WSDL2Java -uri CaseService.wsdl -d adb –o client
结果如下:
此命令将生成包含两个文件的 src 文件夹:CaseServiceStub.java
和 CaseServiceCallbackHandler.java
。这些文件将由客户端应用程序使用。
现在我们已准备好创建客户端应用程序本身:
Client.java
package client;
import org.apache.axis2.AxisFault;
public class Client {
public static void main(String... args) {
try {
CaseServiceStub stub = new CaseServiceStub("http://localhost:8080/axis/services/CaseService");
invokeHelloMethod(stub);
invokeTestMethod(stub);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
public static void invokeHelloMethod(CaseServiceStub stub) {
try {
CaseServiceStub.Hello request = new CaseServiceStub.Hello();
request.setArgs0("Hello World");
CaseServiceStub.HelloResponse response = stub.hello(request);
System.out.println("Hello method says: " + response.get_return());
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
}
public static void invokeTestMethod(CaseServiceStub stub) {
try {
CaseServiceStub.Test request = new CaseServiceStub.Test();
CaseServiceStub.TestResponse response = stub.test(request);
System.out.println("Test method says: " + response.get_return().getId());
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
}
}
不要忘记在创建 CaseServiceStub
对象期间更改 WS url。在执行此 class 后的结果中,您必须获得以下输出:
Hello method says: Hello World
Test method says: TR-1
希望这会帮助人们执行您的示例:)
当我尝试 return 使用 Axis web 服务的自定义对象时出现以下错误:
aug 22, 2017 12:11:52 PM org.apache.axis.deployment.wsdd.WSDDService deployTypeMapping
SEVERE: Unable to deploy typemapping: {http://server}Case
java.lang.ClassNotFoundException: server._case
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.axis.utils.ClassUtils.run(ClassUtils.java:187)
网络服务似乎找不到我的案例class,但它在 wsdl 中定义。
这是我的代码: 案例:
package server;
import java.io.Serializable;
public class Case implements Serializable {
private static final long serialVersionUID = -1549174508068625157L;
private String id;
public Case() {
}
public Case(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
CaseServiceImpl:
package server;
public class CaseServiceImpl implements CaseService {
//This one works
@Override
public String hello(String message) {
return message;
}
//This one doesn't show up
@Override
public Case test() {
return new Case("TR-1");
}
}
CaseServiceImpl.wsdl(自动生成):
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://server" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://server" xmlns:intf="http://server" 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://server" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="test">
<complexType/>
</element>
<element name="testResponse">
<complexType>
<sequence>
<element name="testReturn" type="impl:Case"/>
</sequence>
</complexType>
</element>
<complexType name="Case">
<sequence>
<element name="id" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="hello">
<complexType>
<sequence>
<element name="message" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="helloResponse">
<complexType>
<sequence>
<element name="helloReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="testResponse">
<wsdl:part element="impl:testResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part element="impl:helloResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="helloRequest">
<wsdl:part element="impl:hello" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="testRequest">
<wsdl:part element="impl:test" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="CaseServiceImpl">
<wsdl:operation name="test">
<wsdl:input message="impl:testRequest" name="testRequest">
</wsdl:input>
<wsdl:output message="impl:testResponse" name="testResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdl:input message="impl:helloRequest" name="helloRequest">
</wsdl:input>
<wsdl:output message="impl:helloResponse" name="helloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CaseServiceImplSoapBinding" type="impl:CaseServiceImpl">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="test">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="testRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="testResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="helloRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="helloResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CaseServiceImplService">
<wsdl:port binding="impl:CaseServiceImplSoapBinding" name="CaseServiceImpl">
<wsdlsoap:address location="http://localhost:8080/MORPOC_SOAP/services/CaseServiceImpl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我觉得我错过了什么,但又不知道是什么。有人能指出我正确的方向吗?
显然我不能为我的 class 使用名称 Case,因为 case
是保留的并且它在某些时候会被取消资本化。重命名后 class 它起作用了。
看来您已经找到了解决问题的方法,但我会 post 为潜在读者提供详细步骤。希望它也有助于改进您的解决方案,因为我不确定您的问题不在于实体的命名。
先决条件:
- Ant 已安装
- Axis2 已下载并且 AXIS_HOME 环境变量已正确 在环境变量中设置
- 任何应用程序都可用于部署轴。在我的例子中,我使用了 Tomcat
Apache Tomcat/7.0.41
。要部署轴,您只需将之前下载的轴文件夹添加到TOMCAT_HOME\webapps
文件夹中。
我使用了相同的 bean 和服务实现。所以:
Case.java
package server;
import java.io.Serializable;
public class Case implements Serializable {
private static final long serialVersionUID = -1549174508068625157L;
private String id;
public Case() {
}
public Case(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
CaseService.java
package server;
interface CaseService {
String hello(String message);
Case test();
}
CaseServiceImpl.java
package server;
public class CaseServiceImpl implements CaseService {
//This one works
@Override
public String hello(String message) {
return message;
}
//This one doesn't show up
@Override
public Case test() {
return new Case("TR-1");
}
}
创建此基础架构后,您可以根据您的服务接口生成 wsdl。转到存放编译文件的文件夹的上一级(Case.class
、CaseService.class
、CaseServiceImpl.class
)。在我们的例子中是:
和运行以下命令:
%AXIS2_HOME%\bin\java2wsdl.bat -cp . -cn server.CaseService -of CaseService.wsdl
结果如下:
将创建新文件 CaseService.wsdl
。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://server" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ax21="http://server/xsd" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" targetNamespace="http://server">
<wsdl:types>
<xs:schema xmlns:ax22="http://server/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://server">
<xs:import namespace="http://server/xsd"/>
<xs:element name="test">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="testResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax22:Case"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hello">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="helloResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://server/xsd">
<xs:complexType name="Case">
<xs:sequence>
<xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="testRequest">
<wsdl:part name="parameters" element="ns:test"/>
</wsdl:message>
<wsdl:message name="testResponse">
<wsdl:part name="parameters" element="ns:testResponse"/>
</wsdl:message>
<wsdl:message name="helloRequest">
<wsdl:part name="parameters" element="ns:hello"/>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part name="parameters" element="ns:helloResponse"/>
</wsdl:message>
<wsdl:portType name="CaseServicePortType">
<wsdl:operation name="test">
<wsdl:input message="ns:testRequest" wsaw:Action="urn:test"/>
<wsdl:output message="ns:testResponse" wsaw:Action="urn:testResponse"/>
</wsdl:operation>
<wsdl:operation name="hello">
<wsdl:input message="ns:helloRequest" wsaw:Action="urn:hello"/>
<wsdl:output message="ns:helloResponse" wsaw:Action="urn:helloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CaseServiceSoap11Binding" type="ns:CaseServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="test">
<soap:operation soapAction="urn:test" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<soap:operation soapAction="urn:hello" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CaseServiceSoap12Binding" type="ns:CaseServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="test">
<soap12:operation soapAction="urn:test" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<soap12:operation soapAction="urn:hello" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CaseServiceHttpBinding" type="ns:CaseServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="test">
<http:operation location="test"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="hello">
<http:operation location="hello"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CaseService">
<wsdl:port name="CaseServiceHttpSoap11Endpoint" binding="ns:CaseServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
<wsdl:port name="CaseServiceHttpSoap12Endpoint" binding="ns:CaseServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
<wsdl:port name="CaseServiceHttpEndpoint" binding="ns:CaseServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/CaseService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
现在我们可以生成 WS 组件了。从生成 CaseService.wsdl
的文件夹中执行以下命令:
%AXIS2_HOME%\bin\WSDL2Java -uri CaseService.wsdl -d adb -s -ss -sd -ssi -o service
结果如下:
并且会生成新文件夹service
。此命令还会为您的 WS 方法生成一个框架,其中应该实现的方法。所以打开 CaseServiceSkeleton.java
并实现 hello
和 test
方法。结果应该是这样的:
package server;
public class CaseServiceSkeleton implements CaseServiceSkeletonInterface {
public HelloResponse hello(Hello hello0) {
CaseService caseService = new CaseServiceImpl();
String hello = caseService.hello(hello0.getArgs0());
HelloResponse helloResponse = new HelloResponse();
helloResponse.set_return(hello);
return helloResponse;
}
public TestResponse test(Test test2) {
CaseService caseService = new CaseServiceImpl();
Case test = caseService.test();
server.xsd.Case aCase = new server.xsd.Case();
aCase.setId(test.getId());
TestResponse testResponse = new TestResponse();
testResponse.set_return(aCase);
return testResponse;
}
}
因为您依赖于 CaseService
、CaseServiceImpl
和 Case
(它们是在步骤 #1 中生成的),请将这些文件复制到 CaseServiceSkeleton.java
所在的同一文件夹中被生成。
现在您已准备好生成 *.aar
文件。它将用于 WS 部署。导航到新生成的 service
文件夹并执行 ant 命令:
ant -buildfile build.xml
结果如下:
并在 build\lib\
文件夹中创建 CaseService.aar
。
由于某些原因 Test.class
没有自动包含到 *.aar
文件中,因此需要手动添加 - 只需将 Test.class
从 build/classes
文件夹复制到新生成的 CaseService.aar
到 server
文件夹。在所有这些步骤之后 CaseService.aar\server
文件夹应该如下所示:
现在您可以将其部署到 axis - 只需将其复制到 axis Web 应用程序中的 WEB-INF\services\
。一个你启动应用程序服务器的新服务应该出现。转到 http://your_host:your_port/axis_application_name/services/listServices
。如果部署成功,应出现以下页面:
服务调用
调用所提供服务的方法有很多种。在我们的例子中,我们将使用生成的客户端存根。要生成客户端,请使用带有 wsdl 文件的文件夹中的以下命令:
%AXIS2_HOME%\bin\WSDL2Java -uri CaseService.wsdl -d adb –o client
结果如下:
此命令将生成包含两个文件的 src 文件夹:CaseServiceStub.java
和 CaseServiceCallbackHandler.java
。这些文件将由客户端应用程序使用。
现在我们已准备好创建客户端应用程序本身:
Client.java
package client;
import org.apache.axis2.AxisFault;
public class Client {
public static void main(String... args) {
try {
CaseServiceStub stub = new CaseServiceStub("http://localhost:8080/axis/services/CaseService");
invokeHelloMethod(stub);
invokeTestMethod(stub);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
public static void invokeHelloMethod(CaseServiceStub stub) {
try {
CaseServiceStub.Hello request = new CaseServiceStub.Hello();
request.setArgs0("Hello World");
CaseServiceStub.HelloResponse response = stub.hello(request);
System.out.println("Hello method says: " + response.get_return());
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
}
public static void invokeTestMethod(CaseServiceStub stub) {
try {
CaseServiceStub.Test request = new CaseServiceStub.Test();
CaseServiceStub.TestResponse response = stub.test(request);
System.out.println("Test method says: " + response.get_return().getId());
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
}
}
不要忘记在创建 CaseServiceStub
对象期间更改 WS url。在执行此 class 后的结果中,您必须获得以下输出:
Hello method says: Hello World
Test method says: TR-1
希望这会帮助人们执行您的示例:)