use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class SftpTests method testSftpOutboundFlow.
@Test
public void testSftpOutboundFlow() {
IntegrationFlow flow = f -> f.handle(Sftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL).useTemporaryFileName(false).fileNameExpression("headers['" + FileHeaders.FILENAME + "']").remoteDirectory("sftpTarget"));
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
String fileName = "foo.file";
registration.getInputChannel().send(MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, fileName).build());
RemoteFileTemplate<ChannelSftp.LsEntry> template = new RemoteFileTemplate<>(sessionFactory());
ChannelSftp.LsEntry[] files = template.execute(session -> session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
assertEquals(1, files.length);
assertEquals(3, files[0].getAttrs().getSize());
registration.destroy();
}
use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class SftpTests method testSftpInboundFlow.
@Test
public void testSftpInboundFlow() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = IntegrationFlows.from(Sftp.inboundAdapter(sessionFactory()).preserveTimestamp(true).remoteDirectory("sftpSource").regexFilter(".*\\.txt$").localFilenameExpression("#this.toUpperCase() + '.a'").localDirectory(getTargetLocalDirectory()), e -> e.id("sftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
Message<?> message = out.receive(10_000);
assertNotNull(message);
Object payload = message.getPayload();
assertThat(payload, instanceOf(File.class));
File file = (File) payload;
assertThat(file.getName(), isOneOf(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
assertThat(file.getAbsolutePath(), containsString("localTarget"));
message = out.receive(10_000);
assertNotNull(message);
file = (File) message.getPayload();
assertThat(file.getName(), isOneOf(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
assertThat(file.getAbsolutePath(), containsString("localTarget"));
registration.destroy();
}
Aggregations