Skip to content

Commit 2e409aa

Browse files
garyrussellartembilan
authored andcommitted
GH-3175: Add .scanner() to inbound file sync spec
Resolves #3175 * Fix `@since` for backport **Cherry-pick to `5.2.x`** (cherry picked from commit 1ff69d4)
1 parent 23b1a9f commit 2e409aa

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import org.springframework.integration.dsl.ComponentsRegistration;
2626
import org.springframework.integration.dsl.MessageSourceSpec;
2727
import org.springframework.integration.expression.FunctionExpression;
28+
import org.springframework.integration.file.DirectoryScanner;
2829
import org.springframework.integration.file.filters.ExpressionFileListFilter;
2930
import org.springframework.integration.file.filters.FileListFilter;
3031
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer;
@@ -270,6 +271,17 @@ public S metadataStorePrefix(String metadataStorePrefix) {
270271
return _this();
271272
}
272273

274+
/**
275+
* Configure a scanner to use for the file system scan after transfer.
276+
* @param scanner the scanner.
277+
* @return the spec.
278+
* @since 5.2.4
279+
*/
280+
public S scanner(DirectoryScanner scanner) {
281+
this.target.setScanner(scanner);
282+
return _this();
283+
}
284+
273285
@Override
274286
public Map<Object, String> getComponentsToRegister() {
275287
Map<Object, String> componentsToRegister = new LinkedHashMap<>();

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,9 @@
2525
import java.io.IOException;
2626
import java.io.InputStream;
2727
import java.nio.charset.StandardCharsets;
28+
import java.util.Iterator;
2829
import java.util.List;
30+
import java.util.Map;
2931
import java.util.regex.Matcher;
3032

3133
import org.apache.commons.net.ftp.FTPFile;
@@ -47,6 +49,8 @@
4749
import org.springframework.integration.dsl.StandardIntegrationFlow;
4850
import org.springframework.integration.dsl.context.IntegrationFlowContext;
4951
import org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration;
52+
import org.springframework.integration.file.DefaultDirectoryScanner;
53+
import org.springframework.integration.file.DirectoryScanner;
5054
import org.springframework.integration.file.FileHeaders;
5155
import org.springframework.integration.file.remote.RemoteFileTemplate;
5256
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
@@ -86,17 +90,24 @@ public class FtpTests extends FtpTestSupport {
8690
@Test
8791
public void testFtpInboundFlow() throws IOException {
8892
QueueChannel out = new QueueChannel();
93+
DirectoryScanner scanner = new DefaultDirectoryScanner();
8994
IntegrationFlow flow = IntegrationFlows.from(Ftp.inboundAdapter(sessionFactory())
9095
.preserveTimestamp(true)
9196
.remoteDirectory("ftpSource")
9297
.maxFetchSize(10)
98+
.scanner(scanner)
9399
.regexFilter(".*\\.txt$")
94100
.localFilename(f -> f.toUpperCase() + ".a")
95101
.localDirectory(getTargetLocalDirectory()),
96102
e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100)))
97103
.channel(out)
98104
.get();
99105
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
106+
Map<?, ?> components = TestUtils.getPropertyValue(registration, "integrationFlow.integrationComponents", Map.class);
107+
Iterator<?> iterator = components.keySet().iterator();
108+
iterator.next();
109+
Object spcafb = iterator.next();
110+
assertThat(TestUtils.getPropertyValue(spcafb, "source.fileSource.scanner")).isSameAs(scanner);
100111
Message<?> message = out.receive(10_000);
101112
assertThat(message).isNotNull();
102113
assertThat(message.getHeaders())

0 commit comments

Comments
 (0)