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

  • submit to reddit

Consuming The Service :

Let's use Spring annotations to consume this service in the client project
  • Add spring-osgi-annotation to pom XML dependency :

Register Activator bean in bundle-context.xml and enable annotation processor
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

<bean id="activator" class="com.jtunisie.osgi.sca.client.Activator"/>

<!-- annotation processor -->
<bean class="org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor"/>
init() method will called as default-init-method.
  • No need to bundle-context-osgi.xml, we can delete it.
  • In the Activator class we add the Spring annotation as follows:

public void setService(IService service) {
this.service = service;
Note: Filter is used to enable Newton.
  • In the composite file we add a service reference named service_ref_rmi

 <reference name="service_ref_rmi" multiplicity="0..1">
<interface.java interface="com.jtunisie.osgi.sca.IService" />
  • Declare a component named serv-test with the reference name as the newton.sca.reference filter value

  <component name="serv-test">
<description>spring configuration</description>
<reference name="service_cons" />
<sdm:implementation.spring />
  • Wire reference to component :

  • We have finished our second composite :

<?xml version="1.0" encoding="UTF-8"?>
<composite name="service_test"

<reference name="service_ref_rmi" multiplicity="0..1">
<interface.java interface="com.jtunisie.osgi.sca.IService" />
<component name="serv_test">
<description>spring configuration</description>
<reference name="service_cons" />
<sdm:implementation.spring />



Running The SCA composite :

Before starting this final step,  we need to add to folders and two files.
  • ls
bin  etc       hello                LICENSE.txt  publish-springdm-1.2.0.xml  sdk                   springdm
doc  examples  hello-config.script  lib          NOTICE.txt                  README.html           var

  • Springdm directory contains Spring 1.2 bundles and the hello bundles :

|-- aopalliance.osgi-1.0-SNAPSHOT.jar
|-- jcl104-over-slf4j-1.4.3.jar
|-- log4j.osgi-1.2.15-SNAPSHOT.jar
|-- slf4j-api-1.4.3.jar
|-- slf4j-api-1.5.2.jar
|-- slf4j-log4j12-1.4.3.jar
|-- slf4j-log4j12-1.5.2.jar
|-- spring-2.5.5.jar
|-- spring-aop-2.5.5.jar
|-- spring-beans-2.5.5.jar
|-- spring-context-2.5.5.jar
|-- spring-context-support-2.5.5.jar
|-- spring-core-2.5.5.jar
|-- spring-osgi-annotation-1.2.0-m1-SNAPSHOT.jar
|-- spring-osgi-core-1.2.0-m1.jar
|-- spring-osgi-extender-1.2.0-m1.jar
`-- spring-osgi-io-1.2.0-m1.jar
|-- client-1.0-SNAPSHOT.jar
`-- impl-1.0-SNAPSHOT.jar

  • publish-springdm-1.2.0.xml will be used to publish the Spring bundles

<?xml version="1.0" encoding="iso-8859-1"?>
<item name="spring-2.5.5.jar" path="springdm/spring-2.5.5.jar" />
<item name="spring-aop-2.5.5.jar" path="springdm/spring-aop-2.5.5.jar" />
<item name="spring-beans-2.5.5.jar" path="springdm/spring-beans-2.5.5.jar" />
<item name="spring-context-2.5.5.jar" path="springdm/spring-context-2.5.5.jar" />
<item name="spring-context-support-2.5.5.jar" path="springdm/spring-context-support-2.5.5.jar" />
<item name="spring-core-2.5.5.jar" path="springdm/spring-core-2.5.5.jar" />
<item name="spring-osgi-annotation-1.2.0-m1-SNAPSHOT.jar" path="springdm/spring-osgi-annotation-1.2.0-m1-SNAPSHOT.jar" />
<item name="spring-osgi-core-1.2.0-m1.jar" path="springdm/spring-osgi-core-1.2.0-m1.jar" />
<item name="spring-osgi-extender-1.2.0-m1.jar" path="springdm/spring-osgi-extender-1.2.0-m1.jar" />
<item name="spring-osgi-io-1.2.0-m1.jar" path="springdm/spring-osgi-io-1.2.0-m1.jar" />
<item name="aopalliance.osgi-1.0-SNAPSHOT.jar" path="springdm/aopalliance.osgi-1.0-SNAPSHOT.jar" />
<item name="jcl104-over-slf4j-1.4.3.jar" path="springdm/jcl104-over-slf4j-1.4.3.jar" />
<item name="slf4j-api-1.4.3.jar" path="springdm/slf4j-api-1.4.3.jar" />
<item name="slf4j-log4j12-1.4.3.jar" path="springdm/slf4j-log4j12-1.4.3.jar" />


  • hello-config.script contains script routines :
exec etc/scripts/single-jvm-dist-infra 
# install jini browser (optional)
installer install etc/instances/jinibrowser.composite

installer install etc/instances/server-cds.composite
system manage etc/systems/remote-container.system 

# load bundles into cds
cds scan remote /springdm
cds publish remote  publish-springdm-1.2.0.xml . 
cds scan remote /hello
  • Open two terminals and in the first one we execute :
 bin/container -fabricName=test

on the second one
 bin/container -fabricName=test instance=1

If 2 machines are used

 bin/container -fabricName=test -bindAddress=machineIP(1) -serviceLookupURLs=jini:machineIP(1)
 bin/container -fabricName=test -bindAddress=machineIP(2) -serviceLookupURLs=jini:machineIP(1) -instance=1

  • Execute hello-config.script, type it on two terminals.

>exec hello-config.script

  • On the first jvm, we will install the service implementation :

>installer install composite:sca_service

the Service is now installed and you can verify it on the jini  browser.

  • On the other jvm, we will install the client . Let's verify it presence :

>cds find ser*
>Content[service_test:{bundle.symbolic.name=client-1.0-SNAPSHOT, type=component.template, version=1.0.0.SNAPSHOT, zone=remote}]
  • Install it
> installer install composite:service_test
> Hello world!!!!
  • We get our first service message. In fact, the client bundle is downloaded in the client jvm.
  • Verify Bundles

On the client console type :

>eq ss
110 RESOLVED org.springframework.bundle.osgi.io_1.2.0.m1
111 RESOLVED org.springframework.bundle.osgi.core_1.2.0.m1
112 RESOLVED org.springframework.bundle.osgi.extensions.annotations_1.2.0.m1-SNAPSHOT
113 ACTIVE org.springframework.bundle.osgi.extender_1.2.0.m1
114 ACTIVE client-1.0-SNAPSHOT_1.0.0.SNAPSHOT

Impl bundle is downloaded too but not started. Impl bundle is downloaded because it exports the api interfaces.
On the server console type :

> eq ss 
109 RESOLVED org.springframework.bundle.spring_2.5.5
110 RESOLVED org.springframework.bundle.osgi.io_1.2.0.m1
111 RESOLVED org.springframework.bundle.osgi.core_1.2.0.m1
112 RESOLVED org.springframework.bundle.osgi.extensions.annotations_1.2.0.m1-SNAPSHOT
113 ACTIVE org.springframework.bundle.osgi.extender_1.2.0.m1
114 ACTIVE com.sun.jini.browser_2.1.0
Note : The implementation is deployed on the server and is activated.
Note : If we have split the impl on two bundles api and impl, only api bundle will be downloaded and an RMI exception may be thrown.
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.)


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.