Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sending files over FTP using the Spring integration


Think of a scenario in which you are sending files over an FTP channel. Consider that there are two files, say Orders.txt and vendors.txt, that need to be sent over FTP to a remote location. To accomplish this, we need to follow these steps:

  1. Create FTPChannel.

  2. Make a directory in the base folder using baseFolder.mkdirs().

  3. Create two file objects at the base folder location.

  4. Use InputStream and create two separate streams for orders and vendors.

  5. Using the file utils available in Spring, copy the input streams to their specific files.

  6. Using the MessageBuilder class, use the withpayload() method to convert the files into messages.

  7. Lastly, send the message to the FTP channel and close the context.

Let's write some sample code to do this:

public void sendFilesOverFTP() throws Exception{

  ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml");

  MessageChannel...