java - 用于 Mput 操作的 Spring-Integration SFTP 网关
问题描述
我正在尝试使用 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
知道如何解决此问题并上传多个文件吗?请分享任何完整的例子。谢谢
解决方案
推荐阅读
- angular - 登录 - Grafana 与 Angular+SpringBoot
- html - 使用 xmlstarlet 编辑 HTML 中特定节点的 XPath 语法
- javascript - 我可以从不可见的组件中获取事件吗?(Vue.js)
- amazon-web-services - 如何获取和显示一组网络图像?
- angular - 从 Angular v7 升级到 v8 后,显示“my-custom-element”的 VS 代码不是已知元素
- swiftui - 是否可以指示 swiftUI ObservableObjects 在数据更改事件时修改自己?
- javascript - 用 Javascript 重写 Fetch API
- mysql - 具有多个 group_concats 的“on 子句”中的未知列
- typescript - 参数允许包装泛型函数,但推断不允许
- python - 在训练决策树模型时遇到错误