我在使用DSL的SFTP出站网关时遇到问题 . 我想使用出站网关发送文件,然后继续我的流程 . 问题是我有一个例外告诉我:
IllegalArgumentException: 'remoteDirectoryExpression' is required
我看到我可以使用RemoteFileTemplate,我可以在其中设置sftp会话工厂和远程目录信息,但是我不想通过在批处理启动之前放入 Headers 中的代码在我的流程中定义目录 .
@Bean
public IntegrationFlow orderServiceFlow() {
return f -> f
.handleWithAdapter(h -> h.httpGateway("myUrl")
.httpMethod(HttpMethod.GET)
.expectedResponseType(List.class)
)
.split()
.channel(batchLaunchChannel());
}
@Bean
public DirectChannel batchLaunchChannel() {
return MessageChannels.direct("batchLaunchChannel").get();
}
@Bean
public IntegrationFlow batchLaunchFlow() {
return IntegrationFlows.from(batchLaunchChannel())
.enrichHeaders(h -> h
.headerExpression("oiCode", "payload")
)
.transform((GenericTransformer<String, JobLaunchRequest>) message -> {
JobParameters jobParameters = new JobParametersBuilder()
.addDate("exec_date", new Date())
.addString("oiCode", message)
.toJobParameters();
return new JobLaunchRequest(orderServiceJob, jobParameters);
})
.handle(new JobLaunchingMessageHandler(jobLauncher))
.enrichHeaders(h -> h
.headerExpression("jobExecution", "payload")
)
.handle((p, h) -> {
//Logic to retreive file...
return new File("");
})
.handle(Sftp.outboundGateway(sftpSessionFactory,
AbstractRemoteFileOutboundGateway.Command.PUT,
"payload")
)
.get();
}
我不知道如何告诉我的出站网关哪个目录取决于我的 Headers 中的内容 .
2 回答
Sftp.outboundGateway()
具有RemoteFileTemplate
的重载版本 . 所以,你需要实例化SftpRemoteFileTemplate
bean并配置它:这个可以像
FunctionExpression
:在我得到答案之前,我提出了这个解决方案,但我不确定它是一个好的解决方案 .
但是这引起了警告,因为
ExpresionUtils
java.lang.RuntimeException: No beanFactory
抛出异常