Search in sources :

Example 1 with FtpRemoteFileTemplate

use of org.springframework.integration.ftp.session.FtpRemoteFileTemplate in project spring-integration by spring-projects.

the class FtpTests method testFtpInboundStreamFlow.

@Test
public void testFtpInboundStreamFlow() throws Exception {
    QueueChannel out = new QueueChannel();
    StandardIntegrationFlow flow = IntegrationFlows.from(Ftp.inboundStreamingAdapter(new FtpRemoteFileTemplate(sessionFactory())).remoteDirectory("ftpSource").maxFetchSize(11).regexFilter(".*\\.txt$"), e -> e.id("ftpInboundAdapter").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(" ftpSource1.txt", "ftpSource2.txt"));
    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(" ftpSource1.txt", "ftpSource2.txt"));
    new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
    MessageSource<?> source = context.getBean(FtpStreamingMessageSource.class);
    assertThat(TestUtils.getPropertyValue(source, "maxFetchSize"), equalTo(11));
    registration.destroy();
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) FtpRemoteFileTemplate(org.springframework.integration.ftp.session.FtpRemoteFileTemplate) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test)

Example 2 with FtpRemoteFileTemplate

use of org.springframework.integration.ftp.session.FtpRemoteFileTemplate in project spring-integration by spring-projects.

the class FtpServerOutboundTests method testInt3412FileMode.

@Test
public void testInt3412FileMode() {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(ftpSessionFactory);
    assertFalse(template.exists("ftpTarget/appending.txt"));
    Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt").build();
    appending.send(m);
    appending.send(m);
    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"));
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) Matchers.containsString(org.hamcrest.Matchers.containsString) FtpRemoteFileTemplate(org.springframework.integration.ftp.session.FtpRemoteFileTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 FtpRemoteFileTemplate (org.springframework.integration.ftp.session.FtpRemoteFileTemplate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 StandardIntegrationFlow (org.springframework.integration.dsl.StandardIntegrationFlow)1 IntegrationFlowRegistration (org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration)1 MessagingException (org.springframework.messaging.MessagingException)1