INT-4356: FileTransferMH: Add string SpEL setters
JIRA: https://jira.spring.io/browse/INT-4356 **Cherry-pick to 4.3.x** Address PR comments: * Remove unused variable in the test case * Add string-based SpEL setters to the `AbstractInboundFileSynchronizer` * Fix `@since` in the `FileTransferringMessageHandler` to the proper version
This commit is contained in:
committed by
Gary Russell
parent
a5d30b9f66
commit
1fa73a9728
@@ -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<F> extends AbstractMessageHandler {
|
||||
@@ -89,6 +90,16 @@ public class FileTransferringMessageHandler<F> 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<F> 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();
|
||||
}
|
||||
|
||||
@@ -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<F>
|
||||
implements InboundFileSynchronizer, BeanFactoryAware, InitializingBean, Closeable {
|
||||
|
||||
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final RemoteFileTemplate<F> remoteFileTemplate;
|
||||
@@ -135,6 +139,16 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
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<F>
|
||||
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;
|
||||
|
||||
@@ -811,7 +811,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
template.afterPropertiesSet();
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", null);
|
||||
FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<TestLsEntry>(sessionFactory);
|
||||
handler.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
|
||||
handler.setRemoteDirectoryExpressionString("'foo/'");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
gw.afterPropertiesSet();
|
||||
|
||||
@@ -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<F> sf = mock(SessionFactory.class);
|
||||
Session<F> session = mock(Session.class);
|
||||
when(sf.getSession()).thenReturn(session);
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
FileTransferringMessageHandler<F> handler = new FileTransferringMessageHandler<F>(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<F> session2 = newSession();
|
||||
Session<F> 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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user