【发布时间】: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