Versions Compared

Key

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

...

Remark : We use maven to avoid to create manually the MANIFEST file.

This command can be launched from Eclipse (if you have integrated maven within Eclipse (eclipse maven plugin)) or a Unix/Dos prompt in the folder where your Before to execute the command, the pom.xml file is locatedmust be modified like this :

Code Block
titlepom demo.service-bundle
mvn org.ops4j:maven-pax-plugin:compile org.ops4j:maven-pax-plugin:eclipse install

If this command does not report any error, then a 'MANIFEST.MF' file containing the following information is created in the folder 'META-INF' and
a demo.service-bundle-0.1.0.jar jar is created in the target folder:

Code Block

Manifest-Version: 1.0
Export-Package: demo.service;version="0.1"
Private-Package: demo.service.impl
Built-By: Charlesm
Build-Jdk: 1.6.0_07
Bundle-Version: 0.1.0
Tool: Bnd-0.0.255
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;version="0.1",org.apache.commons.logging
Tip
titlebnd tool

This file is created because the POM.file contains the maven felix plugin which uses the tool bnd. Bnd stands for BuNDle tool and has been created by Peter Kriens (OSGi Technical Officer)

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 with a reference to our TransformationService deployed in a OSGI bundle.

  • For the routing, create the following file in the folder src/main/resources/META-INF/spring of the project demo.camel-bundle:

...


<?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>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <properties>
    <bundle.symbolicName>demo.service-bundle</bundle.symbolicName>
    <bundle.namespace>demo.service</bundle.namespace>
    <commons.log>1.1</commons.log>
  </properties>

  <modelVersion>4.0.0</modelVersion>
  <groupId>demo.service</groupId>
  <artifactId>demo.service-bundle</artifactId>
  <version>0.1</version>

  <name>${bundle.symbolicName} [${bundle.namespace}]</name>

  <packaging>bundle</packaging>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <!--
       | example additional resource entries, useful when building Eclipse RCP applications
      -->
      <resource>
        <directory>.</directory>
        <includes>
          <include>plugin.xml</include>
          <include>plugin.properties</include>
          <include>icons/**</include>
        </includes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.ops4j</groupId>
        <artifactId>maven-pax-plugin</artifactId>
        <version>1.5-SNAPSHOT</version>
        <!--
           | enable improved OSGi compilation support for the bundle life-cycle.
           | to switch back to the standard bundle life-cycle, move this setting
           | down to the maven-bundle-plugin section
          -->
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.3</version>
        <!--
         | the following instructions build a simple set of public/private classes into an OSGi bundle
        -->
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
            <Bundle-Version>${pom.version}</Bundle-Version>
            <Export-Package>${bundle.namespace};version="${pom.version}"</Export-Package>
            <Private-Package>${bundle.namespace}.impl.*</Private-Package>
            <Include-Resource>src/main/resources</Include-Resource>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>osgi_R4_core</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>osgi_R4_compendium</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
        <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging-api</artifactId>
		<version>${commons.log}</version>
		<scope>provided</scope>
    </dependency>
  </dependencies>

</project>

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

Code Block

mvn org.ops4j:maven-pax-plugin:compile org.ops4j:maven-pax-plugin:eclipse install

If this command does not report any error, then a 'MANIFEST.MF' file containing the following information is created in the folder 'META-INF' and
a demo.service-bundle-0.1.0.jar jar is created in the target folder:

Code Block

Manifest-Version: 1.0
Export-Package: demo.service;version="0.1"
Private-Package: demo.service.impl
Built-By: Charlesm
Build-Jdk: 1.6.0_07
Bundle-Version: 0.1.0
Tool: Bnd-0.0.255
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;version="0.1",org.apache.commons.logging
Tip
titlebnd tool

This file is created because the POM.file contains the maven felix plugin which uses the tool bnd. Bnd stands for BuNDle tool and has been created by Peter Kriens (OSGi Technical Officer)

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 with a reference to our TransformationService deployed in a OSGI bundle.

  • For the routing, create the following file in the folder src/main/resources/META-INF/spring of the project demo.camel-bundle:
Code Block
xml
xml
titleCamelContext.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 which will trigger every 10th second and call the POJO 'MyTransform' and send the result to the 'camel:log' component. As, you can see, this is a pure Camel configuration file without any reference to an 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
titlebundle-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.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 7 : Generate the manifest and jar file

Prior to run/launch the command generating the MANIFEST file, you must modify the pom.xml file in order to allow the OSGI bundle to import/use the services classes : demo.service

Code Block
titlepom demo.camel-bundle

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <properties>
    <bundle.symbolicName>demo.camel-bundle</bundle.symbolicName>
    <bundle.namespace>demo.camel</bundle.namespace>
  </properties>

  <modelVersion>4.0.0</modelVersion>
  <groupId>demo.camel</groupId>
  <artifactId>demo.camel-bundle</artifactId>
  <version>0.1</version>

  <name>${bundle.symbolicName} [${bundle.namespace}]</name>

  <packaging>bundle</packaging>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <!--
       | example additional resource entries, useful when building Eclipse RCP applications
      -->
      <resource>
        <directory>.</directory>
        <includes>
          <include>plugin.xml</include>
          <include>plugin.properties</include>
          <include>icons/**</include>
          <include>META-INF/*</include>
        </includes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.ops4j</groupId>
        <artifactId>maven-pax-plugin</artifactId>
        <version>1.5-SNAPSHOT</version>
        <!--
           | enable improved OSGi compilation support for the bundle life-cycle.
           | to switch back to the standard bundle life-cycle, move this setting
           | down to the maven-bundle-plugin section
          -->
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.3</version>
        <!--
         | the following instructions build a simple set of public/private classes into an OSGi bundle
        -->
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
            <Bundle-Version>${pom.version}</Bundle-Version>
            <Import-Package>demo.service;version="${pom.version}"</Import-Package>
            <Include-Resource>src/main/resources</Include-Resource>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>osgi_R4_core</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>osgi_R4_compendium</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>demo.service</groupId>
      <artifactId>demo.service-bundle</artifactId>
      <version>${pom.version}</version>
    </dependency>
  </dependencies>

</project>

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

  • To inject the dependency, we will create a second file named bundle-context-osgi.xml in the same folder:

...


<?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 7 : Generate the manifest and jar file

Prior to run/launch the command generating the MANIFEST file, you must modify the pom.xml file and add the following line in order to allow the OSGI bundle to import/use the services classes : demo.service

Code Block

...
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.3</version>
        <!--
         | the following instructions build a simple set of public/private classes into an OSGi bundle
        -->
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
            <Bundle-Version>${pom.version}</Bundle-Version>
            <Import-Package>demo.service;version="${pom.version}"</Import-Package> -- LINE TO BE ADDED
            <Include-Resource>src/main/resources</Include-Resource>
          </instructions>
        </configuration>
      </plugin>

...

Run the command mvn org.ops4j:maven-pax-plugin:compile org.ops4j:maven-pax-plugin:eclipse install (= Repeat step #5).

...