-
1. Re: Accessing other osgi-bundles from a POJO class
dgreco Nov 25, 2008 5:57 AM (in response to benrubio)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"> <osgix:interfaces> <value>com.progress.ps.samples.embeddedsoademo.service2.Company</value> </osgix:interfaces> <osgix:service-properties> <entry key="name" value="service2"></entry> </osgix:service-properties> </osgix:service>
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
xmlns:osgix="http://www.springframework.org/schema/osgi"
and the following schema location
xsi:schemaLocation=" 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" cardinality="0..1"/>
Here you can find a lot of information on how to export and import services using the Spring and OSGi
Hope it helps,
Regards,
David
-
2. Re: Accessing other osgi-bundles from a POJO class
benrubio Dec 8, 2008 6:42 PM (in response to dgreco)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