【问题标题】:Spring-Integeration SFTP Gateway for Mput Operation用于 Mput 操作的 Spring-Integration SFTP 网关
【发布时间】:2018-10-23 20:31:25
【问题描述】:

我正在尝试使用 SFTP 出站网关上传多个文件。我的 Java 代码是这样的:

final DirectChannel reqWriteChannel = (DirectChannel) context.getBean("toWriteChannel");
final PollableChannel repWriteChannel = (PollableChannel) context.getBean("fromWriteChannel");

reqWriteChannel.send(MessageBuilder.withPayload(listOfFiles).build());
Message<?> input = repReadChannel.receive(1000);

System.out.println(input);
System.out.println(input.getPayload().toString());

这是 XML 配置:

<int:channel id="fromWriteChannel"><int:queue /></int:channel>
<int:channel id="toWriteChannel" />

<int-sftp:outbound-gateway
      id="sftpWriteOnly"
      session-factory="sftpSessionFactory"
      request-channel="toWriteChannel"
      reply-channel="fromWriteChannel"
      command="mput"
      expression="payload"
      remote-directory="/test/mytest/"
      remote-file-separator="X"
      auto-create-directory="true"
      order="1" mput-regex=".*">
</int-sftp:outbound-gateway>

<int:poller default="true" fixed-delay="500"/>

当我传递单个文件时,上面的代码有效,但是当我传递文件列表时,我得到以下异常:

Caused by: java.lang.IllegalArgumentException: Only File or String payloads allowed for 'mput'
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.doMput(AbstractRemoteFileOutboundGateway.java:816)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.handleRequestMessage(AbstractRemoteFileOutboundGateway.java:598)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158)
... 7 more

知道如何解决这个问题并上传多个文件吗?请分享任何完整的例子。谢谢

【问题讨论】:

    标签: java spring spring-integration spring-integration-dsl spring-integration-sftp


    【解决方案1】:

    MPUT 发送目录中的所有文件;不是File 的列表。

    来自the documentation...

    mput 向服务器发送多个文件并支持以下选项:

    -R - Recursive - 发送目录和子目录中的所有文件(可能被过滤)

    消息负载必须是表示本地目录的 java.io.File。

    ...

    (我强调,它也可以是一个引用目录的字符串)。

    如果您不想发送所有文件,可以添加过滤器。

    随时打开“改进”JIRA Issue,我们可以添加对File 集合的支持。

    【讨论】:

    • 我们可以添加对 File 集合的支持 - 随时打开 JIRA 问题。
    • 由于v5.1,还支持FileString的集合作为消息负载。
    猜你喜欢
    • 1970-01-01
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    相关资源
    最近更新 更多