O'Reilly logo

Just Spring Integration by Madhusudhan Konda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

File Adapters

File Adapters fetch or copy files to and from different file systems. They pick a file from a file system and turn into Framework’s Message to publish onto a channel and vice versa. Framework supports a declarative model using file namespace. It also provides a few classes for reading and writing files, but using namespace is advised.

Using Namespace

The file namespace provides the respective elements to create the objects declaratively and easily. In order to use the file namespace, you should add the respective schema urls to your XML file, highlighted in bold below:

<?xml version="1.0" encoding="UTF-8"?>
 <beans 
   ....
   xmlns:file="http://www.springframework.org/schema/integration/file"
 xsi:schemaLocation=
   http://www.springframework.org/schema/integration/file 
   http://www.springframework.org/schema/integration/file/spring-integration-file-2.1.xsd">
   ...
</beans>

Framework provides two adapters to read and write the files. The inbound-channel-adapter element is used for reading the files and publishing them onto a channel as File payload messages. The outbound-channel-adapter is used for picking up the File payload messages from a channel, extracting them as files, and writing them to the file systems.

Inbound File Adapter

The following snippet demonstrates the inbound adapter:

<!-- Adapter using namespace --> <file:inbound-channel-adapter id="fileAdapter" directory="/Users/mkonda/dev/ws/" channel="files-out-channel"> <int:poller fixed-rate="1000" /> </file:inbound-channel-adapter> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required