We now have to configure the tutorial-file-su to copy files from one directory to the other.

Configuring pom.xml

Changing the project name

In order to make the build output a little bit more comprehensible, we first change the project name in the generated pom.xml file.

<project>
  ...
  <name>Tutorial :: File SU</name>
  ...
</project>

Adding a dependency for a JBI component

Every service unit is targeted at a specific JBI component. We also specify this in pom.xml, by simple adding a dependency to the targeted pom.xml. ServiceMix's Maven tooling will take care of the rest. In this case, we are going to add a dependency to servicemix-file (groupId is org.apache.servicemix. The ServiceMix version is specified as a property in the pom.xml file, so we are going to re-use the same version property here. Since we are not going to use JUnit here, the <dependencies> element below should be enough for your SU right now.

<dependencies>
  <dependency>
    <groupId>org.apache.servicemix</groupId>
    <artifactId>servicemix-file</artifactId>
    <version>${servicemix-version}</version>
  </dependency>
</dependencies>

Configuring xbean.xml

Next, we will have to configure our new SU to really provide some services. We do this by creating a file named xbean.xml in the src/main/resources directory of our tutorial-file-su module. The sample shown below defines two namespaces: the file prefix refers to namespace to address the standard file functionality, while the tut prefix will be used for the namespace in which all our services will be defined.

<beans xmlns:file="http://servicemix.apache.org/file/1.0"
       xmlns:tut="urn:servicemix:tutorial">
  <!-- add the sender endpoint here -->
  <!-- add the poller endpoint here -->    
</beans>
On Windows

The code snippets below use Unix paths. If you want to explicitly specify the drive letter on a Windows system, the correct URI format is file:///c:/servicemix/poller.

Defining a file sender endpoint

A file sender can be used to write files on the local filesystem. With the XML snippet shown below, we create a file sender endpoint by using appropriate XML element and specifying the service name, endpoint name and the directory to write the files in (change this into an existing folder on your machine).

<file:sender service="tut:file" 
             endpoint="sender"
             directory="file:/home/gert/sender" />

Defining a file poller endpoint

We are going to read XML files from a specific directory (specified by the file attribute, so change this into an existing directory on your own system). The XML snippet below is used to configure a poller, which will check for new files every few seconds. The files will be sent to the file sender endpoint, which is specified by the targetService and targetEndpoint attributes.

<file:poller service="tut:file" 
             endpoint="poller"
             file="file:/home/gert/poller" 
             targetService="tut:file"
             targetEndpoint="sender"/>

Now, all we have to do is package the SU in a service assembly and deploy it.

Things to remember

  • You specify the target component for a SU as a normal dependency in Maven's pom.xml file
  • In ServiceMix, most service units will be configured by a file named xbean.xml

Further reading

  • servicemix-file contains more information about the servicemix-file JBI component and an overview of the various configuration options.