2 Replies Latest reply on Mar 12, 2013 6:05 AM by thomas.diesler

    BundleContext injection in J2EE servlet broken?

    cooperjk

      I've been trying to deploy a J2EE compliant war containing 1 simple test servlet to jboss for 2 days and I'm afraid I simply don't get it and would appreciate some help/input.

       

      17:13:33,397 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "servletosgi.war" (runtime-name: "servletosgi.war")

      17:13:33,428 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-3) JBAS018567: Deployment "deployment.servletosgi.war" is using a private module ("org.jboss.osgi.framework:main") which may be changed or removed in future versions without notice.

      17:13:33,652 ERROR [org.jboss.as.server] (management-handler-thread - 5) JBAS015870: Deploy of deployment "servletosgi.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.servletosgi.servletosgi.env.\"com.servletosgi.TestServlet\".context is missing [jboss.naming.context.java.jboss.osgi.BundleContext]"]}

       

      I've gone through all the threads related to resolving a bundlecontext from a servlet and got the impression that I'm not the only one struggling with J2EE <-> OSGI interaction.

       

      My pom.xml includes as recommended:

       

      <manifestEntries>

          <Dependencies>org.osgi.core, org.jboss.osgi.framework</Dependencies>

      </manifestEntries>

       

      and the servlet simply contains the usual:

       

      @Resource

      private BundleContext context;

       

      Resulting in the error shown above at deploy time.

       

      I'm using a fresh compiled JBoss AS 7.2.0.Final "Janus"

       

      What am I overlooking? Do I need the bundlecontext at all to access for instance a declarative service from a servlet? Or am I on the wrong track here?

        • 1. Re: BundleContext injection in J2EE servlet broken?
          cooperjk

          After putting extra debug printouts in BundleContextBindingService it became apparent that the OSGI stuff was never used at runtime. From that I could deduce that something was wrong with my "fresh build" of 7.2.0 Janus: The OSGI subsystem is by default not enabled and needs to be enabled in the list of subsystems in the build-as maven module. That put me on the wrong foot especially since deploying of bundle jars in an AS without osgi subsystem appears to be working since they end up on the list of deployments and no errors or warnings in the log.

           

          Topic closed (!?).

          • 2. Re: BundleContext injection in J2EE servlet broken?
            thomas.diesler

            You can start jboss-as-7.2.0.Final with OSGi support like this

             

            [tdiesler@localhost jboss-as-7.2.0.Final]$ bin/standalone.sh -c standalone-osgi.xml