Simple Web Application Bundle(WAB) in tomcat osgi implementation

I am having trouble accessing a simple WAB deployed in tomcat using servletbridge osgi implementation.

I was able to programmatically register jsp/servlets/html using HttpService using pure osgi bundles and can access this bundle. The next thing i tried was creating a separate WAB containing one html and one servlet resource, but running into some issues accessing the bundle. I tried both jarred and unjarred bundle. What I am assuming right now is that for a WAB I am not required to register my resources either programmatically or in a declarative way ???

Below is the WAB bundle which I have created. It does not contain any Http Service Tracker, just an activator to show an activation and deactivation message on console.

sample.http1

   helloworld.html

   |META-INF 
       MANIFEST.MF

   |WEB-INF
      web.xml
      |classes
           |sample
                 |http
                      Activator.class
                      HelloWorldServlet.class

Below is the MANIFEST.MF file

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: sample.http1
Bundle-SymbolicName: sample.http1
Bundle-Version: 1.0.0
Bundle-Activator: sample.http.Activator
Import-Package: javax.servlet,javax.servlet.http,org.osgi.framework, org.osgi.service.http, org.osgi.util.tracker
Bundle-ClassPath: WEB-INF/classes
Web-ContextPath: /samplehttp

Below is the code for Activator class

package sample.http;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {

    public void start(BundleContext context) throws Exception {
    System.out.println("Starting Hello World");
}
        public void stop(BundleContext context) throws Exception {
          System.out.println("Stopping Hello World");
}       
}

Below is the content of web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>sample.http.HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>
</web-app>

I then activated this bundle. And tried accessing the WAB resources as below, but i am getting a 404 page resource not found error.

http://localhost/bridge/samplehttp/helloworld.html --for the static html

http://localhost/samplehttp/helloworld.html

http://localhost/bridge/samplehttp/helloworld --for the HelloWorldServlet

http://localhost/samplehttp/helloworld

Tomcat is hosted on port 80. and i can access my other osgi bundles which are registered programmatically using HttpService. The Below osgi bundle works perfectly.

eg http://localhost/bridge/jsp-examples/helloworld.jsp

Please advice. I have referred the osgi specification document and an another blog at http://www.javabeat.net/2011/11/writing-an-osgi-web-application/


Does your embedded OSGi container setup support WABs? What kind of osgi framework is running? Is there only the HttpService available. As long as you don't have a support for WABs (eg the Felix HTTP-Service doesn't support this) you're in vain. If it's possible to change the HTTP-Service, you might consider using the Pax-Web implementation of it, it supports std. HTTP-Service, a WhiteBoard Extender for it and of course full support for WABs. The latest one even supports Servlets 3.0. Though if you're bound to an existing infrastructure, which you're not allowed to change there is nothing you can do to deploy a WAB. It's kind of "strange" to deploy a WAB in a OSGi container which itself runs inside a WAR container :-)

So basically if you want to use this scenario you probably need to do something like the following: Have a WAR application running in the Tomcat, have your OSGi services running inside the OSGi-Container inside the other WAR. Do remote HTTP calls to the services inside your OSGi-War.

链接地址: http://www.djcxy.com/p/74722.html

上一篇: OSGi Web应用程序未运行

下一篇: tomcat osgi实现中的简单Web应用程序包(WAB)