Enterprise Integration Zone is brought to you in partnership with:

Ouertani Slim was born in Tunisia in 1981. Now he is a software engineer since 2004 and he is Java 6 and Spring certified with 100% and 94% respectively. He is very interested in Java technology, Scala and open source projects. He believes that programming is one of the hardest jobs and most beautiful in the world. Slim has posted 32 posts at DZone. You can read more from them at their website. View Full User Profile

SCA, Newton and Spring DM

02.04.2009
| 22365 views |
  • submit to reddit

Publishing service

  • Back to impl bundle and it's Spring XML files. Declare the simple Spring bean on bundle-context.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
>

<bean id="service" class="com.jtunisie.osgi.sca.impl.Service"/>
</beans>
  • Publish it on bundle-context-osgi.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">




<osgi:service id="_service" interface="com.jtunisie.osgi.sca.IService" ref="service"/>

</beans>
The service is now published inside the local OSGi container using Spring DM.
  • Now we will expose it outside of the local container. To do this we first add a property to our exposed service to let Newton detect it. bundle-context-osgi.xml will contain.

 <osgi:service id="_service" interface="com.jtunisie.osgi.sca.IService" ref="service">
<osgi:service-properties>
<entry key="newton.sca.service" value="sca_service"/>
</osgi:service-properties>
</osgi:service>
  • Exporting Service :
Newton basically exposes services using RMI outside of the local JVM and we can use OSGi inside it. The composite file is an XML document. To edit it let's add this type to the Netbeans IDE.
  •  Go to tools-->options-->miscellaneous
  • In file extension click new and add composite add associate to it and "APPLICATION/xhtml+xml" .
  •  Open service.composite.
  •   Edit service.composite, add two services for rmi and osgi :
      <service name="sca_service_rmi" >
    <interface.java interface="com.jtunisie.osgi.sca.IService"></interface.java>
    <binding.rmi/>
    </service>
    <service name="sca_service_osgi" >
    <interface.java interface="com.jtunisie.osgi.sca.IService"></interface.java>
    <binding.osgi/>
    </service>
  •  We can use short declaration (but I didn't test it):


    <service name="sca_service_rmi" >
    <interface.java interface="com.jtunisie.osgi.sca.IService"></interface.java>
    <binding.rmi/>
    <binding.osgi/>
    </service>
  • Add our bundle as a component which is implemented using Spring:

<component name="srv">
<description>spring configuration</description>
<service name="sca_service" />
<sdm:implementation.spring />
</component>
The service name is the newton.sca.service property value spring file.
  • We have two services binding and one component. Now, add wiring services :

 <wire>
<source.uri>sca_service_rmi</source.uri>
<target.uri>srv/sca_service</target.uri>
</wire>
<wire>
<source.uri>sca_service_osgi</source.uri>
<target.uri>srv/sca_service</target.uri>
</wire>
  • Add Impl composite :

<?xml version="1.0" encoding="UTF-8"?>
<composite name="configuration"
xmlns:sdm="http://newton.cauldron.org/springdm">.
<service name="sca_service_rmi" >
<interface.java interface="com.jtunisie.osgi.sca.IService"></interface.java>
<binding.rmi/>
</service>
<service name="sca_service_osgi" >
<interface.java interface="com.jtunisie.osgi.sca.IService"></interface.java>
<binding.osgi/>
</service>
<component name="srv">
<description>spring configuration</description>
<service name="sca_service" />
<sdm:implementation.spring />
</component>
<wire>
<source.uri>sca_service_rmi</source.uri>
<target.uri>srv/sca_service</target.uri>
</wire>
<wire>
<source.uri>sca_service_osgi</source.uri>
<target.uri>srv/sca_service</target.uri>
</wire>
</composite>
  • We have finished our first composite. It publishes a service inside and outside of the JVM by configuring just three XML files.
Published at DZone with permission of its author, Slim Ouertani.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Wassim ABID replied on Wed, 2009/02/04 - 11:48am

Good work :-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.