我正在使用建议将新的有效载荷标头发送到成功通道,在成功通道中,我正在使用outboundAdapter将file_originalFile发送到FTP服务器,但是我遇到了一个问题,即成功通道将文件发送为.msg和.msg旁边,当我想将foo.csv自身发送到ftp服务器时,可以看到显示file_originalFile名称的文本。
有什么可能的解决方案?
这是应用程序的代码
public IntegrationFlow localToFtpFlow(Branch myBranch) {
return IntegrationFlows.from(Files.inboundAdapter(new File(myBranch.getBranchCode()))
.filter(new ChainFileListFilter<File>()
.addFilter(new RegexPatternFileListFilter("final" + myBranch.getBranchCode() + ".csv"))
.addFilter(new FileSystemPersistentAcceptOnceFileListFilter(metadataStore(dataSource), "foo"))),//FileSystemPersistentAcceptOnceFileListFilter
e -> e.poller(Pollers.fixedDelay(10_000)))
.enrichHeaders(h ->h.header("file_originalFile", "new java.io.File('/BEY/FEFOexport" + myBranch.getBranchCode() + ".csv')",true))
.transform(p -> {
LOG1.info("Sending file " + p + " to FTP branch " + myBranch.getBranchCode());
return p;
})
.log()
.handle(Ftp.outboundAdapter(createNewFtpSessionFactory(myBranch), FileExistsMode.REPLACE)
.useTemporaryFileName(true)
.autoCreateDirectory(false)
.remoteDirectory(myBranch.getFolderPath()), e -> e.advice(expressionAdvice()))
.get();
}
/*
* Creating the advice for routing the payload of the outbound message on different expressions (success, failure)
*
* */
@Bean
public Advice expressionAdvice() {
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setSuccessChannelName("success.input");
advice.setOnSuccessExpressionString("payload.delete() + ' was successful'");
//advice.setFailureChannelName("failure.input");
advice.setOnFailureExpressionString("payload + ' was bad, with reason: ' + #exception.cause.message");
advice.setTrapException(true);
return advice;
}
/*
* Creating FTP connection based on the branch ftp data entered.
* */
public DefaultFtpSessionFactory createNewFtpSessionFactory(Branch branch) {
final DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory();
factory.setHost(branch.getHost());
factory.setUsername(branch.getUsern());
factory.setPort(branch.getFtpPort());
factory.setPassword(branch.getPassword());
return factory;
}
public DefaultFtpSessionFactory createNewFtpSessionFactory() {
final DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory();
factory.setHost("BEY");
factory.setUsername("bey-ftp");
factory.setPort(21);
factory.setPassword("spicysilk");
return factory;
}
/*
* Creating a metadata store to be used across the application flows to prevent reprocessing the file if it is already processed.
* This will save the new file in a metadata table in the DB with the state of the report, so when a new copy comes with different date it will be processed only.
* */
@Bean
public ConcurrentMetadataStore metadataStore(final DataSource dataSource) {
return new JdbcMetadataStore(dataSource);
}
/*
* Success channel that will handle the AdviceMessage from the outbound adapter
*
* */
@Bean
public IntegrationFlow success(){
return f -> f.transform("inputMessage.headers['file_originalFile']")
.handle(Ftp.outboundAdapter(createNewFtpSessionFactory(), FileExistsMode.REPLACE)
.useTemporaryFileName(true)
.autoCreateDirectory(true)
.remoteDirectory("/ftp/erbranch/EDMS/FEFO/History/"));
//f.handle(System.out::println);
}
调试:
2019-02-08 20:18:34.264 DEBUG 1368 --- [ask-scheduler-2] o.s.integration.channel.DirectChannel : postSend (sent=true) on channel '1o.channel#3', message: GenericMessage [payload=BEY\finalBEY.csv, headers={file_originalFile=new java.io.File('/BEY/FEFOexportBEY.csv'), id=e1b48bf4-ba44-bdd0-23bc-e335e3c377a1, file_name=finalBEY.csv, file_relativePath=finalBEY.csv, timestamp=1549649899453}]
2019-02-08 20:18:34.267 DEBUG 1368 --- [ask-scheduler-2] o.s.integration.channel.DirectChannel : postSend (sent=true) on channel '1o.channel#1', message: GenericMessage [payload=BEY\finalBEY.csv, headers={file_originalFile=new java.io.File('/BEY/FEFOexportBEY.csv'), id=0c599e08-a972-2ffc-cc9b-f45ff266ca98, file_name=finalBEY.csv, file_relativePath=finalBEY.csv, timestamp=1549649899439}]
2019-02-08 20:18:34.268 DEBUG 1368 --- [ask-scheduler-2] o.s.integration.channel.DirectChannel : postSend (sent=true) on channel '1o.channel#0', message: GenericMessage [payload=BEY\finalBEY.csv, headers={file_originalFile=BEY\finalBEY.csv, id=14336975-2e33-1990-63e0-3182726b47fe, file_name=finalBEY.csv, file_relativePath=finalBEY.csv, timestamp=1549649899439}]
答案 0 :(得分:0)
.enrichHeaders(h ->h.header("file_originalFile","/someDirectory/FEFOexport" + myBranch.getBranchCode() + ".csv",true))
标头仅包含文件名,而不包含File
。发送字符串时,它将成为远程文件的内容。在这种情况下,默认情况下,远程文件名使用FileHeaders.FILENAME
;如果没有这样的标头,则使用<messageId>.msg
。
使用
.enrichHeaders(h ->h.headerExpression("file_originalFile", "new java.io.File('/someDirectory/FEFOexport" + myBranch.getBranchCode() + ".csv')",true))