2 Replies Latest reply on Dec 8, 2008 6:42 PM by Benjamin Rubio

    Accessing other osgi-bundles from a POJO class

    Benjamin Rubio Newbie

      JBI components provide a way to access, from Java classes, other service-units that are published on the bus. It would be really helpful if somebody could give a brief explanation of the procedure to this with osgi bundles.


      For example. I have a JAX-WS endpoint that implements the Provider interface (works at the xml level without JAXB binding) that needs to perform an XSLT transformation on the incoming message. I already have a saxon-xslt osgi bundle that does this transformation and I would like to invoke this bundle from my Java class (the one handling the xml message).


      It seems like it should be a simple procedure, but I can't seem to find any documentation on the subject.

        • 1. Re: Accessing other osgi-bundles from a POJO class
          David Greco Newbie

          Hi Benjamin,

          this is pretty easy. The trick is to register into the OSGi service registry the reference of the object you want to access from another bundle.

          SMX4 is integrated with SpringDM and so you can register services and lookup them a la Spring way.


          <bean id="service2"  class="com.progress.ps.samples.embeddedsoademo.service2.impl.CompanyImpl" />
          <osgix:service ref="service2">
                    <entry key="name" value="service2"></entry>


          this snippet of code above shows how to register a service into the OSGi registry using SpringDM, you have to put a configuration file into the META-INF/spring directory of the bundle's jar.

          The Spring config file should contain the following namespace


          and the following schema location

                    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"

          then on the bundle client you can use similarly a Spring config file for injecting the reference to the service exposed by the other bundle:


          <osgix:reference id="MyService" interface="com.progress.ps.samples.embeddedsoademo.service2.Company"


          Here you can find a lot of information on how to export and import services using the Spring and OSGi




          Hope it helps,



          • 2. Re: Accessing other osgi-bundles from a POJO class
            Benjamin Rubio Newbie

            I tried a few examples of this little trick with the OSGI service registry and they worked fairly well. However, I now have some new doubts:


            1) What happens when I want to register more than a simple bean in the OSGI service resgistry, for example a jaxws-endpoint. I'm not sure what interface I need to use to register these type of endpoints. 


            2) How exactly would I post a message to the bus via Java code.


            In advance thank you for your help.


            Edited by: benrubio on Dec 8, 2008 6:41 PM