2013-07-11 61 views
4

我正在研究java web服務,我想使用JAW-XS註釋(配置web服務)並將其與tomcat 7/Axis2一起部署。在Tomcat/Axis2中使用JAW-XS註釋

但是我總是會遇到一個錯誤,無論我嘗試。

所以在這裏我的web服務(這只是暫時一個基本的Web服務)與註釋:

接口

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,Server和Runti也是如此我在Eclipse中的偏好。

因此,要使用orignal WSDL(由JAX-WS生成),參數useOriginalwsdl在service.xml文件中設置爲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 

然後HTTP頁面通過tomcat的產生:

可用的服務頁面: Available service page

現在我對ConverterService WSDL和轉換器得到的迴應:??

ConverterService 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服務:接口和實現(它指定endpointInterface)。
  2. 那麼如何在axis2中使用JAX-WS註釋?參數「useOriginalwsdl」和「useGeneratedWSDLinJAXWS」是否相關?

我嘗試通過在Tomcat的bin文件夾中添加setenv.bat文件(其中我設置了CLASSPATH變量)來解決此錯誤,但似乎無法工作。 (當我運行startup.bat時沒有錯誤)。

這裏setenv.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什麼想法?

對不起,但我想提供所有可用的文件/信息。 謝謝

+0

我將在今天下午測試,僅使用JAX-WS批註創建Web服務,生成WSDL,然後使用axis2部署自頂向下的Web服務。 – Zangdak

+0

我在使用tomcat部署我的JAX-Ws Web服務時遇到了一些麻煩......我想我會重新閱讀關於Web服務如何在Java上工作的一些教程。 – Zangdak

+0

我在axis2上手動部署了web服務,但問題仍然存在......似乎axis2沒有看到XmlElement和XmlEnumValue註釋(JAXB註釋)。任何人都有這個想法? – Zangdak

回答

0

是否有任何特定的原因,你一定會開發一個SOAP服務?您可以通過Jersey路線節省一些時間和精力。 Axis版本之間存在很多問題。

要回答你原來的問題 - this是一個後我寫了一段時間回來,並可以幫助你去

+0

我沒有選擇,我需要使用SOAP服務。這是規範要求的。我會看看你的工作,謝謝。 – Zangdak

0

我面臨同樣的問題。看起來像我們使用Axis2創建Web服務時,它創建了wsdl。當您使用@WebService批註對類進行批註時,JAX-WS會執行相同的操作。我刪除了註釋並使用Axis2爲該類創建了web服務,wsdl已正確創建。