Example usage for org.springframework.integration IntegrationMessageHeaderAccessor CLOSEABLE_RESOURCE

List of usage examples for org.springframework.integration IntegrationMessageHeaderAccessor CLOSEABLE_RESOURCE

Introduction

In this page you can find the example usage for org.springframework.integration IntegrationMessageHeaderAccessor CLOSEABLE_RESOURCE.

Prototype

String CLOSEABLE_RESOURCE

To view the source code for org.springframework.integration IntegrationMessageHeaderAccessor CLOSEABLE_RESOURCE.

Click Source Link

Usage

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);/* w  w w .  j ava 2 s .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"));
}