4

我正在开发一个 java web 服务,我想使用 JAW-XS 注释(配置 web 服务)并使用 tomcat 7/Axis2 部署它。

但无论我尝试什么,我总是会出错。

所以在这里我的网络服务(目前只是一个基本的网络服务)带有注释:

界面

    package wtp;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface ConverterContract {

        @WebMethod float celsiusToFarenheit(float celsius);
        @WebMethod float farenheitToCelsius(float farenheit);

}

服务实施

   package wtp;

    import javax.jws.WebService;

    @WebService(endpointInterface = "wtp.ConverterContract")
    public class Converter implements ConverterContract {

        public Converter() {

        }

        public float celsiusToFarenheit(float celsius) {
            return (celsius * 9 / 5) + 32;
        }

        public float farenheitToCelsius(float farenheit) {
            return (farenheit - 32) * 5 / 9;


}
}

然后对于部署,我使用 Tomcat7 和 Axis2,Eclipse 中的服务器和运行时首选项也是如此。

因此,要使用原始 WSDL(由 JAX-WS 生成),在 service.xml 文件中将参数 useOriginalwsdl 设置为 true。但它不起作用...

所以这是我在 tomcat 上启动 Web 服务时的输出:

输出

juil. 11, 2013 11:38:55 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\VisualSVN\bin;C:\Program Files\TortoiseSVN\bin;C:\Users\f_gil\Documents\eclipse-jee-kepler-R-win32\eclipse;;.
juil. 11, 2013 11:38:55 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ConverterProj' did not find a matching property.
juil. 11, 2013 11:38:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
juil. 11, 2013 11:38:55 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
juil. 11, 2013 11:38:55 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 278 ms
juil. 11, 2013 11:38:55 AM org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
juil. 11, 2013 11:38:55 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
[ERROR] Unable to find config file.  Creating new servlet engine config file: /WEB-INF/server-config.wsdd
[WARN] Web application uses org.apache.axis2.transport.http.AxisAdminServlet; please update web.xml to use org.apache.axis2.webapp.AxisAdminServlet instead
[INFO] Clustering has been disabled
[INFO] Deploying module: addressing-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/addressing-1.6.2.mar
[INFO] Deploying module: jaxws-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/axis2-jaxws-mar-1.6.2.mar
[INFO] Deploying module: metadataExchange-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/mex-1.6.2.mar
[INFO] Deploying module: mtompolicy-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/mtompolicy-1.6.2.mar
[INFO] Deploying module: ping-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/ping-1.6.2.mar
[INFO] Deploying module: script-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/scripting-1.6.2.mar
[INFO] Deploying module: soapmonitor-1.6.2 - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/modules/soapmonitor-1.6.2.mar
[INFO] Deploying JAXWS annotated class wtp.Converter as a service - ConverterService
[INFO] Deploying Web service: Converter - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/services/Converter/
[INFO] Deploying Web service: version-1.6.2.aar - file:/C:/Users/f_gil/Documents/Workspace/AirNavLight_WS/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ConverterProj/WEB-INF/services/version-1.6.2.aar
juil. 11, 2013 11:38:57 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
juil. 11, 2013 11:38:57 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
juil. 11, 2013 11:38:57 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1673 ms

然后是tomcat生成的http页面:

可用服务页面: 可用服务页面

现在我在 ConverterService 和 Converter 上使用 ?wsdl 得到的响应:

转换器服务?wsdl

<error>
<description>
Unable to generate WSDL 1.1 for this service
</description>
<reason>
If you wish Axis2 to automatically generate the WSDL 1.1, then please set useOriginalwsdl as false in your services.xml
</reason>
javax.xml.ws.WebServiceException: Error occurred generating WSDL file for Web service implementation class {wtp.Converter} at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.generateWsdl(JAXWSRIWSDLGenerator.java:198) at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.initialize(JAXWSRIWSDLGenerator.java:390) at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.getWSDL(JAXWSRIWSDLGenerator.java:383) at org.apache.axis2.description.AxisService.printWSDL(AxisService.java:1394) at org.apache.axis2.transport.http.ListingAgent.handleWSDLRequest(ListingAgent.java:327) at org.apache.axis2.transport.http.ListingAgent.processListService(ListingAgent.java:183) at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.sun.tools.ws.spi.WSToolsObjectFactory at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.generateWsdl(JAXWSRIWSDLGenerator.java:177) ... 24 more 
</error>

转换器?wsdl

<error>
<description>
Unable to generate WSDL 1.1 for this service
</description>
<reason>
If you wish Axis2 to automatically generate the WSDL 1.1, then please set useOriginalwsdl as false in your services.xml
</reason>
</error>

并在 ?WSDL 被击中时完成输出:

击中 ?WSDL 时输出

[ERROR] Error occurred generating WSDL file for Web service implementation class {wtp.Converter}
java.lang.ClassNotFoundException: com.sun.tools.ws.spi.WSToolsObjectFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.generateWsdl(JAXWSRIWSDLGenerator.java:177)
    at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.initialize(JAXWSRIWSDLGenerator.java:390)
    at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.getWSDL(JAXWSRIWSDLGenerator.java:383)
    at org.apache.axis2.description.AxisService.printWSDL(AxisService.java:1394)
    at org.apache.axis2.transport.http.ListingAgent.handleWSDLRequest(ListingAgent.java:327)
    at org.apache.axis2.transport.http.ListingAgent.processListService(ListingAgent.java:183)
    at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

因此,如您所见,WSDL 没有生成...

所以我的问题:

  1. 为什么在可用服务页面上,我可以看到没有指定操作的 Converter 和具有 2 个可用操作的 ConverterService?我只有一个 Web 服务:接口和实现(指定端点接口)。
  2. 那么如何在axis2中使用JAX-WS注解呢?参数“useOriginalwsdl”和“useGeneratedWSDLinJAXWS”是否相关?

我尝试通过在 Tomcat 的 bin 文件夹中添加一个 setenv.bat 文件(我在其中设置 CLASSPATH 变量)来解决此错误,但它似乎不起作用。(运行startup.bat 时没有错误)。

这是我写的 setenv.bat :

设置环境文件

set "CLASSPATH=%CLASSPATH%;C:\Program Files (x86)\Java\jdk1.7.0_25\lib\tools.jar;C:\Program Files (x86)\Java\jre7\lib\javaws.jar"

那么有人知道如何使用 JAX-WS 注释和 Axis2 吗?

抱歉,篇幅较长,但我想提供所有可用的文件/信息。谢谢

4

2 回答 2

0

有什么特别的原因您一定要开发 SOAP 服务吗?走泽西路线可能会节省一些时间和精力。Axis 版本之间存在很多问题。

回答你原来的问题 -是我以前写的一篇文章,可能会帮助你

于 2013-07-30T06:23:27.580 回答
0

I was facing the same problem. Seems like when we create a webservice using Axis2, it creates the wsdl. When you are annotating the class with @WebService annotation, JAX-WS does the same thing. I removed the annotation and created webservice for the class using Axis2, wsdl was properly created.

于 2017-06-29T02:32:49.163 回答