首页 > 代码库 > webservice 初涉
webservice 初涉
WebService runtime modeler error: Wrapper class XXX is not found. Have you run APT to generate them
环境
MyEclipse 8.6 + JDK 1.6.31
问题
启动WebService项目出现如下异常:
严重: WSSERVLET11: failed to parse runtime descriptor: runtime modelererror: Wrapper class com.axt.service.jaxws.GetTimePoint is not found. Have yourun APT to generate them com.sun.xml.ws.model.RuntimeModelerException:runtime modeler error: Wrapper class com.axt.service.jaxws.GetTimePoint is notfound. Have you run APT to generate them atcom.sun.xml.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:285) atcom.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:596) atcom.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:543) atcom.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:370) atcom.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:256) atcom.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:322) atcom.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:188) atcom.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467) atcom.sun.xml.ws.transport.(DeploymentDescriptorParser.java:253) atcom.sun.xml.ws.transport.(DeploymentDescriptorParser.java:147) atcom.sun.xml.ws.transport.(WSServletContextListener.java:108) atorre.StandardContext.listenerStart(StandardContext.java:3843) atorre.StandardContext.start(StandardContext.java:4342) atorre.ContainerBase.addChildInternal(ContainerBase.java:791) atorre.ContainerBase.addChild(ContainerBase.java:771) atorre.StandardHost.addChild(StandardHost.java:525) atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926) atorg.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889) atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1149) atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) atorre.ContainerBase.start(ContainerBase.java:1053 atorre.StandardHost.start(StandardHost.java:719) atorre.ContainerBase.start(ContainerBase.java:1045) atorre.StandardEngine.start(StandardEngine.java:443) atorre.StandardService.start(StandardService.java:516) atorre.StandardServer.start(StandardServer.java:710) atorg.apache.catalina.startup.Catalina.start(Catalina.java:578) atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) atjava.lang.reflect.Method.invoke(Method.java:597) atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) 2012-10-25 19:23:13orre.StandardContext listenerStart 严重: Exception sending context initialized event to listener instanceof class com.sun.xml.ws.transport.ptor: runtime modeler error: Wrapperclass com.axt.service.jaxws.GetTimePoint is not found. Have you run APT togenerate them atcom.sun.xml.ws.transport.(WSServletContextListener.java:118) atorre.StandardContext.listenerStart(StandardContext.java:3843) atorre.StandardContext.start(StandardContext.java:4342) atorre.ContainerBase.addChildInternal(ContainerBase.java:791) atorre.ContainerBase.addChild(ContainerBase.java:771) atorre.StandardHost.addChild(StandardHost.java:525) atorg.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926) atorg.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889) atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1149) atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) atorre.ContainerBase.start(ContainerBase.java:1053) atorre.StandardHost.start(StandardHost.java:719) atorre.ContainerBase.start(ContainerBase.java:1045) atorre.StandardEngine.start(StandardEngine.java:443) atorre.StandardService.start(StandardService.java:516) atorre.StandardServer.start(StandardServer.java:710) atorg.apache.catalina.startup.Catalina.start(Catalina.java:578) atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) atjava.lang.reflect.Method.invoke(Method.java:597) atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by:com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapperclass com.axt.service.jaxws.GetTimePoint is not found. Have you run APT togenerate them atcom.sun.xml.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:285) atcom.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:596) atcom.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:543) atcom.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:370) atcom.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:256) atcom.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:322) atcom.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:188) atcom.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467) atcom.sun.xml.ws.transport.(DeploymentDescriptorParser.java:253) atcom.sun.xml.ws.transport.(DeploymentDescriptorParser.java:147) atcom.sun.xml.ws.transport.(WSServletContextListener.java:108) ...24 more
原因
cxf需要jaxws-api-2.1.jar及jaxb-api-2.1.jar的支持。
解决办法
1. 检查项目里是否有上述相关Jar包,如果没有,将cxf所需的2.1的jar复制一份到jdk目录下的jre\lib\endorsed文件夹中。如果endorsed文件夹不存在,可新建。
2. 项目里是有上述相关Jar包,还需要在public class XXX类上方加入@SOAPBinding(style = SOAPBinding.Style.RPC);
3. JDK升级到1.6.0.22版本以上;
接口方法:
import javax.jws.WebMethod;import javax.jws.WebService;@WebServicepublic interface HelloInt { @WebMethod public String sayHello(String name );}
实现:
import javax.jws.WebService;import javax.jws.soap.SOAPBinding;@WebService@SOAPBinding(style = SOAPBinding.Style.RPC)public class HelloImpl implements HelloInt { @Override public String sayHello(String name) { return "hello,"+name; }}
测试方法:
import javax.xml.ws.Endpoint;public class ServerTest { public static void main(String[] args) { String address = "http://192.168.1.110:8989/d01ws/hello"; Endpoint.publish(address,new HelloImpl()); System.out.println("webservice发布成功"); }}
浏览器中输入发布的地址:
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. -->-<definitions name="HelloImplService" targetNamespace="http://wa.com/"
xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://wa.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types/>
-<message name="sayHello">
<part name="arg0" type="xsd:string"/>
</message>
-<message name="sayHelloResponse">
<part name="return" type="xsd:string"/>
</message>
-<portType name="HelloImpl">
-<operation name="sayHello" parameterOrder="arg0">
<input message="tns:sayHello"/>
<output message="tns:sayHelloResponse"/>
</operation>
</portType>
-<binding name="HelloImplPortBinding" type="tns:HelloImpl">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
-<operation name="sayHello">
<soap:operation soapAction=""/>
-<input>
<soap:body namespace="http://wa.com/" use="literal"/>
</input> +<output> </operation> </binding>
-<service name="HelloImplService">
-<port name="HelloImplPort" binding="tns:HelloImplPortBinding">
<soap:address location="http://192.168.1.110:8989/d01ws/hello"/>
</port> </service>
</definitions>
在客户端调用:
新建一个java工程:
在命令窗口中编译 发布的地址,wsimport -keep http://192.168.1.110:8989/d01ws/hello?wsdl 生成的代码如下:
import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;import javax.jws.WebService;import javax.jws.soap.SOAPBinding;/** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.1.1 in JDK 6 * Generated source version: 2.1 * */@WebService(name = "HelloImpl", targetNamespace = "http://wa.com/")@SOAPBinding(style = SOAPBinding.Style.RPC)public interface HelloImpl { /** * * @param arg0 * @return * returns java.lang.String */ @WebMethod @WebResult(partName = "return") public String sayHello( @WebParam(name = "arg0", partName = "arg0") String arg0);}
import java.net.MalformedURLException;import java.net.URL;import javax.xml.namespace.QName;import javax.xml.ws.Service;import javax.xml.ws.WebEndpoint;import javax.xml.ws.WebServiceClient;import javax.xml.ws.WebServiceFeature;/** * This class was generated by the JAX-WS RI. * JAX-WS RI 2.1.1 in JDK 6 * Generated source version: 2.1 * */@WebServiceClient(name = "HelloImplService", targetNamespace = "http://wa.com/", wsdlLocation = "http://192.168.1.110:8989/d01ws/hello?wsdl")public class HelloImplService extends Service{ private final static URL HELLOIMPLSERVICE_WSDL_LOCATION; static { URL url = null; try { url = new URL("http://192.168.1.110:8989/d01ws/hello?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); } HELLOIMPLSERVICE_WSDL_LOCATION = url; } public HelloImplService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public HelloImplService() { super(HELLOIMPLSERVICE_WSDL_LOCATION, new QName("http://wa.com/", "HelloImplService")); } /** * * @return * returns HelloImpl */ @WebEndpoint(name = "HelloImplPort") public HelloImpl getHelloImplPort() { return (HelloImpl)super.getPort(new QName("http://wa.com/", "HelloImplPort"), HelloImpl.class); } /** * * @param features * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. * @return * returns HelloImpl */ @WebEndpoint(name = "HelloImplPort") public HelloImpl getHelloImplPort(WebServiceFeature... features) { return (HelloImpl)super.getPort(new QName("http://wa.com/", "HelloImplPort"), HelloImpl.class, features); }}
客户端测试:
import com.wa.HelloImpl;import com.wa.HelloImplService;public class ClientTest { public static void main(String[] args) { HelloImplService service = new HelloImplService(); HelloImpl hello =service.getHelloImplPort(); System.out.println(hello.sayHello("good")); }}
控制台输出:
hello,good.
至此,测试成功。
webservice 初涉