当我尝试使用Axis webservice返回自定义对象时收到以下错误:
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$2.run(ClassUtils.java:187)
似乎web服务无法找到我的Case类,但它在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>
我觉得我错过了一些东西,但我不知道是什么。有人能指出我正确的方向吗?
答案 0 :(得分:0)
显然我不能在我的课程中使用Case这个名称,因为case
被保留了,并且在某些时候它会被资本化。重命名课程后,它可以工作。
答案 1 :(得分:0)
您似乎已找到问题的解决方案,但我会为潜在读者发布详细步骤。希望它也有助于改进您的解决方案,因为我不确定您的问题不在于实体的命名。
<强>前提条件强>:
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
文件夹复制到新生成的{{1}到CaseService.aar
文件夹。完成所有这些步骤后,server
文件夹应如下所示:
现在您可以将其部署到轴 - 只需将其复制到轴Web应用程序中的CaseService.aar\server
即可。应该出现一个启动应用程序服务器的新服务。转到WEB-INF\services\
。如果部署成功,则应显示以下页面:
服务调用
如何使用提供的服务有很多方法。在我们的例子中,我们将使用生成的客户端存根。要生成客户端,请使用wsdl文件夹中的以下命令:
http://your_host:your_port/axis_application_name/services/listServices
此命令将生成包含两个文件的src文件夹:%AXIS2_HOME%\bin\WSDL2Java -uri CaseService.wsdl -d adb –o client
和CaseServiceStub.java
。客户端应用程序将使用这些文件。
现在我们已准备好创建客户端应用程序本身:
<强> Client.java 强>
CaseServiceCallbackHandler.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();
}
}
}
对象期间,不要忘记更改WS url。在执行此类之后的结果中,您必须得到以下输出:
CaseServiceStub
希望这会帮助人们执行你的例子:)