Example usage for org.springframework.integration.file FileHeaders REMOTE_FILE

List of usage examples for org.springframework.integration.file FileHeaders REMOTE_FILE

Introduction

In this page you can find the example usage for org.springframework.integration.file FileHeaders REMOTE_FILE.

Prototype

String REMOTE_FILE

To view the source code for org.springframework.integration.file FileHeaders REMOTE_FILE.

Click Source Link

Usage

From source file:com.example.GcsSpringIntegrationApplication.java

/**
 * A service activator that connects to a channel with messages containing
 * {@code InputStream} payloads and copies the file data to a remote directory on GCS.
 * @param gcs a storage client to use/*from   w w  w . j a va 2s .c  o  m*/
 * @return a message handler
 */
@Bean
@ServiceActivator(inputChannel = "copy-channel")
public MessageHandler outboundChannelAdapter(Storage gcs) {
    GcsMessageHandler outboundChannelAdapter = new GcsMessageHandler(new GcsSessionFactory(gcs));
    outboundChannelAdapter.setRemoteDirectoryExpression(new ValueExpression<>(this.gcsWriteBucket));
    outboundChannelAdapter
            .setFileNameGenerator((message) -> message.getHeaders().get(FileHeaders.REMOTE_FILE, String.class));

    return outboundChannelAdapter;
}

From source file:org.springframework.integration.aws.inbound.S3InboundStreamingChannelAdapterTests.java

@Test
public void testS3InboundStreamingChannelAdapter() throws IOException {
    Message<?> message = this.s3FilesChannel.receive(10000);
    assertThat(message).isNotNull();/*from w  w  w. j  a  v a2 s.  c o m*/
    assertThat(message.getPayload()).isInstanceOf(InputStream.class);
    assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("subdir/a.test");

    InputStream inputStreamA = (InputStream) message.getPayload();
    assertThat(inputStreamA).isNotNull();
    assertThat(IOUtils.toString(inputStreamA)).isEqualTo("Hello");

    message = this.s3FilesChannel.receive(10000);
    assertThat(message).isNotNull();
    assertThat(message.getPayload()).isInstanceOf(InputStream.class);
    assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("subdir/b.test");
    InputStream inputStreamB = (InputStream) message.getPayload();
    assertThat(IOUtils.toString(inputStreamB)).isEqualTo("Bye");

    assertThat(this.s3FilesChannel.receive(10)).isNull();
}

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

@Test
public void testFtpInboundStreamFlow() throws Exception {
    QueueChannel out = new QueueChannel();
    StandardIntegrationFlow flow = IntegrationFlows.from(
            Ftp.inboundStreamingAdapter(new FtpRemoteFileTemplate(sessionFactory()))
                    .remoteDirectory("ftpSource").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);/*from ww w .j a  va  2 s . co m*/
    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();

    registration.destroy();
}

From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java

@Test
public void testStream() {
    String dir = "ftpSource/";
    this.inboundGetStream.send(new GenericMessage<Object>(dir + " ftpSource1.txt"));
    Message<?> result = this.output.receive(1000);
    assertNotNull(result);//from ww  w .  j a v a 2s. co m
    assertEquals("source1", result.getPayload());
    assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals(" ftpSource1.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));

    Session<?> session = (Session<?>) result.getHeaders()
            .get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE);
    // Returned to cache
    assertTrue(session.isOpen());
    // Raw reading is finished
    assertFalse(TestUtils.getPropertyValue(session, "targetSession.readingRaw", AtomicBoolean.class).get());

    // Check that we can use the same session from cache to read another remote InputStream
    this.inboundGetStream.send(new GenericMessage<Object>(dir + "ftpSource2.txt"));
    result = this.output.receive(1000);
    assertNotNull(result);
    assertEquals("source2", result.getPayload());
    assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("ftpSource2.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));
    assertSame(TestUtils.getPropertyValue(session, "targetSession"), TestUtils.getPropertyValue(
            result.getHeaders().get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE), "targetSession"));
}

From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java

@Test
public void testStream() {
    Session<?> session = spy(this.sessionFactory.getSession());
    session.close();// w  w  w.  ja va  2 s.co m

    String dir = "sftpSource/";
    this.inboundGetStream.send(new GenericMessage<Object>(dir + " sftpSource1.txt"));
    Message<?> result = this.output.receive(1000);
    assertNotNull(result);
    assertEquals("source1", result.getPayload());
    assertEquals("sftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals(" sftpSource1.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));
    verify(session).close();
}