Add (S)FTP Inbound Java Config samples into Docs
This commit is contained in:
@@ -326,6 +326,97 @@ This will work for any `ResettableFileListFilter`.
|
||||
class="org.springframework.integration.transaction.PseudoTransactionManager" />
|
||||
----
|
||||
|
||||
==== Configuring with Java Configuration
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using Java configuration:
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class FtpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(FtpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SessionFactory<FTPFile> ftpSessionFactory() {
|
||||
DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
|
||||
sf.setHost("localhost");
|
||||
sf.setPort(port);
|
||||
sf.setUsername("foo");
|
||||
sf.setPassword("foo");
|
||||
return new CachingSessionFactory<FTPFile>(sf);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FtpInboundFileSynchronizer ftpInboundFileSynchronizer() {
|
||||
FtpInboundFileSynchronizer fileSynchronizer = new FtpInboundFileSynchronizer(ftpSessionFactory());
|
||||
fileSynchronizer.setDeleteRemoteFiles(false);
|
||||
fileSynchronizer.setRemoteDirectory("/");
|
||||
fileSynchronizer.setFilter(new FtpSimplePatternFileListFilter("*.xml"));
|
||||
return fileSynchronizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(channel = "ftpChannel")
|
||||
public MessageSource<File> ftpMessageSource() {
|
||||
FtpInboundFileSynchronizingMessageSource source =
|
||||
new FtpInboundFileSynchronizingMessageSource(ftpInboundFileSynchronizer());
|
||||
source.setLocalDirectory(new File("ftp-inbound"));
|
||||
source.setAutoCreateLocalDirectory(true);
|
||||
source.setLocalFilter(new AcceptOnceFileListFilter<File>());
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "ftpChannel")
|
||||
public MessageHandler handler() {
|
||||
return new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
System.out.println(message.getPayload());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
==== Configuring with the Java DSL
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using the Java DSL:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class FtpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(FtpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow ftpInboundFlow() {
|
||||
return IntegrationFlows
|
||||
.from(s -> s.ftp(this.ftpSessionFactory)
|
||||
.preserveTimestamp(true)
|
||||
.remoteDirectory("ftpSource")
|
||||
.regexFilter(".*\\.txt$")
|
||||
.localFilename(f -> f.toUpperCase() + ".a")
|
||||
.localDirectory(new File("d:\ftp_files")),
|
||||
e -> e.id("ftpInboundAdapter").autoStartup(false))
|
||||
.handle(m -> System.out.println(m.getPayload()))
|
||||
.get();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
[[ftp-streaming]]
|
||||
=== FTP Streaming Inbound Channel Adapter
|
||||
|
||||
@@ -361,6 +452,44 @@ file being processed again, you can configure an `FtpPersistentFileListFilter` i
|
||||
If you don't actually want to persist the state, an in-memory `SimpleMetadataStore` can be used with the filter.
|
||||
If you wish to use a filename pattern (or regex) as well, use a `CompositeFileListFilter`.
|
||||
|
||||
==== Configuring with Java Configuration
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using Java configuration:
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class FtpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(FtpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(channel = "stream")
|
||||
public MessageSource<InputStream> ftpMessageSource() {
|
||||
FtpStreamingMessageSource messageSource = new FtpStreamingMessageSource(template(), null);
|
||||
messageSource.setRemoteDirectory("ftpSource/");
|
||||
messageSource.setFilter(new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(),
|
||||
"streaming"));
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Transformer(inputChannel = "stream", outputChannel = "data")
|
||||
public org.springframework.integration.transformer.Transformer transformer() {
|
||||
return new StreamTransformer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FtpRemoteFileTemplate template() {
|
||||
return new FtpRemoteFileTemplate(ftpSessionFactory());
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
[[ftp-outbound]]
|
||||
=== FTP Outbound Channel Adapter
|
||||
|
||||
|
||||
@@ -434,6 +434,98 @@ This will work for any `ResettableFileListFilter`.
|
||||
class="org.springframework.integration.transaction.PseudoTransactionManager" />
|
||||
----
|
||||
|
||||
==== Configuring with Java Configuration
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using Java configuration:
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class SftpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(SftpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SessionFactory<LsEntry> sftpSessionFactory() {
|
||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||
factory.setHost("localhost");
|
||||
factory.setPort(port);
|
||||
factory.setUser("foo");
|
||||
factory.setPassword("foo");
|
||||
factory.setAllowUnknownKeys(true);
|
||||
return new CachingSessionFactory<LsEntry>(factory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
|
||||
SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||
fileSynchronizer.setDeleteRemoteFiles(false);
|
||||
fileSynchronizer.setRemoteDirectory("/");
|
||||
fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter("*.xml"));
|
||||
return fileSynchronizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(channel = "sftpChannel")
|
||||
public MessageSource<File> sftpMessageSource() {
|
||||
SftpInboundFileSynchronizingMessageSource source =
|
||||
new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
|
||||
source.setLocalDirectory(new File("ftp-inbound"));
|
||||
source.setAutoCreateLocalDirectory(true);
|
||||
source.setLocalFilter(new AcceptOnceFileListFilter<File>());
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ServiceActivator(inputChannel = "sftpChannel")
|
||||
public MessageHandler handler() {
|
||||
return new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
System.out.println(message.getPayload());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
==== Configuring with the Java DSL
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using the Java DSL:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class SftpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(SftpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow sftpInboundFlow() {
|
||||
return IntegrationFlows
|
||||
.from(s -> s.sftp(this.sftpSessionFactory)
|
||||
.preserveTimestamp(true)
|
||||
.remoteDirectory("sftpSource")
|
||||
.regexFilter(".*\\.txt$")
|
||||
.localFilenameExpression("#this.toUpperCase() + '.a'")
|
||||
.localDirectory(this.sftpServer.getTargetLocalDirectory()),
|
||||
e -> e.id("sftpInboundAdapter").autoStartup(false))
|
||||
.handle(m -> System.out.println(m.getPayload()))
|
||||
.get();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
[[sftp-streaming]]
|
||||
=== SFTP Streaming Inbound Channel Adapter
|
||||
|
||||
@@ -469,6 +561,45 @@ file being processed again, you can configure an `SftpPersistentFileListFilter`
|
||||
If you don't actually want to persist the state, an in-memory `SimpleMetadataStore` can be used with the filter.
|
||||
If you wish to use a filename pattern (or regex) as well, use a `CompositeFileListFilter`.
|
||||
|
||||
==== Configuring with Java Configuration
|
||||
|
||||
The following Spring Boot application provides an example of configuring the inbound adapter using Java configuration:
|
||||
[source, java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class SftpJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(SftpJavaApplication.class)
|
||||
.web(false)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(channel = "stream")
|
||||
public MessageSource<InputStream> ftpMessageSource() {
|
||||
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template(), null);
|
||||
messageSource.setRemoteDirectory("sftpSource/");
|
||||
messageSource.setFilter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(),
|
||||
"streaming"));
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Transformer(inputChannel = "stream", outputChannel = "data")
|
||||
public org.springframework.integration.transformer.Transformer transformer() {
|
||||
return new StreamTransformer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SftpRemoteFileTemplate template() {
|
||||
return new SftpRemoteFileTemplate(sftpSessionFactory());
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[sftp-outbound]]
|
||||
=== SFTP Outbound Channel Adapter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user