0

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.

e.g 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/

Dhirendra Khanka
  • 759
  • 1
  • 8
  • 21
  • are you really required to run your application in a Tomcat? Ever considered moving to a OSGi Container like Apache Karaf or Eclipse Virgo? – Achim Nierbeck Apr 18 '13 at 06:28
  • @AchimNierbeck I am actually trying to study an existing deployment. Osgi tomcat is the standard deployment used in SAP business object 4 tool. I am interested in adding my own bundles to it and hence i cannot change its existing structure. – Dhirendra Khanka Apr 18 '13 at 07:29

1 Answers1

0

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 (e.g. 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.

Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22
  • the OSGi container being used is Eclipse Equinox using a customized ServletBridge and it is deployed as a WAR in tomcat. the bundles are present in Tomcat6\webapps\bridge\WEB-INF\eclipse\plugins. The existing plugins created by developers and deployed in this directory are having tomcat webapps like structure e.g having web/WEB-INF and having filters and servlets defined in those web.xml. The point i read somewhere is that if your OSGi container doesn't support WAB then its not possible to use filters and define your servlets and you will have to use HttpService to register all your resources. – Dhirendra Khanka Apr 18 '13 at 09:20
  • But since i can see these bundles active and running and accessible via url, looks like they are WAB since they are using web.xml for defining some resources. But at the same time i can see that their MANIFEST.MF doesnt not contain Web-ContextPath also i cannot verify their Activator class since i do not have the source code of the existing plugins. I am not sure what i said is making enough sense, what i am trying to find out is whether the existing plugins are indeed WABs and if yes then i would like to deploy my own WABs – Dhirendra Khanka Apr 18 '13 at 09:20
  • From what you're telling me I think you just have a plain HTTP-Service running, don't know how all these "WABs" are running, or even worse, is every single war also providing a OSGi framework with it. Then I'd say this is a real strange setup ... Again, the HTTP-Service and the WAB support are compendium Services which are *not* supported just from the osgi-framework out of the box. Therefore you need some additional Services providing this features. Again it's most probably the felix-http-service + bridge you're using. --> leaving you with my previous answer :) – Achim Nierbeck Apr 18 '13 at 09:23
  • i read another article http://blog.knowhowlab.org/2010/10/osgi-tutorial-4-ways-to-activate-code.html which describes the way to pass servletcontext to the bundlecontext. However the article just present the code but no explanation as such..i am not able to find out enough resources on this WAB thing :( – Dhirendra Khanka Apr 18 '13 at 12:21
  • well, actually your scenario is the problem, not the WABs, take a look at Apache Karaf as container and Pax-Web as the used infrastructure to support WABs, HttpService etc.. The "WAB thing" as you call it, works perfectly in a valid context. So from what you are telling me here I just can say you do have an issue with your environment. The used container is just plain crap and doesn't support what you are seeking for. Regarding the article, it's a good one, still you need a valid environment. – Achim Nierbeck Apr 18 '13 at 12:27
  • i found out that this project is using webapp Discoverer from Eclipse or web xml discoverer plugin. in short my webapp activators are extending WebXmlActivator which is implementing BundleActivator. So my guess is that all resources( jsp, html, Servlets) are discovered from the bundles and then registered programmatically in the activator. – Dhirendra Khanka Apr 22 '13 at 12:35