diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java index de3e91d8da..2645d32409 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author David Turanski * @author Gary Russell + * * @since 2.0 */ public class FileTransferringMessageHandler extends AbstractMessageHandler { @@ -89,6 +90,16 @@ public class FileTransferringMessageHandler extends AbstractMessageHandler { this.remoteFileTemplate.setRemoteDirectoryExpression(remoteDirectoryExpression); } + /** + * Specify a remote directory path SpEL expression. + * @param remoteDirectoryExpression the remote directory expression + * @since 4.3.13 + * @see #setRemoteDirectoryExpression(Expression) + */ + public void setRemoteDirectoryExpressionString(String remoteDirectoryExpression) { + setRemoteDirectoryExpression(EXPRESSION_PARSER.parseExpression(remoteDirectoryExpression)); + } + /** * Specify a remote directory path SpEL expression. * @param temporaryRemoteDirectoryExpression the temporary remote directory expression @@ -98,6 +109,16 @@ public class FileTransferringMessageHandler extends AbstractMessageHandler { this.remoteFileTemplate.setTemporaryRemoteDirectoryExpression(temporaryRemoteDirectoryExpression); } + /** + * Specify a remote directory path SpEL expression. + * @param temporaryRemoteDirectoryExpression the temporary remote directory expression + * @since 4.3.13 + * @see #setTemporaryRemoteDirectoryExpression(Expression) + */ + public void setTemporaryRemoteDirectoryExpressionString(String temporaryRemoteDirectoryExpression) { + setTemporaryRemoteDirectoryExpression(EXPRESSION_PARSER.parseExpression(temporaryRemoteDirectoryExpression)); + } + protected String getTemporaryFileSuffix() { return this.remoteFileTemplate.getTemporaryFileSuffix(); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index 7f42d5b456..5e87690360 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -36,7 +36,9 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; +import org.springframework.expression.ExpressionParser; import org.springframework.expression.common.LiteralExpression; +import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.integration.expression.ExpressionUtils; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.ResettableFileListFilter; @@ -67,6 +69,8 @@ import org.springframework.util.ObjectUtils; public abstract class AbstractInboundFileSynchronizer implements InboundFileSynchronizer, BeanFactoryAware, InitializingBean, Closeable { + protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); + protected final Log logger = LogFactory.getLog(this.getClass()); private final RemoteFileTemplate remoteFileTemplate; @@ -135,6 +139,16 @@ public abstract class AbstractInboundFileSynchronizer this.localFilenameGeneratorExpression = localFilenameGeneratorExpression; } + /** + * Set an expression used to determine the local file name. + * @param localFilenameGeneratorExpression the expression. + * @since 4.3.13 + * @see #setRemoteDirectoryExpression(Expression) + */ + public void setLocalFilenameGeneratorExpressionString(String localFilenameGeneratorExpression) { + setLocalFilenameGeneratorExpression(EXPRESSION_PARSER.parseExpression(localFilenameGeneratorExpression)); + } + /** * Set a temporary file suffix to be used while transferring files. Default ".writing". * @param temporaryFileSuffix the file suffix. @@ -161,6 +175,17 @@ public abstract class AbstractInboundFileSynchronizer doSetRemoteDirectoryExpression(remoteDirectoryExpression); } + /** + * Specify an expression that evaluates to the full path to the remote directory. + * @param remoteDirectoryExpression The remote directory expression. + * @since 4.3.13 + * @see #setRemoteDirectoryExpression(Expression) + */ + public void setRemoteDirectoryExpressionString(String remoteDirectoryExpression) { + setRemoteDirectoryExpression(EXPRESSION_PARSER.parseExpression(remoteDirectoryExpression)); + } + + protected final void doSetRemoteDirectoryExpression(Expression remoteDirectoryExpression) { Assert.notNull(remoteDirectoryExpression, "'remoteDirectoryExpression' must not be null"); this.remoteDirectoryExpression = remoteDirectoryExpression; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java index c02994becc..afeb3a6b04 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java @@ -811,7 +811,7 @@ public class RemoteFileOutboundGatewayTests { template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", null); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory); - handler.setRemoteDirectoryExpression(new LiteralExpression("foo/")); + handler.setRemoteDirectoryExpressionString("'foo/'"); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); gw.afterPropertiesSet(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java index ff03cbb365..46cfbc191d 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java @@ -53,6 +53,7 @@ import org.springframework.messaging.support.GenericMessage; * @author Oleg Zhurakousky * @author Gary Russell * @author Gunnar Hillert + * @author Artem Bilan */ public class FileTransferringMessageHandlerTests { @@ -130,10 +131,9 @@ public class FileTransferringMessageHandlerTests { SessionFactory sf = mock(SessionFactory.class); Session session = mock(Session.class); when(sf.getSession()).thenReturn(session); - ExpressionParser parser = new SpelExpressionParser(); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sf); handler.setBeanFactory(mock(BeanFactory.class)); - handler.setRemoteDirectoryExpression(parser.parseExpression("headers['path']")); + handler.setRemoteDirectoryExpressionString("headers['path']"); handler.setTemporaryFileSuffix(null); handler.onInit(); } @@ -169,7 +169,7 @@ public class FileTransferringMessageHandlerTests { Session session2 = newSession(); Session session3 = newSession(); when(sf.getSession()).thenReturn(session1, session2, session3); - handler.setRemoteDirectoryExpression(new LiteralExpression("foo")); + handler.setRemoteDirectoryExpressionString("'foo'"); handler.afterPropertiesSet(); for (int i = 0; i < 3; i++) { try { diff --git a/src/reference/asciidoc/ftp.adoc b/src/reference/asciidoc/ftp.adoc index f53079ca47..d7ddd4f262 100644 --- a/src/reference/asciidoc/ftp.adoc +++ b/src/reference/asciidoc/ftp.adoc @@ -720,7 +720,7 @@ public class FtpJavaApplication { @ServiceActivator(inputChannel = "ftpChannel") public MessageHandler handler() { FtpMessageHandler handler = new FtpMessageHandler(ftpSessionFactory()); - handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); + handler.setRemoteDirectoryExpressionString("headers['remote-target-dir']"); handler.setFileNameGenerator(new FileNameGenerator() { @Override diff --git a/src/reference/asciidoc/sftp.adoc b/src/reference/asciidoc/sftp.adoc index 9025575796..a447b49cf6 100644 --- a/src/reference/asciidoc/sftp.adoc +++ b/src/reference/asciidoc/sftp.adoc @@ -773,7 +773,7 @@ public class SftpJavaApplication { @ServiceActivator(inputChannel = "toSftpChannel") public MessageHandler handler() { SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory()); - handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); + handler.setRemoteDirectoryExpressionString("headers['remote-target-dir']"); handler.setFileNameGenerator(new FileNameGenerator() { @Override