Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You could figure out that developing OSGI is similar to developp EJB components using EJB 1.0 specification. Remember that time when the only way to design an enterprise solution was to use EJB with its proxy, stub-skeleton classes, the protocol RMI/IIOP (blocked by most of the firewall) for the communication between the client and the server, ... and so on and so on

Luckily, this is not the case because the specification has tried to avoid such pitfalls of EJB spefications and because two interesting projects exist today to simplify our life :

...

Step 5 : Generate the MANIFEST.MF file and jar of the bundle

Now, that the code and the configuration files are ready, we will use maven to generate the MANIFEST.MF file describing the information about our bundle, its version n°, the package to export or import.

This command can be launched from Eclipse (if you have integrated maven within Eclipse ( more info : eclipse maven plugin)) or a Unix/Dos prompt in the folder where your pom.xml file is located.

Code Block

mvn package

If this command does not report any error, then

  • A 'MANIFEST.MF' file containing the following information is created in the folder 'META-INF' :
Code Block

Manifest-Version: 1.0
Export-Package: demo.service;uses:="org.apache.commons.logging"
Built-By: Charlesm
Build-Jdk: 1.6.0_07
Bundle-Version: 0.1.0
Tool: Bnd-0.0.238
Bundle-Name: Demo Service Bundle
Bnd-LastModified: 1228122578185
Created-By: Apache Maven Bundle Plugin
Bundle-ManifestVersion: 2
Bundle-SymbolicName: demo.demo.service-bundle
Import-Package: demo.service,org.apache.commons.logging

Remark : the pom of spring dm uses the maven bundle plugin and the tool bnd to generate this manifest file.

  • a 'demo.service-bundle-0.1.0.jar' jar is created in the folder 'target'

Step 6 : Create the Camel context file and OSGI dependency

The next step is quite simple for Camel users because we will create two configurations files, one containing the routing and the other a reference to our TransformationService deployed in a OSGI bundle.

  • For the routing, create the following file under the folder 'src/main/resources/META-INF/spring" of the project 'demo.camel-bundle'
Code Block
xml
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-2.5.xsd
       http://activemq.apache.org/camel/schema/spring
       http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="timer://myTimer?fixedRate=true&amp;period=10000"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </camelContext>
</beans>

The routing defined here is a timer who will every 10s call the POJO 'MyTransform' and send the result to the 'camel:log' component. As, you can see, this is a pure Camel config file without any reference to a OSGI bundle

  • To inject the dependency, we will create a second file named 'bundle-context-osgi.xml' in the same folder
Code Block
xml
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.xsd
  http://www.springframework.org/schema/osgi
  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
       
      <osgi:reference id="myTransform" interface="demo.service.TransformService"/>
  
</beans>

Remarks :
- The id of the bean referenced 'myTransform' used by the camel context has a reference to the OSGI interface 'demo.service.TransformService'
- How could we imagine something more simplest ? We don't have to call a JNDI server with a reference or something like that. Only a reference to the service interface.

Step 6 : Generate the manifest and jar file

Repeat the step 5.

Unfortunately, the MANIFEST.MF file of the Camel bundle does not contain a link to the package 'demo.Service' that the bean 'myTransform' required in order the instantiate the class. This link is not added by the bnd tool during the generation step. So we have to edit the file contained in the jar file 'demo.camel-bundle-0.1.jar' in order to add the following line at the end of the MANIFEST.MF file.

Remark : if someone find how to avoid this, he/she is welcome (wink)

Code Block

Import-Package: demo.service

Save the MANIFEST.MF file (and the jar containing it)

Launch the server and deploy the bundles

#Resources

  • Attachments
    patterns.*part-one.zip