LibraryToggle FramesPrintFeedback

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:


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.


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.


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


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.

Comments powered by Disqus