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:
Create
FTPChannel
.Make a directory in the base folder using
baseFolder.mkdirs()
.Create two file objects at the base folder location.
Use
InputStream
and create two separate streams for orders and vendors.Using the file utils available in Spring, copy the input streams to their specific files.
Using the
MessageBuilder
class, use thewithpayload()
method to convert the files into messages.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...