INT-3622: (S)FTP: Add MessageSessionCallback
JIRA: https://jira.spring.io/browse/INT-3622 INT-3622: Polishing
This commit is contained in:
committed by
Gary Russell
parent
d89dabe72f
commit
e408331e67
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
import org.springframework.integration.file.remote.AbstractFileInfo;
|
||||
import org.springframework.integration.file.remote.MessageSessionCallback;
|
||||
import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
@@ -32,15 +33,51 @@ import org.springframework.integration.ftp.session.FtpFileInfo;
|
||||
* Outbound Gateway for performing remote file operations via FTP/FTPS.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 2.1
|
||||
*/
|
||||
public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway<FTPFile> {
|
||||
|
||||
public FtpOutboundGateway(SessionFactory<FTPFile> sessionFactory, String command,
|
||||
String expression) {
|
||||
/**
|
||||
* Construct an instance using the provided session factory and callback for
|
||||
* performing operations on the session.
|
||||
* @param sessionFactory the session factory.
|
||||
* @param messageSessionCallback the callback.
|
||||
*/
|
||||
public FtpOutboundGateway(SessionFactory<FTPFile> sessionFactory,
|
||||
MessageSessionCallback<FTPFile, ?> messageSessionCallback) {
|
||||
super(sessionFactory, messageSessionCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance with the supplied remote file template and callback
|
||||
* for performing operations on the session.
|
||||
* @param remoteFileTemplate the remote file template.
|
||||
* @param messageSessionCallback the callback.
|
||||
*/
|
||||
public FtpOutboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate,
|
||||
MessageSessionCallback<FTPFile, ?> messageSessionCallback) {
|
||||
super(remoteFileTemplate, messageSessionCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance with the supplied session factory, a command ('ls', 'get'
|
||||
* etc), and an expression to determine the filename.
|
||||
* @param sessionFactory the session factory.
|
||||
* @param command the command.
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public FtpOutboundGateway(SessionFactory<FTPFile> sessionFactory, String command, String expression) {
|
||||
super(sessionFactory, command, expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance with the supplied remote file template, a command ('ls',
|
||||
* 'get' etc), and an expression to determine the filename.
|
||||
* @param remoteFileTemplate the remote file template.
|
||||
* @param command the command.
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public FtpOutboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate, String command, String expression) {
|
||||
super(remoteFileTemplate, command, expression);
|
||||
}
|
||||
@@ -82,7 +119,6 @@ public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway<FTPFil
|
||||
canonicalFiles.add(new FtpFileInfo(file));
|
||||
}
|
||||
return canonicalFiles;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,5 +127,4 @@ public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway<FTPFil
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@
|
||||
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
|
||||
minOccurs="0" maxOccurs="1" />
|
||||
</xsd:all>
|
||||
<xsd:attribute name="command" use="required">
|
||||
<xsd:attribute name="command">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
FTP command.
|
||||
@@ -256,6 +256,20 @@
|
||||
<xsd:union memberTypes="int-file:remoteGatewayCommand xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="session-callback" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type
|
||||
type="org.springframework.integration.file.remote.MessageSessionCallback" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
The 'MessageSessionCallback' bean reference to perform custom operation(s) on 'Session'
|
||||
with 'requestMessage'.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="command-options" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -272,7 +286,7 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="expression" use="required" type="xsd:string">
|
||||
<xsd:attribute name="expression" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
SpEL expression representing the path in the
|
||||
@@ -462,8 +476,7 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-create-local-directory"
|
||||
type="xsd:boolean">
|
||||
<xsd:attribute name="auto-create-local-directory" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Tells this adapter if local directory must be
|
||||
|
||||
@@ -160,4 +160,14 @@
|
||||
<bean id="sortingFilter"
|
||||
class="org.springframework.integration.ftp.outbound.FtpServerOutboundTests$SortingFileListFilter"/>
|
||||
|
||||
<int-ftp:outbound-gateway
|
||||
session-factory="ftpSessionFactory"
|
||||
session-callback="messageSessionCallback"
|
||||
request-channel="inboundCallback"
|
||||
reply-channel="output"/>
|
||||
|
||||
<bean id="messageSessionCallback"
|
||||
class="org.springframework.integration.ftp.outbound.FtpServerOutboundTests$TestMessageSessionCallback"/>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -60,6 +60,7 @@ import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.file.FileHeaders;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.remote.InputStreamCallback;
|
||||
import org.springframework.integration.file.remote.MessageSessionCallback;
|
||||
import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
import org.springframework.integration.file.remote.SessionCallback;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
@@ -135,6 +136,9 @@ public class FtpServerOutboundTests {
|
||||
@Autowired
|
||||
private DirectChannel inboundGetStream;
|
||||
|
||||
@Autowired
|
||||
private DirectChannel inboundCallback;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.ftpServer.recursiveDelete(ftpServer.getTargetLocalDirectory());
|
||||
@@ -535,6 +539,14 @@ public class FtpServerOutboundTests {
|
||||
assertEquals(6, files[0].getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSessionCallback() {
|
||||
this.inboundCallback.send(new GenericMessage<String>("foo"));
|
||||
Message<?> receive = this.output.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("FOO", receive.getPayload());
|
||||
}
|
||||
|
||||
public static class SortingFileListFilter implements FileListFilter<File> {
|
||||
|
||||
@Override
|
||||
@@ -560,4 +572,15 @@ public class FtpServerOutboundTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class TestMessageSessionCallback
|
||||
implements MessageSessionCallback<FTPFile, Object> {
|
||||
|
||||
@Override
|
||||
public Object doInSession(Session<FTPFile> session, Message<?> requestMessage) throws IOException {
|
||||
return ((String) requestMessage.getPayload()).toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user