GH-3026: Fix chmod support for DSL
Fixes https://github.com/spring-projects/spring-integration/issues/3026 **Cherry-pick to `5.1.x`** * Populate proper `FileTransferringMessageHandler` impl from DSL spec implementations. This way we are able to use a provided `chmod` from Java DSL * Added `FileTransferringMessageHandlerSpec` ctor TODO * Update SftpTests * Code cleanup; `@Ignore` `SftpTests.testSftpOutboundFlowWithChmod()` since it doesn't work properly on Windows
This commit is contained in:
committed by
Artem Bilan
parent
66c3eff2ba
commit
7aea76c6c4
@@ -22,25 +22,28 @@ import org.springframework.integration.file.dsl.FileTransferringMessageHandlerSp
|
||||
import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.file.support.FileExistsMode;
|
||||
import org.springframework.integration.ftp.outbound.FtpMessageHandler;
|
||||
|
||||
/**
|
||||
* A {@link FileTransferringMessageHandlerSpec} for FTP.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Joaquin Santana
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public class FtpMessageHandlerSpec extends FileTransferringMessageHandlerSpec<FTPFile, FtpMessageHandlerSpec> {
|
||||
|
||||
FtpMessageHandlerSpec(SessionFactory<FTPFile> sessionFactory) {
|
||||
super(sessionFactory);
|
||||
this.target = new FtpMessageHandler(sessionFactory);
|
||||
}
|
||||
|
||||
FtpMessageHandlerSpec(RemoteFileTemplate<FTPFile> remoteFileTemplate) {
|
||||
super(remoteFileTemplate);
|
||||
this.target = new FtpMessageHandler(remoteFileTemplate.getSessionFactory());
|
||||
}
|
||||
|
||||
FtpMessageHandlerSpec(RemoteFileTemplate<FTPFile> remoteFileTemplate, FileExistsMode fileExistsMode) {
|
||||
super(remoteFileTemplate, fileExistsMode);
|
||||
this.target = new FtpMessageHandler(remoteFileTemplate, fileExistsMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.springframework.util.FileCopyUtils;
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @author Joaquin Santana
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -192,6 +193,30 @@ public class FtpTests extends FtpTestSupport {
|
||||
registration.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFtpOutboundFlowWithChmod() {
|
||||
IntegrationFlow flow = f -> f
|
||||
.handle(Ftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL)
|
||||
.useTemporaryFileName(false)
|
||||
.fileNameExpression("headers['" + FileHeaders.FILENAME + "']")
|
||||
.chmod(0644)
|
||||
.remoteDirectory("ftpTarget"));
|
||||
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
|
||||
String fileName = "foo.file";
|
||||
Message<ByteArrayInputStream> message = MessageBuilder
|
||||
.withPayload(new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)))
|
||||
.setHeader(FileHeaders.FILENAME, fileName)
|
||||
.build();
|
||||
registration.getInputChannel().send(message);
|
||||
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(sessionFactory());
|
||||
FTPFile[] files = template.execute(session ->
|
||||
session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
|
||||
assertThat(files.length).isEqualTo(1);
|
||||
assertThat(files[0].getSize()).isEqualTo(3);
|
||||
|
||||
registration.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testFtpMgetFlow() {
|
||||
|
||||
Reference in New Issue
Block a user