spring-integration - 使用 DSL 的 sftp 出站网关的远程目录

标签 spring-integration sftp dsl

我在使用 DSL 的 SFTP 出站网关时遇到问题。 我想使用出站网关发送文件,然后继续我的流程。 问题是我有一个异常告诉我:

IllegalArgumentException: 'remoteDirectoryExpression' is required

我看到我可以使用 RemoteFileTemplate,在其中我可以设置 sftp session 工厂以及远程目录信息,但是我不需要的目录是由在启动之前放入 header 中的代码在我的流程中定义的。批。

    @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();
}

我不知道如何告诉我的出站网关哪个目录将取决于我的 header 中的内容。

最佳答案

Sftp.outboundGateway() 具有带有 RemoteFileTemplate 的重载版本。因此,您需要实例化 SftpRemoteFileTemplate bean 并配置它:

/**
 * 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"))

关于spring-integration - 使用 DSL 的 sftp 出站网关的远程目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341438/

相关文章:

java - 如何在Spring Integration中配置多个网关?

python - 如何通过 SFTP 连接下载文件的一部分?

groovy - 在 Groovy 中实现 DSL 白名单

scala - 在Scala中嵌入XML(和其他语言?)

java - 任何能够处理数据集的基于 DSL 的框架?

spring-batch - 使用 Java DSL 在远程 S(ftp) 中移动已处理的文件

java - Spring 集成: process files line by line persisting read state

java - Spring cvc复合型.2.4.a : Invalid content was found starting with element 'channel'

java - Apache Mina SSHD 1.0.0 设置用户目录和映射

file - SFTP 使用 bash 脚本发送文件