diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/FileTransferringMessageHandlerSpec.java b/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/FileTransferringMessageHandlerSpec.java index 46a196758d..4e58423fb8 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/FileTransferringMessageHandlerSpec.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/FileTransferringMessageHandlerSpec.java @@ -41,6 +41,7 @@ import org.springframework.util.Assert; * @param the target {@link FileTransferringMessageHandlerSpec} implementation type. * * @author Artem Bilan + * @author Joaquin Santana * * @since 5.0 */ @@ -52,6 +53,10 @@ public abstract class FileTransferringMessageHandlerSpec sessionFactory) { this.target = new FileTransferringMessageHandler<>(sessionFactory); } @@ -62,6 +67,7 @@ public abstract class FileTransferringMessageHandlerSpec remoteFileTemplate, FileExistsMode fileExistsMode) { + this.target = new FileTransferringMessageHandler<>(remoteFileTemplate, fileExistsMode); } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/FtpMessageHandlerSpec.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/FtpMessageHandlerSpec.java index 97d992eb78..260ae0d8cb 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/FtpMessageHandlerSpec.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/FtpMessageHandlerSpec.java @@ -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 { FtpMessageHandlerSpec(SessionFactory sessionFactory) { - super(sessionFactory); + this.target = new FtpMessageHandler(sessionFactory); } FtpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate) { - super(remoteFileTemplate); + this.target = new FtpMessageHandler(remoteFileTemplate.getSessionFactory()); } FtpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate, FileExistsMode fileExistsMode) { - super(remoteFileTemplate, fileExistsMode); + this.target = new FtpMessageHandler(remoteFileTemplate, fileExistsMode); } } diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java index 3d4238b731..993df7bfb6 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java @@ -74,6 +74,7 @@ import org.springframework.util.FileCopyUtils; /** * @author Artem Bilan * @author Gary Russell + * @author Joaquin Santana * * @since 5.0 */ @@ -197,6 +198,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 message = MessageBuilder + .withPayload(new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8))) + .setHeader(FileHeaders.FILENAME, fileName) + .build(); + registration.getInputChannel().send(message); + RemoteFileTemplate template = new RemoteFileTemplate<>(sessionFactory()); + FTPFile[] files = template.execute(session -> + session.list(getTargetRemoteDirectory().getName() + "/" + fileName)); + assertEquals(1, files.length); + assertEquals(3, files[0].getSize()); + + registration.destroy(); + } + @Test @SuppressWarnings("unchecked") public void testFtpMgetFlow() { diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/SftpMessageHandlerSpec.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/SftpMessageHandlerSpec.java index ae6370eb27..e0d150fbfc 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/SftpMessageHandlerSpec.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/SftpMessageHandlerSpec.java @@ -20,26 +20,30 @@ 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.sftp.outbound.SftpMessageHandler; +import org.springframework.integration.sftp.session.SftpRemoteFileTemplate; import com.jcraft.jsch.ChannelSftp; /** * @author Artem Bilan + * @author Joaquin Santana + * * @since 5.0 */ public class SftpMessageHandlerSpec extends FileTransferringMessageHandlerSpec { SftpMessageHandlerSpec(SessionFactory sessionFactory) { - super(sessionFactory); + this.target = new SftpMessageHandler(sessionFactory); } SftpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate) { - super(remoteFileTemplate); + this.target = new SftpMessageHandler(remoteFileTemplate.getSessionFactory()); } SftpMessageHandlerSpec(RemoteFileTemplate remoteFileTemplate, FileExistsMode fileExistsMode) { - super(remoteFileTemplate, fileExistsMode); + this.target = new SftpMessageHandler(new SftpRemoteFileTemplate(remoteFileTemplate.getSessionFactory()), fileExistsMode); } } diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java index 5c2bf1c85e..3bcd94b096 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.regex.Matcher; import org.hamcrest.Matchers; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,6 +62,7 @@ import com.jcraft.jsch.ChannelSftp; /** * @author Artem Bilan * @author Gary Russell + * @author Joaquin Santana * * @since 5.0 * @@ -152,6 +154,34 @@ public class SftpTests extends SftpTestSupport { registration.destroy(); } + + @Test + @Ignore("Doesn't work as expected on Windows") + public void testSftpOutboundFlowWithChmod() { + IntegrationFlow flow = f -> f.handle(Sftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL) + .useTemporaryFileName(false) + .fileNameExpression("headers['" + FileHeaders.FILENAME + "']") + .chmod(0644) + .remoteDirectory("sftpTarget")); + IntegrationFlowRegistration registration = this.flowContext.registration(flow).register(); + String fileName = "foo.file"; + registration.getInputChannel().send(MessageBuilder.withPayload("foo") + .setHeader(FileHeaders.FILENAME, fileName) + .build()); + + RemoteFileTemplate template = new RemoteFileTemplate<>(sessionFactory()); + ChannelSftp.LsEntry[] files = template.execute(session -> + session.list(getTargetRemoteDirectory().getName() + "/" + fileName)); + assertEquals(1, files.length); + assertEquals(3, files[0].getAttrs().getSize()); + String[] permissions = files[0].getAttrs().getPermissionsString().substring(1).replaceAll("--", "-").split("-"); + assertEquals("rw", permissions[0]); + assertEquals("r", permissions[1]); + assertEquals("r", permissions[2]); + + registration.destroy(); + } + @Test @SuppressWarnings("unchecked") public void testSftpMgetFlow() { diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java index a8bb3c4108..cdab8c835c 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/inbound/SftpInboundRemoteFileSystemSynchronizerTests.java @@ -64,6 +64,8 @@ import com.jcraft.jsch.SftpATTRS; * @author Gunnar Hillert * @author Gary Russell * @author Artem Bilan + * @author Joaquin Santana + * * @since 2.0 */ public class SftpInboundRemoteFileSystemSynchronizerTests { @@ -170,7 +172,8 @@ public class SftpInboundRemoteFileSystemSynchronizerTests { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); - when(lsEntry.getAttrs().getMTime()).thenReturn(new Long(calendar.getTimeInMillis() / 1000).intValue()); + when(lsEntry.getAttrs().getMTime()) + .thenReturn(Long.valueOf(calendar.getTimeInMillis() / 1000).intValue()); when(lsEntry.getFilename()).thenReturn(fileName); when(lsEntry.getLongname()).thenReturn(fileName); sftpEntries.add(lsEntry);