Developing Camel mediators with iPOJO

The Camel OSGi tutorial provides a very simple and neat overview of Camel. This article mentions the usage of iPOJO to implement the mediator. This document provides this implementation.

Step 1 : Initial project setup

Instead of using the 'spring-osgi-bundle-archetype' maven archetype, we will use the iPOJO one to create the iPOJO bundle. To create the simple iPOJO service project, execute the following command in your Unix/Dos console.

mvn archetype:create -DarchetypeGroupId=org.apache.felix -DarchetypeArtifactId=maven-ipojo-plugin -DarchetypeVersion=1.0.0 -DgroupId=demo -DartifactId=demo.service-ipojo-bundle -Dversion=0.1

Step 2 : Develop the interface

So now, it is time to create the interface that we will use in the project. Create a new folder "service" in src/main/java/demo tree. Add the interface and copy paste the code below:

package demo.service;
public interface TransformService {
    public Object transform(Object obj);

Step 3 : Create the class implementing the interface

Next, we will create the class TransformServiceImpl implementing the interface TransformService. Create the class in the folder src/main/java/demo/service/

package demo.service;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TransformServiceImpl implements TransformService {
    private static final transient Log LOG = LogFactory.getLog(TransformServiceImpl.class);
    private boolean verbose = true;
    private String prefix = "MyTransform";

    public Object transform(Object body) {
        String answer = prefix + " set body:  " + new Date();
        if (verbose) {
            System.out.println(">> call >> " + answer);
        }">> call >>" + answer);
        return answer;

    public boolean isVerbose() {
        return verbose;

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;

    public String getPrefix() {
        return prefix;

    public void setPrefix(String prefix) {
        this.prefix = prefix;

Step 4 : Create the iPOJO configuration files

The next step concerns the creation of the iPOJO configuration file who will allow the registration of the TranformService as an OSGi service. Create or edit the file metadata.xml in the folder src/main/resources/

<?xml version="1.0" encoding="UTF-8"?>
    <component classname="demo.service.TransformServiceImpl" name="my-ipojo-transformer">
    <instance component="my-ipojo-transformer"/>

Step 5 : Generate the bundle

Before generating the bundle, we need to edit the file to describe our bundle.




Step 6 & 7: Create the Camel context file and the bundle

These steps are exactly the same as into the OSGi Camel Tutorial. So refer to the step 6 and 7 of the article. That's it. Deploy and enjoy.