LibraryPrintFeedback

Using the File Binding Component

Version 7.1

December 2012
Trademark Disclaimer
Third Party Acknowledgements

Updated: 08 Jan 2014

Table of Contents

1. Introduction to the File Binding Component
2. Using Poller Endpoints
Introduction to poller endpoints
Basic configuration
Configuring poller endpoints interactions with the file system
Configuring the Polling Interval
File locking
File filtering
3. Using Sender Endpoints
Introduction to sender endpoints
Basic configuration
Configuring a sender endpoint's interaction with the file system
4. File Marshalers
A. Poller Endpoint Properties
B. Sender Endpoint Properties
C. Using the Maven JBI Tooling
Setting up a Fuse ESB Enterprise JBI project
A service unit project
A service assembly project
D. Using the Maven OSGi Tooling
Setting up a Fuse ESB Enterprise OSGi project
Configuring the Bundle Plug-In
Index

List of Figures

2.1. Poller endpoint
3.1. Sender endpoint

List of Tables

2.1. Attributes for identifying a poller endpoint
3.1. Attributes for identifying a sender endpoint
3.2. Attributes used to determine a temporary file name
4.1. Properties for configuring the binary file marshaler
4.2. Properties used to control the flat file marshaler
4.3. Parameters for reading messages from the file system
4.4. Parameters for writing messages to the file system
A.1. Attributes for configuring a poller endpoint
A.2. Beans for configuring a poller endpoint
B.1. Attributes for configuring a sender endpoint
B.2. Attributes for configuring a sender endpoint
C.1. Service unit archetypes

List of Examples

1.1. JBI descriptor for a file component service unit
1.2. Namespace declaration for using file endpoints
1.3. Schema location for using file endpoints
2.1. Simple poller endpoint
2.2. Poller endpoint that does not check subdirectories
2.3. Poller endpoint that leaves files behind
2.4. Poller endpoint that archives files
2.5. Poller endpoint with a scheduled start time
2.6. Poller endpoint with a delayed start time
2.7. Poller Endpoint with a thirty second polling interval
2.8. The lock manager's get lock method
2.9. Simple lock manager implementation
2.10. Poller endpoint using a custom lock manager
2.11. File filter's accept method
2.12. Simple file filter implementation
2.13. Poller endpoint using a file filter
3.1. Simple sender endpoint
3.2. Sender endpoint that creates its target directory
3.3. Sender endpoint that appends existing files
3.4. Configuring a sender endpoint's temporary file prefix
4.1. The file marshaler interface
4.2. Simple file marshaler
4.3. Poller endpoint using a file marshaler
C.1. POM elements for using Fuse ESB Enterprise Maven tooling
C.2. Top-level POM for a Fuse ESB Enterprise JBI project
C.3. Maven archetype command for service units
C.4. Configuring the maven plug-in to build a service unit
C.5. Specifying the target components for a service unit
C.6. Specifying a target component for a service unit
C.7. POM file for a service unit project
C.8. Maven archetype command for service assemblies
C.9. Configuring the Maven plug-in to build a service assembly
C.10. Specifying the target components for a service unit
C.11. POM for a service assembly project
D.1. Adding an OSGi bundle plug-in to a POM
D.2. Setting a bundle's symbolic name
D.3. Setting a bundle's name
D.4. Setting a bundle's version
D.5. Including a private package in a bundle
D.6. Specifying the packages imported by a bundle

Poller endpoints play the role of consumer from the vantage point of the other endpoints in the ESB. As shown in Figure 2.1, a poller endpoint watches the file system for files to consume. When the endpoint consumes a file, it transfers its contents into a message and starts off an in-only message exchange. Poller endpoints cannot receive messages from the NMR.


In addition to the default file marshaler, Fuse ESB Enterprise provides two other file marshalers that file component endpoints can use:

Binary File Marshaler

The binary file marshaler is provided by the class org.apache.servicemix.components.util.BinaryFileMarshaler. It reads in binary data and adds the data to the normalized message as an attachment. You can set the name of the attachment and specify a content type for the attachment using the properties shown in Table 4.1.


Flat File Marshaler

The flat file marshaler is provided by the class org.apache.servicemix.components.util.SimpleFlatFileMarshaler. It reads in flat text files and converts them into XML messages.

By default, the file is wrapped in a File element. Each line in the file is wrapped in a Line element with a number attribute that represents the position of the line in the original file.

You can control some aspects of the generated XML file using the properties described in Table 4.2.


To develop a custom file marshaler, you need to implement the org.apache.servicemix.components.util.FileMarshaler interface. Example 4.1 shows the interface.


The FileMarshaler interface has three methods that need to be implemented:

readMessage()

The readMessage() method is responsible for reading a file from the file system and converting the data into a normalized message. Table 4.3 describes the parameters used by the method.


getOutputName()

The getOutputName() method returns the name of the file to be written to the file system. The message exchange and the message received by the sender endpoint are passed to the method.

[Important]Important

The returned file name does not contain a directory path. The sender endpoint uses the directory it was configured to use.

writeMessage()

The writeMessage() method is responsible for writing messages received from the NMR to the file system as files. Table 4.4 describes the parameters used by the method.


Example 4.2 shows a simple file mashaler.


Fuse ESB Enterprise provides a Maven plug-in and a number of Maven archetypes that make developing, packaging, and deploying JBI artifacts easier. The tooling provides you with a number of benefits including:

Because Fuse ESB Enterprise only allows you to deploy service assemblies, you will need to do the following when using the Maven JBI tooling:

  1. Set up a top-level project to build all of the service units and the final service assembly.

  2. Create a project for each of your service units..

  3. Create a project for the service assembly.

Example C.2 shows a top-level POM for a project that contains a single service unit.

Example C.2. Top-level POM for a Fuse ESB Enterprise JBI project

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.widgets</groupId>
    <artifactId>demos</artifactId>
    <version>1.0</version>
  </parent>

  <groupId>com.widgets.demo</groupId>
  <artifactId>cxf-wsdl-first</artifactId>
  <name>CXF WSDL Fisrt Demo</name>
  <packaging>pom</packaging>
    
  <pluginRepositories> 1
    <pluginRepository>
      <id>fusesource.m2</id>
      <name> Open Source Community Release Repository</name>
      <url>http://repo.fusesource.com/maven2</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>
  <repositories>
    <repository>
      <id>fusesource.m2</id>
      <name> Open Source Community Release Repository</name>
      <url>http://repo.fusesource.com/maven2</url>
      <snapshots>
         <enabled>false</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
    <repository>
      <id>fusesource.m2-snapshot</id>
      <name> Open Source Community Snapshot Repository</name>
      <url>http://repo.fusesource.com/maven2-snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>
    
  <modules> 2
    <module>wsdl-first-cxfse-su</module>
     <module>wsdl-first-cxf-sa</module>
  </modules>
    
  <build>
    <plugins>
      <plugin> 3
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
         <version>2.1</version>
         <inherited>false</inherited>
           <executions>
             <execution>
                <id>src</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/src.xml</descriptor>
                  </descriptors>
                 </configuration>
               </execution>
             </executions>
           </plugin>
           <plugin> 4
             <groupId>org.apache.servicemix.tooling</groupId>
             <artifactId>jbi-maven-plugin</artifactId>
             <extensions>true</extensions>
           </plugin>
    </plugins>
  </build>
</project>

The top-level POM shown in Example C.2 does the following:

1

Configures Maven to use the repositories for loading the Fuse ESB Enterprise plug-ins.

2

Lists the sub-projects used for this application. The wsdl-first-cxfse-su module is the module for the service unit. The wsdl-first-cxf-sa module is the module for the service assembly

3

Configures the Maven assembly plug-in.

4

Loads the Fuse ESB Enterprise JBI plug-in.

Fuse ESB Enterprise provides Maven artifacts for a number of service unit types. They can be used to seed a project with the smx-arch command. As shown in Example C.3, the smx-arch command takes three arguments. The groupId value and the artifactId values correspond to the project's group ID and artifact ID.


[Important]Important

The double quotes(") are required when using the -DgroupId argument and the -DartifactId argument.

The suArchetypeName specifies the type of service unit to seed. Table C.1 lists the possible values and describes what type of project is seeded.

Table C.1. Service unit archetypes

NameDescription
camelCreates a project for using the Apache Camel service engine
cxf-seCreates a project for developing a Java-first service using the Apache CXF service engine
cxf-se-wsdl-firstCreates a project for developing a WSDL-first service using the Apache CXF service engine
cxf-bcCreates an endpoint project targeted at the Apache CXF binding component
http-consumerCreates a consumer endpoint project targeted at the HTTP binding component
http-providerCreates a provider endpoint project targeted at the HTTP binding component
jms-consumerCreates a consumer endpoint project targeted at the JMS binding component (see Using the JMS Binding Component)
jms-providerCreates a provider endpoint project targeted at the JMS binding component (see Using the JMS Binding Component)
file-pollerCreates a polling (consumer) endpoint project targeted at the file binding component (see Using Poller Endpoints)
file-senderCreates a sender (provider) endpoint project targeted at the file binding component (see Using Sender Endpoints)
ftp-pollerCreates a polling (consumer) endpoint project targeted at the FTP binding component
ftp-senderCreates a sender (provider) endpoint project targeted at the FTP binding component
jsr181-annotatedCreates a project for developing an annotated Java service to be run by the JSR181 service engine [a]
jsr181-wsdl-firstCreates a project for developing a WSDL generated Java service to be run by the JSR181 service engine [a]
saxon-xqueryCreates a project for executing xquery statements using the Saxon service engine
saxon-xsltCreates a project for executing XSLT scripts using the Saxon service engine
eipCreates a project for using the EIP service engine. [b]
lwcontainerCreates a project for deploying functionality into the lightweight container [c]
beanCreates a project for deploying a POJO to be executed by the bean service engine
odeCreate a project for deploying a BPEL process into the ODE service engine

[a] The JSR181 has been deprecated. The Apache CXF service engine has superseded it.

[b] The EIP service engine has been deprecated. The Apache Camel service engine has superseded it.

[c] The lightweight container has been deprecated.


To correctly fill in the metadata required for packaging a service unit, the Maven plug-in must be told what component (or components) the service unit is targeting. If your service unit only has a single component dependency, you can specify it in one of two ways:

  • List the targeted component as a dependency

  • Add a componentName property specifying the targeted component

If your service unit has more than one component dependency, you must configure the project as follows:

  1. Add a componentName property specifying the targeted component.

  2. Add the remaining components to the list dependencies.

Example C.5 shows the configuration for a service unit targeting the Apache CXF binding component.


The advantage of using the Maven dependency mechanism is that it allows Maven to verify if the targeted component is deployed in the container. If one of the components is not deployed, Fuse ESB Enterprise will not hold off deploying the service unit until all of the required components are deployed.

[Tip]Tip

Typically, a message identifying the missing component(s) is written to the log.

If your service unit's targeted component is not available as a Maven artifact, you can specify the targeted component using the componentName element. This element is added to the standard Maven properties block and it specifies the name of a targeted component, as specified in Example C.6.


When you use the componentName element, Maven does not check to see if the component is installed, nor does it download the required component.

Example C.7 shows the POM file for a project that is building a service unit targeted to the Apache CXF binding component.

Example C.7. POM file for a service unit project

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent> 1
        <groupId>com.widgets.demo</groupId>
        <artifactId>cxf-wsdl-first</artifactId>
        <version>1.0</version>
    </parent>

  <groupId>com.widgets.demo.cxf-wsdl-first</groupId>
  <artifactId>cxfse-wsdl-first-su</artifactId>
  <name>CXF WSDL Fisrt Demo :: SE Service Unit</name>
  <packaging>jbi-service-unit</packaging> 2

  <dependencies> 3
    <dependency>
      <groupId>org.apache.servicemix</groupId>
      <artifactId>servicemix-cxf-bc</artifactId>
      <version>3.3.1.0-fuse</version>
    </dependency>
  >/dependencies>

  <build>
    <plugins>
      <plugin> 4
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

The POM file in Example C.7 does the following:

1

Specifies that it is a part of the top-level project shown in Example C.2

2

Specifies that this project builds a service unit

3

Specifies that the service unit targets the Apache CXF binding component

4

Specifies to use the Fuse ESB Enterprise Maven plug-in



[1] You replace this with the version of Apache CXF you are using.

Example C.11 shows a POM file for a project that is building a service assembly.

Example C.11. POM for a service assembly project

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent> 1
        <groupId>com.widgets.demo</groupId>
        <artifactId>cxf-wsdl-first</artifactId>
        <version>1.0</version>
    </parent>

  <groupId>com.widgets.demo.cxf-wsdl-first</groupId>
  <artifactId>cxf-wsdl-first-sa</artifactId>
  <name>CXF WSDL Fisrt Demo ::  Service Assemby</name>
  <packaging>jbi-service-assembly</packaging> 2

  <dependencies> 3
    <dependency>
      <groupId>com.widgets.demo.cxf-wsdl-first</groupId>
      <artifactId>cxfse-wsdl-first-su</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>com.widgets.demo.cxf-wsdl-first</groupId>
      <artifactId>cxfbc-wsdl-first-su</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin> 4
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

The POM in Example C.11 does the following:

1

Specifies that it is a part of the top-level project shown in Example C.2

2

Specifies that this project builds a service assembly

3

Specifies the service units being bundled by the service assembly

4

Specifies to use the Fuse ESB Enterprise Maven plug-in

The Fuse ESB Enterprise OSGi tooling uses the Maven bundle plug-in from Apache Felix. The bundle plug-in is based on the bnd tool from Peter Kriens. It automates the construction of OSGi bundle manifests by introspecting the contents of the classes being packaged in the bundle. Using the knowledge of the classes contained in the bundle, the plug-in can calculate the proper values to populate the Import-Packages and the Export-Package properties in the bundle manifest. The plug-in also has default values that are used for other required properties in the bundle manifest.

To use the bundle plug-in, do the following:

  1. Add the bundle plug-in to your project's POM file.

  2. Configure the plug-in to correctly populate your bundle's manifest.

A Maven project for building an OSGi bundle can be a simple single level project. It does not require any sub-projects. However, it does require that you do the following:

  1. Add the bundle plug-in to your POM.

  2. Instruct Maven to package the results as an OSGi bundle.

[Tip]Tip

There are several Maven archetypes you can use to set up your project with the appropriate settings.

Before you can use the bundle plug-in you must add a dependency on Apache Felix. After you add the dependency, you can add the bundle plug-in to the plug-in portion of the POM.

Example D.1 shows the POM entries required to add the bundle plug-in to your project.

Example D.1. Adding an OSGi bundle plug-in to a POM

...
<dependencies>
  <dependency> 1
    <groupId>org.apache.felix</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>1.0.0</version>
  </dependency>
...
</dependencies>
...
<build>
  <plugins>
    <plugin> 2
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <configuration>
        <instructions>
          <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> 3
          <Import-Package>*,org.apache.camel.osgi</Import-Package> 4
          <Private-Package>org.apache.servicemix.examples.camel</Private-Package> 5
        </instructions>
      </configuration> 
    </plugin>
  </plugins>
</build>
...

The entries in Example D.1 do the following:

1

Adds the dependency on Apache Felix

2

Adds the bundle plug-in to your project

3

Configures the plug-in to use the project's artifact ID as the bundle's symbolic name

4

Configures the plug-in to include all Java packages imported by the bundled classes; also imports the org.apache.camel.osgi package

5

Configures the plug-in to bundle the listed class, but not to include them in the list of exported packages

[Note]Note

Edit the configuration to meet the requirements of your project.

For more information on configuring the bundle plug-in, see Configuring the Bundle Plug-In.

By default, the OSGi manifest's Export-Package list is populated by all of the packages in your local Java source code (under src/main/java), except for the deault package, ., and any packages containing .impl or .internal.

[Important]Important

If you use a Private-Package element in your plug-in configuration and you do not specify a list of packages to export, the default behavior includes only the packages listed in the Private-Package element in the bundle. No packages are exported.

The default behavior can result in very large packages and in exporting packages that should be kept private. To change the list of exported packages you can add an Export-Package child to the plug-in's instructions element.

The Export-Package element specifies a list of packages that are to be included in the bundle and that are to be exported. The package names can be specified using the * wildcard symbol. For example, the entry com.fuse.demo.* includes all packages on the project's classpath that start with com.fuse.demo.

You can specify packages to be excluded be prefixing the entry with !. For example, the entry !com.fuse.demo.private excludes the package com.fuse.demo.private.

When excluding packages, the order of entries in the list is important. The list is processed in order from the beginning and any subsequent contradicting entries are ignored.

For example, to include all packages starting with com.fuse.demo except the package com.fuse.demo.private, list the packages using:

!com.fuse.demo.private,com.fuse.demo.*

However, if you list the packages using com.fuse.demo.*,!com.fuse.demo.private, then com.fuse.demo.private is included in the bundle because it matches the first pattern.

M

marshaler, Configuring an endpoint to use a file marshaler
marshaling
binary files, Provided file marshalers
flat files, Provided file marshalers
Maven archetypes, Useful Maven archetypes
Maven tooling
adding the bundle plug-in, Adding a bundle plug-in
set up, Setting up the Maven tools

N

namespace, Namespace