繁体   English   中英

轴ClassNotFoundException

[英]Axis ClassNotFoundException

尝试使用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$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>

我觉得我想念什么,但我不知道。 有人可以指出我正确的方向吗?

显然,我不能在课堂上使用Case的名称,因为case是保留的,并且在某些时候没有使用case 重命名该类后,它将起作用。

看来您已经找到解决问题的方法,但是我将为潜在读者发布详细的步骤。 希望它也将有助于改善您的解决方案,因为我不确定您的问题不是实体的命名。

前提条件

  1. 已安装Ant
  2. 下载了Axis2 ,并在环境变量中正确设置了AXIS_HOME环境变量
  3. 任何应用程序均可用于部署axis。 就我而言,我使用Tomcat Apache Tomcat/7.0.41 为了部署轴,您只需要将以前下载的axis文件夹添加到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.classCaseService.classCaseServiceImpl.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并实现hellotest方法。 结果应该是这样的:

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有依赖性, CaseService CaseServiceImplCase (它们在步骤1中生成)将这些文件复制到生成CaseServiceSkeleton.java的同一文件夹中。 现在您可以生成*.aar文件了。 它将用于WS部署。 导航到新生成的service文件夹并执行ant命令:

ant -buildfile build.xml

结果如下: 在此处输入图片说明

然后在build\\lib\\文件夹中创建CaseService.aar 由于某种原因, Test.class不会自动包含在*.aar文件中,因此需要手动添加-只需将Test.classbuild/classes文件夹复制到新生成的CaseService.aarserver文件夹中即可。 完成所有这些步骤之后, CaseService.aar\\server文件夹应如下所示: 在此处输入图片说明

现在,您可以将其部署到轴上-只需将其复制到轴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.javaCaseServiceCallbackHandler.java 这些文件将由客户端应用程序使用。 现在我们准备创建客户端应用程序本身:

客户端.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对象期间, CaseServiceStub不要忘记更改WS URL。 结果,在执行完此类后,您必须获得以下输出:

Hello method says: Hello World
Test method says: TR-1

希望这将有助于人们执行您的示例:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM