在Karaf上部署JAX-WS作为OSGi包

时间:2015-09-17 07:15:38

标签: osgi jax-ws karaf

我尝试在Karaf上部署一个简单的JAX-WS Web服务作为OSGi包。 将Web服务导出为War文件并将其部署到Karaf的/ deploy文件夹后,我发现http://localhost:8181/HelloWebService/helloWebService

无法访问它

我的代码很简单,我只使用此https://github.com/yngwietiger/HelloWebService.git

web.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     id="WebApp_ID" version="2.5">

<display-name>jaxwsExample</display-name>

<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>

<servlet>
    <servlet-name>helloWebService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>helloWebService</servlet-name>
    <url-pattern>/helloWebService</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>com.webservices.demo.MyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/myservlet</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>120</session-timeout>
</session-config>

日志是:

2015-09-17 14:59:59,712 | INFO  | raf-4.0.1/deploy | fileinstall                      | 4 - org.apache.felix.fileinstall - 3.5.0 | Updating bundle HelloWebService / 0.0.0
2015-09-17 14:59:59,712 | INFO  | raf-4.0.1/deploy | Activator                        | 89 - org.ops4j.pax.web.pax-web-extender-war - 4.2.0 | Destroying extension for bundle HelloWebService
2015-09-17 14:59:59,716 | INFO  | raf-4.0.1/deploy | HttpServiceFactoryImpl           | 93 - org.ops4j.pax.web.pax-web-runtime - 4.2.0 | Unbinding bundle: [HelloWebService [231]]
2015-09-17 15:00:02,251 | INFO  | raf-4.0.1/deploy | HttpServiceFactoryImpl           | 93 - org.ops4j.pax.web.pax-web-runtime - 4.2.0 | Binding bundle: [HelloWebService [231]] to http service
2015-09-17 15:00:02,254 | INFO  | raf-4.0.1/deploy | fileinstall                      | 4 - org.apache.felix.fileinstall - 3.5.0 | Started bundle: webbundle:file:/E:/Software/apache-karaf-4.0.1/deploy/HelloWebService.war?Web-ContextPath=HelloWebService&Bundle-SymbolicName=HelloWebService&Bundle-Version=0.0.0
2015-09-17 15:00:02,258 | INFO  | pool-24-thread-3 | JettyServerWrapper               | 91 - org.ops4j.pax.web.pax-web-jetty - 4.2.0 | will add org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer to ServletContainerInitializers
2015-09-17 15:00:09,800 | INFO  | pool-24-thread-3 | JettyServerWrapper               | 91 - org.ops4j.pax.web.pax-web-jetty - 4.2.0 | added ServletContainerInitializer: org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer
2015-09-17 15:00:09,800 | INFO  | pool-24-thread-3 | JettyServerWrapper               | 91 - org.ops4j.pax.web.pax-web-jetty - 4.2.0 | will add org.apache.jasper.servlet.JasperInitializer to ServletContainerInitializers
2015-09-17 15:00:09,801 | INFO  | pool-24-thread-3 | JettyServerWrapper               | 91 - org.ops4j.pax.web.pax-web-jetty - 4.2.0 | Skipt org.apache.jasper.servlet.JasperInitializer, because specialized handler will be present
2015-09-17 15:00:09,806 | INFO  | pool-24-thread-3 | HttpServiceContext               | 91 - org.ops4j.pax.web.pax-web-jetty - 4.2.0 | registering context WebAppHttpContext{HelloWebService - 231}, with context-name: HelloWebService

通过使用web:list,它显示231 bundle是活动的并且一直在部署。

=============================================== =======================

如何使用OSGi部署标准JAX-WS Web服务(不是JXC,只是简单的JAX-WS Web服务)? 通过使用Karaf或建造Jetty OSGi环境或其他东西......

1 个答案:

答案 0 :(得分:0)

您提到的示例使用maven。它构建通用WAR文件,其中不包含正确的OSGi清单,并且不生成任何与JaxWS相关的内容。 为了创建公开Web服务的OSGi WAB(Web存档包),您必须使用适当的maven插件,例如: 用于WSDL生成的jaxws-maven-plugin; maven-war-plugin以及maven-bundle-plugin构建WAB。 实际上,maven-bundle-plugin可以自己构建WAB。