This example demonstrates how to develop a simple OSGi WAR bundle containing a RESTful hello world web service
The example WAR (see the war-bundle module) consists of two Jersey resources:
com.sun.jersey.samples.helloworld.HelloWorldResource
com.sun.jersey.samples.helloworld.AnotherResource
The mapping of the URI path space is presented in the following table:
URI path | Resource class | HTTP methods |
---|---|---|
/helloworld | HelloWorldResource | GET |
/another | AnotherResource | GET |
To run the example, you would need to build the WAR file and install it to an OSGi runtime (e.g. Apache Felix) together with other OSGi modules. Look at the attached functional-test module for details on the programatical runtime configuration.
After downloading and installing Felix, you can also deploy the WAR manually as shown bellow. The following steps are known to work with the Felix version 3.0.6:
%java -jar bin/felix.jar ____________________________ Welcome to Apache Felix Gogo g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.0.6) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.6.1) 3|Active | 1|Apache Felix Gogo Runtime (0.6.1) 4|Active | 1|Apache Felix Gogo Shell (0.6.1) g! install http://apache.opensourceresources.org//felix/org.apache.felix.configadmin-1.2.8.jar Bundle ID: 5 g! install http://apache.opensourceresources.org//felix/org.apache.felix.eventadmin-1.2.6.jar Bundle ID: 6 g! install http://repo2.maven.org/maven2/org/ops4j/pax/web/pax-web-jetty-bundle/0.7.1/pax-web-jetty-bundle-0.7.1.jar Bundle ID: 7 g! install http://repo2.maven.org/maven2/org/ops4j/pax/web/pax-web-extender-war/0.7.1/pax-web-extender-war-0.7.1.jar Bundle ID: 8 g! install http://download.java.net/maven/2/com/sun/jersey/jersey-core/1.5-SNAPSHOT/jersey-core-1.5-SNAPSHOT.jar Bundle ID: 9 g! install http://download.java.net/maven/2/com/sun/jersey/jersey-server/1.5-SNAPSHOT/jersey-server-1.5-SNAPSHOT.jar Bundle ID: 10 g! install file:war-bundle-1.5-SNAPSHOT.war Bundle ID: 11 g! lb START LEVEL 1 ID|State |Level|Name 0|Active | 0|System Bundle (3.0.6) 1|Active | 1|Apache Felix Bundle Repository (1.6.2) 2|Active | 1|Apache Felix Gogo Command (0.6.1) 3|Active | 1|Apache Felix Gogo Runtime (0.6.1) 4|Active | 1|Apache Felix Gogo Shell (0.6.1) 5|Installed | 1|Apache Felix Configuration Admin Service (1.2.8) 6|Installed | 1|Apache Felix EventAdmin (1.2.6) 7|Installed | 1|OPS4J Pax Web - Jetty Bundle (0.7.1) 8|Installed | 1|OPS4J Pax Web - Extender - WAR (0.7.1) 9|Installed | 1|jersey-core (1.5.0.SNAPSHOT) 10|Installed | 1|jersey-server (1.5.0.SNAPSHOT) 11|Installed | 1|Helloworld OSGi WebApp - Jersey Sample WAR (1.5.0.SNAPSHOT) g! start 5 6 7 8 9 10 11 DEBUG: EventAdmin: org.apache.felix.eventadmin.CacheSize=30 DEBUG: EventAdmin: org.apache.felix.eventadmin.ThreadPoolSize=20 DEBUG: EventAdmin: org.apache.felix.eventadmin.Timeout=5000 DEBUG: EventAdmin: org.apache.felix.eventadmin.RequireTopic=true DEBUG: EventAdmin: org.apache.felix.eventadmin.CacheSize=30 DEBUG: EventAdmin: org.apache.felix.eventadmin.ThreadPoolSize=20 DEBUG: EventAdmin: org.apache.felix.eventadmin.Timeout=5000 DEBUG: EventAdmin: org.apache.felix.eventadmin.RequireTopic=true Nov 8, 2010 12:20:11 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate INFO: Initiating Jersey application, version 'Jersey: 1.5-SNAPSHOT 10/22/2010 01:30 AM'Now both Jersey resources should become available at: