Apache Camel File2 仅包含源目录中的特定子文件夹
Apache Camel File2 include only specific subfolders from the source directory
我正在使用 Apache Camel File2 (SFTP)(使用 Camel 最新版本)和 Java8 API。
我正在尝试开发一个扩展 RouteBuilder class 并实现配置方法的 MyRouteBuilder.java class。
我想将文件从源路径传输到目标路径。
在源端点中,指定 URI 参数 "include" 以包含来自源路径下特定特定子文件夹的文件,例如 "SubFolder1, SubFolder2, SubFolder3".
示例源 URI:
1) "file:\src\SubFolder1\.*\.txt"
2) "file:\src\SubFolder2\.*\.txt"
我试过下面的多个例子,甚至
示例:
1) include=.SubFolder[1-2]\.*\.txt
2) include=.SubFolder1|SubFolder2\.*\.txt
3) include=SubFolder[1-2]\.*\.txt
4) include=SubFolder1\.*\.txt
5) include=.SubFolder(?)\.*\.txt
没有任何效果。
请提出使用 Apache Camel File2 API 使用 Java 解决问题的方法。
public void configure() throws Exception {
String sftpUrl = "sftp://" + user + "@" + hostName + sourcePath + "?" + "noop=true"
+ "&recursive=true&include=.*\.txt$"+"&strictHostKeyChecking=no" + "&useUserKnownHostsFile=true" + "&password=RAW("
+ password + ")&preferredAuthentications=publickey,keyboard-interactive,password";
System.out.println("\n\n sftpUrl + " + sftpUrl + "\n\n");
from(sftpUrl)
.log(" Copying File : ${file:name} ").process(exchange -> {
System.out.println("1. Processing a File --> = " + exchange);
}).to("file://" + destPath)
// ;
.log("Uploading file ${file:parent} / ${file:name} complete.");
}
如下@hk6279 所示,除非另有说明,否则 FTP2 继承 File2 并且 File2 行为在 FTP2 上可用。但是,@hk6279 强调了 OP 可能遗漏的一个非常重要的部分。
Only files (not directories) are matched for valid filename, if options such as: include or exclude are used.
可能这就是造成麻烦的原因。
看起来您指的是 FTP2 组件而不是 file2 组件。请查看 FTP component's test cases to see how filtering is implemented. It does not support include
option as you can see in the docs.
您应该使用 antInclude
,因为它同时支持目录和文件。
顺便说一句,Camel 网站正在进行彻底的重新设计,同时可以从 github.
浏览最新的组件文档。
antInclude=F1/*.txt,F2/*.txt
所以看:https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/docs/ftp-component.adoc
另外请注意,您可以浏览每个版本的文档(选择 branch/tag)。
我正在使用 Apache Camel File2 (SFTP)(使用 Camel 最新版本)和 Java8 API。 我正在尝试开发一个扩展 RouteBuilder class 并实现配置方法的 MyRouteBuilder.java class。
我想将文件从源路径传输到目标路径。 在源端点中,指定 URI 参数 "include" 以包含来自源路径下特定特定子文件夹的文件,例如 "SubFolder1, SubFolder2, SubFolder3".
示例源 URI: 1) "file:\src\SubFolder1\.*\.txt" 2) "file:\src\SubFolder2\.*\.txt"
我试过下面的多个例子,甚至 示例:
1) include=.SubFolder[1-2]\.*\.txt
2) include=.SubFolder1|SubFolder2\.*\.txt
3) include=SubFolder[1-2]\.*\.txt
4) include=SubFolder1\.*\.txt
5) include=.SubFolder(?)\.*\.txt
没有任何效果。
请提出使用 Apache Camel File2 API 使用 Java 解决问题的方法。
public void configure() throws Exception {
String sftpUrl = "sftp://" + user + "@" + hostName + sourcePath + "?" + "noop=true"
+ "&recursive=true&include=.*\.txt$"+"&strictHostKeyChecking=no" + "&useUserKnownHostsFile=true" + "&password=RAW("
+ password + ")&preferredAuthentications=publickey,keyboard-interactive,password";
System.out.println("\n\n sftpUrl + " + sftpUrl + "\n\n");
from(sftpUrl)
.log(" Copying File : ${file:name} ").process(exchange -> {
System.out.println("1. Processing a File --> = " + exchange);
}).to("file://" + destPath)
// ;
.log("Uploading file ${file:parent} / ${file:name} complete.");
}
如下@hk6279 所示,除非另有说明,否则 FTP2 继承 File2 并且 File2 行为在 FTP2 上可用。但是,@hk6279 强调了 OP 可能遗漏的一个非常重要的部分。
Only files (not directories) are matched for valid filename, if options such as: include or exclude are used.
可能这就是造成麻烦的原因。
看起来您指的是 FTP2 组件而不是 file2 组件。请查看 FTP component's test cases to see how filtering is implemented. It does not support include
option as you can see in the docs.
您应该使用 antInclude
,因为它同时支持目录和文件。
顺便说一句,Camel 网站正在进行彻底的重新设计,同时可以从 github.
antInclude=F1/*.txt,F2/*.txt
所以看:https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/docs/ftp-component.adoc
另外请注意,您可以浏览每个版本的文档(选择 branch/tag)。