Java 骆驼sftp生产商。如何将多个文件从单个处理器放入不同的sftp文件夹
我使用DSL配置和spring 我的路线如下所示:Java 骆驼sftp生产商。如何将多个文件从单个处理器放入不同的sftp文件夹,java,spring,configuration,sftp,spring-camel,Java,Spring,Configuration,Sftp,Spring Camel,我使用DSL配置和spring 我的路线如下所示: @Component public class UploadRoutesDefinition extends RouteBuilder { @Override public void configure() throws Exception { from("seda:rest_upload") .process(new Processor() { @Over
@Component
public class UploadRoutesDefinition extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.process(new Processor() {
@Override
public void process(Exchange exchange) {
...
String sftPathForAdditionalFile = ....
String AdditionalFileContent = ...
...
}
).to(String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath(),
systemSettingsService.getSystemSettings().getSftpPassword()))
它允许我从seda:rest\u upload
读取文件,然后将其移动到sftp文件夹
我想再移动一个文件。我知道过程
方法中的路径和内容
我怎样才能做到呢
更新
我目前的代码
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelFilename", "ololo.txt");
exchange.getIn().setBody(exchange.getProperty(PUSH_ERROR_MESSAGE, String.class).getBytes());
exchange.getIn().setHeader("destFilePath", sftpErrorFileTextPath);
}
})
.to(String.format(SFTP_BASE_URL + "&fileExist=Append",
systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword()))
.end();
这里有一种方法
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.multicast()
.to("direct::sendMainFile")
.to("direct:sendAnotherFile") // You could also use seda:
.end();
from("direct:sendMainFile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String filepath = <calculate filepath>;
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
exchange.getIn().setHeader("CamelFileName", fileNameforMainFile);
}
}.toD(sftpRoute()) // It is toD not to
from("direct:sendAnotherfile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// Here you have the same body which was sent from rest_upload
// extract the info from exchange.getIn().getBody()
// Read the file and set it as exchange body
String fileContent = <Your logic to read file>
exchange.getIn().setBody(fileContent);
exchange.getIn().setHeader("CamelFileName", fileNameforYourAdditionalFile)
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
}
})
.toD(sftpRoute()); // It is toD not to
}
private String sftpRoute() {
return String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword())
}
}
@覆盖
public void configure()引发异常{
来自(“seda:rest_上传”)
.multicast()
.to(“direct::sendMainFile”)
.to(“direct:sendAnotherFile”)//您也可以使用seda:
.end();
来自(“直接:sendMainFile”)
.进程(新处理器(){
@凌驾
公共作废进程(Exchange)引发异常{
字符串filepath=;
字符串completeFilePath=systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath()+文件路径
exchange.getIn().setHeader(“destFilePath”,completeFilePath);
exchange.getIn().setHeader(“CamelFileName”,filenameformainle);
}
}.toD(sftpRoute())//不能
发件人(“直接:发送其他文件”)
.进程(新处理器(){
@凌驾
公共作废进程(Exchange)引发异常{
//这里你有相同的身体,这是从rest_上传发送的
//从exchange.getIn().getBody()中提取信息
//读取文件并将其设置为exchange正文
字符串文件内容=
exchange.getIn().setBody(fileContent);
exchange.getIn().setHeader(“CamelFileName”,您的附加文件的文件名)
字符串completeFilePath=systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath()+文件路径
exchange.getIn().setHeader(“destFilePath”,completeFilePath);
}
})
.toD(sftpRoute());//不能
}
私有字符串sftpRoute(){
返回String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
“${header.destFilePath}”,
systemSettingsService.getSystemSettings().GetSFTPassword())
}
}
您可以将来自rest\u upload的文件和添加文件保存在某个位置。然后创建一个路由,该路由将登录到此目录并上载到ftp@pvpkiran是的,这会起作用,但不是很方便。我不认为你可以通过任何其他方式来实现。原因是,发送到ftp的内容就是文件中的内容交换主体(根据您的上一步设置,即您案例中的流程(…)。并且您不能有多个实体。@pvpkiran,但无论如何,我不能使用camel保存文件。我需要手动操作此附加文件的路径是否会根据您从rest_上载获得的内容而更改,还是独立于它?在sftp上,我有文件夹/输出。假设我需要放置名为file1.txt的文件。其父文件夹的计算取决于loginc正在处理中。因此,我需要根据路径输出/some_computed_name/file1.txt放置文件。看起来我无法使用您的方法完成我的任务。实际上,我需要在主文件附近放置其他文件。我无法完全理解您要说的内容。当您有相同的正文时,可以使用相同的逻辑来计算哪个目录我不明白你的代码如何允许使用进程方法中计算的目录名你是指ftp服务器上的目标目录?这是什么systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath()),
?能否显示SFTP_BASE_URL中的内容,如果希望两个文件在ftp上位于同一路径上,可以保存该路径并在sftpRoute()函数中使用它是的,我正在确定SFTP。最终目标应为systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath()/某些文件夹名称/文件名称