带有sftp出站网关的远程目录 [英] Remote directory for sftp outbound gateway with DSL
问题描述
使用DSL的SFTP出站网关出现问题.我想使用出站网关发送文件,然后继续我的流程.问题是我有一个例外告诉我:
I'm having an issue with the SFTP outbound gateway using DSL. I want to use a outbound gateway to send a file, then continue my flow. The problem is that I have an exception telling me:
IllegalArgumentException: 'remoteDirectoryExpression' is required
我看到我可以使用RemoteFileTemplate来设置sftp会话工厂以及远程目录信息,但是我不需要的目录是在启动流之前由标头中放置的代码在我的流程中定义的批.
I saw that I can use a RemoteFileTemplate where I can set the sftp session factory plus the remote directory information, but the directory I wan't is defined in my flow by the code put in the header just before the launch of the batch.
@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();
}
我看不到如何告诉我的出站网关哪个将是目录,具体取决于标头中的内容.
I don't see how I can tell my outbound gateway which will be the directory depending what is in my header.
推荐答案
Sftp.outboundGateway()
的重载版本带有 RemoteFileTemplate
.因此,您需要实例化 SftpRemoteFileTemplate
bean并配置其:
The Sftp.outboundGateway()
has an overloaded version with the RemoteFileTemplate
. So, you need to instantiate SftpRemoteFileTemplate
bean and configure its:
/**
* Set the remote directory expression used to determine the remote directory to which
* files will be sent.
* @param remoteDirectoryExpression the remote directory expression.
*/
public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) {
这可以像 FunctionExpression
:
setRemoteDirectoryExpression(m -> m.getHeaders().get("remoteDireHeader"))
这篇关于带有sftp出站网关的远程目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!