Example usage for org.springframework.integration.ftp.dsl Ftp outboundAdapter

List of usage examples for org.springframework.integration.ftp.dsl Ftp outboundAdapter

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.dsl Ftp outboundAdapter.

Prototype

public static FtpMessageHandlerSpec outboundAdapter(RemoteFileTemplate<FTPFile> remoteFileTemplate,
        FileExistsMode fileExistsMode) 

Source Link

Document

A FtpMessageHandlerSpec factory for an outbound channel adapter spec.

Usage

From source file:org.springframework.integration.ftp.dsl.FtpTests.java

@Test
public void testFtpOutboundFlow() {
    IntegrationFlow flow = f -> f.handle(Ftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL)
            .useTemporaryFileName(false).fileNameExpression("headers['" + FileHeaders.FILENAME + "']")
            .remoteDirectory("ftpTarget"));
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    String fileName = "foo.file";
    Message<ByteArrayInputStream> message = MessageBuilder
            .withPayload(new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)))
            .setHeader(FileHeaders.FILENAME, fileName).build();
    registration.getInputChannel().send(message);
    RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(sessionFactory());
    FTPFile[] files = template/*from w  ww.  j a  v  a 2s . c o m*/
            .execute(session -> session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
    assertEquals(1, files.length);
    assertEquals(3, files[0].getSize());

    registration.destroy();
}