INT-3622: (S)FTP: Add MessageSessionCallback

JIRA: https://jira.spring.io/browse/INT-3622

INT-3622: Polishing
This commit is contained in:
Artem Bilan
2015-08-07 23:18:52 -04:00
committed by Gary Russell
parent d89dabe72f
commit e408331e67
14 changed files with 396 additions and 59 deletions

View File

@@ -153,4 +153,13 @@
<int:service-activator input-channel="markers"
expression="payload.mark.toString().equals('END') ? headers['file_remoteSession'].close() : null"/>
<int-sftp:outbound-gateway
session-factory="sftpSessionFactory"
session-callback="messageSessionCallback"
request-channel="inboundCallback"
reply-channel="output"/>
<bean id="messageSessionCallback"
class="org.springframework.integration.sftp.outbound.SftpServerOutboundTests$TestMessageSessionCallback"/>
</beans>

View File

@@ -47,6 +47,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.file.remote.MessageSessionCallback;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.sftp.TestSftpServer;
@@ -62,6 +63,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.FileCopyUtils;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.ChannelSftp.LsEntry;
/**
@@ -129,6 +131,9 @@ public class SftpServerOutboundTests {
@Autowired
private DirectChannel inboundGetStream;
@Autowired
private DirectChannel inboundCallback;
@Before
@After
public void setup() {
@@ -420,6 +425,14 @@ public class SftpServerOutboundTests {
assertFalse(((Session<?>) result.getHeaders().get(FileHeaders.REMOTE_SESSION)).isOpen());
}
@Test
public void testMessageSessionCallback() {
this.inboundCallback.send(new GenericMessage<String>("foo"));
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals("FOO", receive.getPayload());
}
private void assertLength6(SftpRemoteFileTemplate template) {
LsEntry[] files = template.execute(new SessionCallback<LsEntry, LsEntry[]>() {
@@ -432,4 +445,14 @@ public class SftpServerOutboundTests {
assertEquals(6, files[0].getAttrs().getSize());
}
private static final class TestMessageSessionCallback
implements MessageSessionCallback<LsEntry, Object> {
@Override
public Object doInSession(Session<ChannelSftp.LsEntry> session, Message<?> requestMessage) throws IOException {
return ((String) requestMessage.getPayload()).toUpperCase();
}
}
}