GH-3554: Eval remote dir on each synchToLocal (#3556)
* GH-3554: Eval remote dir on each synchToLocal Fixes https://github.com/spring-projects/spring-integration/issues/3554 The `remoteDirectoryExpression` was introduced into an `AbstractInboundFileSynchronizer` to let end-user to evaluate a remote directory on each poll (essentially on each `synchronizeToLocalDirectory()` call). The fix for the https://jira.spring.io/browse/INT-4491 introduced a regression when such an expression was evaluated only once when we call a `setRemoteDirectory()`. So, an original purpose of this option was lost and we don't get an actual remote dir on each poll * Remove `evaluateRemoteDirectory()` method and its usage since it doesn't reflect expectation of the remote dir expression property * Reinstate the `remoteDirectoryExpression` evaluation in the `synchronizeToLocalDirectory()` * Propagate the result of that expression into further methods for copying files * Remove setting of the `remoteDirectory` variable into a global `EvaluationContext` of the `AbstractInboundFileSynchronizer` instance since it is not thread-safe * Instead create an `EvaluationContext` locally for each `synchronizeToLocalDirectory()` call and set the `remoteDirectory` variable into this scoped instances * Generate a local file name from the `localFilenameGeneratorExpression` against locally created `EvaluationContext` with the mentioned `remoteDirectory` variable * Cover the expected functionality with a unit-test **Cherry-pick to `5.4.x` & `5.3.x`** * * Fix `testRemoteDirectoryRefreshedOnEachSynchronization` according PR review
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.integration.file.DirectoryScanner;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
@@ -136,7 +137,8 @@ public class FtpInboundChannelAdapterParserTests {
|
||||
method.setAccessible(true);
|
||||
genMethod.set(method);
|
||||
}, method -> "generateLocalFileName".equals(method.getName()));
|
||||
assertThat(genMethod.get().invoke(fisync, "foo")).isEqualTo("FOO.afoo");
|
||||
assertThat(genMethod.get().invoke(fisync, "foo", ExpressionUtils.createStandardEvaluationContext(this.context)))
|
||||
.isEqualTo("FOO.afoo");
|
||||
assertThat(inbound.getMaxFetchSize()).isEqualTo(42);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user