use of org.springframework.integration.sftp.session.SftpRemoteFileTemplate in project spring-integration by spring-projects.
the class SftpTests method testSftpSessionCallback.
@Test
public void testSftpSessionCallback() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = f -> f.<String>handle((p, h) -> new SftpRemoteFileTemplate(sessionFactory()).execute(s -> s.list(p))).channel(out);
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
registration.getInputChannel().send(new GenericMessage<>("sftpSource"));
Message<?> receive = out.receive(10_000);
assertNotNull(receive);
Object payload = receive.getPayload();
assertThat(payload, instanceOf(ChannelSftp.LsEntry[].class));
assertTrue(((ChannelSftp.LsEntry[]) payload).length > 0);
registration.destroy();
}
use of org.springframework.integration.sftp.session.SftpRemoteFileTemplate in project spring-integration by spring-projects.
the class SftpTests method testSftpInboundStreamFlow.
@Test
public void testSftpInboundStreamFlow() throws Exception {
QueueChannel out = new QueueChannel();
StandardIntegrationFlow flow = IntegrationFlows.from(Sftp.inboundStreamingAdapter(new SftpRemoteFileTemplate(sessionFactory())).remoteDirectory("sftpSource").regexFilter(".*\\.txt$"), 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);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" sftpSource1.txt", "sftpSource2.txt"));
((InputStream) message.getPayload()).close();
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
message = out.receive(10_000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" sftpSource1.txt", "sftpSource2.txt"));
((InputStream) message.getPayload()).close();
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
registration.destroy();
}
use of org.springframework.integration.sftp.session.SftpRemoteFileTemplate in project spring-integration by spring-projects.
the class SftpServerOutboundTests method testInt3412FileMode.
@Test
public void testInt3412FileMode() {
Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt").build();
appending.send(m);
appending.send(m);
SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sessionFactory);
assertLength6(template);
ignoring.send(m);
assertLength6(template);
try {
failing.send(m);
fail("Expected exception");
} catch (MessagingException e) {
assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
}
}
Aggregations