13 Replies Latest reply on Apr 10, 2012 3:31 PM by Maxym Pendyshchuk

    How to invoke the bundle osgi service from ejb3?

    Matthew Cheng Newbie

      Thougth the 1.0.0 final release shows the feature "OSGi service invocation from EJB3 and Webap" is supported, in which I think the EJB3 is deployed as JBoss AS7 modules not an OSGi bundle, but there is no clear narration in the user guide document. I do find two methods, but they do not work:

      1)  Create a JNDI entry when the bundle starts, and let the EJB3 invoke it by lookup up it from JNDI 

              ServiceReference sref = context.getServiceReference(InitialContext.class.getName());

              InitialContext initCtx = (InitialContext) context.getService(sref);


             SendDownSrv downImpl = new DownLinkImpl();


             initCtx.createSubcontext("OTAMediation").bind("sendDownSrv", downImpl);


             But the bundle can not start because the system prompts "the InitialContext is read-only".


      2) Register an instance of that service with the OSGi service registry. And use a injected bundle context in the EJB3 to invoke it, which is provided by "Thomas Diesler" in the JBoss OSGI Diary.


               InjectedValue<BundleContext> injectedBundleContext = new InjectedValue<BundleContext>();

               BundleContext systemContext = injectedBundleContext.getValue();

               ServiceReference sref = systemContext.getServiceReference(SendDownSrv.class.getName());


      But there is such exception raised when the line 2 of above codes is reached:



      at org.jboss.msc.value.InjectedValue.getValue(InjectedValue.java:47)


      So what is the true method to invoke a osgi service from an EJB3?