Skip to main content

Web Application Osgi (WAB) and JAX-RS

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2006-06-26

I'm developing a modular application with OSGI.
The central idea is: A central Bundle defines a JAX-RS application and
A set of bundles that define resources to be dynamically attached to the JAX-RS application.
The problem is as follows:
If I define an WAB Application and define the application JAX-RS as commonly done:

@ApplicationPath ("rest")
KratosRestApplication public class extends Application {

and configure this in web.xml.

Now, I do not know how to get the instance of this application in order to manipulate dynamically the resources when these are detected in other bundles.

Now, if I use the HTTPService in the WAB application directly to register the JAX-RS aplication, I do not know how to access to resources (services) in the navigator, because /app/rest fails.

public class Activator implements BundleActivator {

    private BundleContext bc;
    private ServiceTracker tracker;
    private HttpService httpService = null;
    private KernelJaxApplication application = null;
    private ServletContainer container = null;
    public void start(BundleContext bundleContext) throws Exception {
        this.bc = bundleContext;

        System.out.println("STARTING HTTP SERVICE BUNDLE");

        this.tracker = new ServiceTracker(this.bc, HttpService.class.getName(), null) {
            public Object addingService(ServiceReference serviceRef) {
                httpService = (HttpService) super.addingService(serviceRef);
                System.out.println("HTTP SERVICE: " + httpService.getClass().getCanonicalName());

                return httpService;

            public void removedService(ServiceReference ref, Object service) {
                if (httpService == service) {
                    httpService = null;
                super.removedService(ref, service);
        System.out.println("TRACKER OPEN....");

    private void registerServlets() {
        try {
            application = new KernelJaxApplication();
            container = new ServletContainer(application);
            httpService.registerServlet("/rest", container, getJerseyServletParams(), null);
            System.out.println("HTTPSERVICE .....");
        } catch (ServletException ex) {
            Logger.getLogger(Activator.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NamespaceException ex) {
            Logger.getLogger(Activator.class.getName()).log(Level.SEVERE, null, ex);

In the pom.xml this is the bundle configuration:

                            <!-- Read all OSGi configuration info from this optional file -->
                            <!-- By default, we don't export anything -->
                            <!--Export-Package>!\*.impl.\*, \*</Export-Package-->

Any suggestions?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-05-10

You maybe should see the following,

I guess this should be helpful for you.