Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
apache-felix-ipojo-header
apache-felix-ipojo-header

HTML
Wiki Markup
{html}
<div class="content">
{html}

Developing Camel mediators with iPOJO

...

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 TransformService.java and copy paste the code below:

Code Block
java
java
titleTransformService.javajava
package demo.service;
public interface TransformService {
    public Object transform(Object obj);
}

...

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

Code Block
java
java
titleTransformServiceImpl.javajava
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);
        }
        LOG.info(">> 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;
    }
}

...

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/

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

...

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

Code Block
xml
xml
titlepom.xmlxml
<project>
  <modelVersion>4.0.0</modelVersion>
  <packaging>bundle</packaging>
  <groupId>demo</groupId>
  <artifactId>demo.service-ipojo-bundle</artifactId>
  <version>0.1</version>
  <name>demo.service-ipojo-bundle</name>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>1.4.2</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
            <Import-Package>*</Import-Package>
            <Export-Package>*</Export-Package>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
	      <groupId>org.apache.felix</groupId>
	      <artifactId>maven-ipojo-plugin</artifactId>
		  <executions>
          	<execution>
            	<goals>
	              <goal>ipojo-bundle</goal>
               </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  
  <dependencies>
	  <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
          <version>1.5.0</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>com.springsource.slf4j.api</artifactId>
          <version>1.5.0</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>com.springsource.slf4j.log4j</artifactId>
          <version>1.5.0</version>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.log4j</groupId>
                <artifactId>com.springsource.org.apache.log4j</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
    </dependencies>
</project>

...