1 Reply Latest reply: Mar 8, 2012 11:13 AM by Thomas Diesler RSS

Call OSGI Services from EJB

diego loro Newbie

Hi,

I'm calling an OSGI Service from a EJB3.

I correctly get the BundleContext including the MANIFEST DEPENDENCY.

When I try to get a Service from Bundle Context I get a null ServiceReference.

 

My service in osgi bundle is declared with Blueprint, like this:

     <bean id="businessBean" class="jboss.osgi.BusinessService" init-method="startup">

      </bean>

    <service id="BusinessService" interface="jboss.osgi.ServiceInterface" ref="businessBean">

        <service-properties>

            <entry key="service.exported.interfaces" value="*"/>

        </service-properties>

    </service>

 

My code in the EJB3 class is:

BundleContext bundleContext = bcp.getBundleContext();

ServiceReference ref = bundleContext.getServiceReference(ServiceInterface.class.getName());

ServiceInterface service = (ServiceInterface) bundleContext.getService(ref);

output = service.callme(input);

 

Is there something wrong in it?

Thanks a lot!

Diego

  • 1. Re: Call OSGI Services from EJB
    Thomas Diesler Master

    My orignial response to this is here.

     

    Are you using the correct BundleContext? BundleContext.getServiceReference() does a check on assignability. It would only return a reference if you ultimately can use the service associated with it. The service consumer must have a wire to the service type, otherwise you would get a CCE on BundleContext.getService()

     

    There are special and IMHO somewhat undefined rules if the system bundle context or service factories are involved.

     

    If you enable DEBUG on org.jboss.osgi you should see the details of service assignability