OSGi web application not running

3.1k views Asked by At

I'm trying to figure out how to implement a web application bundle. In order to do that I created a small sample following the instructions in this tutorial. The war-file can be deployed and started but I'm not able to call any url.

The structure of the war file;

+META-INF
        MANIFEST.MF
+WEB-INF
        classes/
                fancyfoods/web/SayHello.class
                web.xml
index.html


I tried to call
localhost:8080/
localhost:8080/fancyfoods.web/index.html
localhost:8080/fancyfoods.web/SayHello
but I always get "HTTP ERROR 404"



I have no idea what's wrong. Do I need more bundles to run a web application?

Best Regard





CUT

Hello again,

thank you for your replies and sorry the confusion with my misplaced answer (I'm new to Stack Overflow). I started a new WAB-example from scratch and it still doesn't work. In order to test if the http services work in general I first implemented another bundle (not WAB) containing a servlet and a OSGi-Component that registers the servlet and the static resources. And it works! I'm able to call the html and the servlet.

Now back to my problem with my WAB. Since the non-WAB example works I assume that the war file is not OK. I invested more time to provide you the necessary information (I hope so).

The structure of my war-file is:

¦---index.html
¦
+---META-INF
¦-------MANIFEST.MF
¦
+---WEB-INF
    ¦   web.xml
    ¦
    +---classes
        +---org
            +---osgi
                +---helloworld
                    +---wab
                            HelloWorldWab.class
                            HelloWorldWabActivator.class
                            HelloWorldWabComponent.class
                            HelloWorldWabServlet.class



The MANIFEST.MF:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_09-b05 (Oracle Corporation)
Bundle-ManifestVersion: 2
Bundle-Name: org.osgi.helloworld.wab
Bundle-SymbolicName: org.osgi.helloworld.wab
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Activator: org.osgi.helloworld.wab.HelloWorldWabActivator
Bundle-ClassPath: WEB-INF/classes
Import-Package: javax.servlet, javax.servlet.http, org.osgi.framework,
  org.osgi.service.component, org.osgi.service.http, org.osgi.util.tra
 cker
Export-Package: org.osgi.helloworld.wab
Web-ContextPath: /helloworld
Webapp-Context: /helloworld



When I start & stop the bundle the methods of the HelloWorldWabActivator are invoked as aspected.

The web.xml:

<web-app>
    <!-- welcome file mapping -->
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>HelloWorldWabServlet</servlet-name>
        <servlet-class>org.osgi.helloworld.wab.HelloWorldWabServletXXX</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorldWabServlet</servlet-name>
        <url-pattern>/HelloWorldWabServlet</url-pattern>
    </servlet-mapping>
</web-app>



The OSGi server:

START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.2.1)
    1|Active     |    1|Apache Commons FileUpload (1.2.2.v20111214-1400)
    2|Active     |    1|Apache Commons IO (1.4.0.v20081110-1000)
    3|Active     |    1|Apache Felix Bundle Repository (1.6.6)
    4|Active     |    1|Apache Felix Configuration Admin Service (1.6.0)
    5|Active     |    1|Apache Felix EventAdmin (1.3.2)
    6|Active     |    1|Apache Felix File Install (3.2.6)
    7|Active     |    1|Apache Felix Gogo Command (0.12.0)
    8|Active     |    1|Apache Felix Gogo Runtime (0.10.0)
    9|Active     |    1|Apache Felix Gogo Shell (0.10.0)
   10|Active     |    1|Apache Felix Http Api (2.2.0)
   11|Active     |    1|Apache Felix Http Base (2.2.0)
   12|Active     |    1|Apache Felix Http Bridge (2.2.0)
   13|Active     |    1|Apache Felix Http Bundle (2.2.0)
   14|Active     |    1|Apache Felix Http Jetty (2.2.0)
   15|Active     |    1|Apache Felix Http Proxy (2.2.0)
   16|Active     |    1|Apache Felix Http Whiteboard (2.2.0)
   17|Active     |    1|Apache Felix Log Service (1.0.1)
   18|Active     |    1|Apache Felix Preferences Service (1.0.4)
   19|Active     |    1|Apache Felix Declarative Services (1.6.2)
   20|Active     |    1|Apache Felix Web Management Console (4.0.0)
   21|Active     |    1|JSON Implementation for Java (1.0.0.v201011060100)
   22|Active     |    1|org.osgi.helloworld.wab (1.0.0.qualifier)
   23|Active     |    1|org.osgi.helloworld.servlet (1.0.0.qualifier)

Thank you for your support

3

There are 3 answers

0
gt1111 On

I had to add the pax-web-extender-war bundle (and maybe pax-url) and dependencies to get war-style wabs to work with web.xml. To accomplish this in bndTools felix runtime in eclipse, I extracted all the jars/bundles from an up-to-date Apache ServiceMix system/ directory; imported them all into my bndTools local repository; and added all the pax and jetty bundles to my bndTools Run configuration. (You might have to track down a few additional dependencies).

0
Achim Nierbeck On

There are a couple different samples on how to get your web-application running on a OSGi-Web Container available at the pax web project, those might help you resolve your issue and get going with OSGi-WARs quickly. Pax-Web Samples Oh, and make sure you're having the WebApp-Context set.

0
rimero On

Did you also specify Web-ContextPath in your MANIFEST file?

http://www.javabeat.net/2011/11/writing-an-osgi-web-application/

Ideally you should also specify a web.xml file in your WEB-INF folder too.