【发布时间】:2016-10-14 19:16:26
【问题描述】:
我们正在使用 Spring 4.3.3.Release 和 Spring Integration 4.3.4.Release,这两个版本都应该是本文发布时的最新版本。我们正在应用程序中创建一个 File 对象,我们不需要将该文件写入磁盘。
我们想要获取 File 对象并使用 Spring Integration,将此文件移动到远程 SFTP 目录。
我对 Spring Integration 有一定了解,并且一直在查看一些示例,但我不确定现在哪个示例最有意义。
如果我可以被推荐到正确的地方,那么我将举一些例子,看看我如何将它们应用到我的代码中。
谢谢!
更新 1:
这是我的新应用程序上下文 XML 文件:
<int-sftp:outbound-channel-adapter id="sftpOutbondAdapter"
channel="ftpOutboundChannel"
remote-directory="${sftp.remote.outbound.dir}"
session-factory="sftpSessionFactory" >
<int-sftp:request-handler-advice-chain>
<int:retry-advice />
</int-sftp:request-handler-advice-chain>
</int-sftp:outbound-channel-adapter>
<int:channel id="ftpOutboundChannel"/>
“sftp.remote.outbound.dir”指向 sftp 服务器上的真实目录: /home/test/tom/出站
我的班级看起来像:
@Transactional
@Service("reportService")
public class ReportServiceImpl implements ReportService
{
@Autowired
private MessageChannel ftpOutboundChannel;
@Scheduled(cron = "${sftp.timerTaskCron}", zone = "UTC")
public void runReports() throws Exception
{
File file = new File(path to some local filename);
// yes, this file really exists
Message<File> message = MessageBuilder.withPayload(file).build();
ftpOutboundChannel.send(message);
// I presume this file is output to that local directory
}
}
这似乎可以编译,但我只是想确保正确配置移动它的机制。
我有一个非常相似的单元测试。它是事务性的,也许它不应该是?
public class SftpOutboundReceiveSample extends BaseServiceTests
{
@Autowired
private MessageChannel ftpOutboundChannel;
private String _filename = "/src/test/resources/attachment/DemoTrialFormv6_1.pdf";
@Test
public void runDemo()
{
File file = new File(_filename);
assertNotNull(file);
Message<File> message = MessageBuilder.withPayload(file).build();
ftpOutboundChannel.send(message);
}
}
这是事务性的事实是否意味着一旦我们完成测试,它将文件滚出这个目录?或者,这不是一个很好的测试吗? 我正在尝试确保文件到达正确的位置。
【问题讨论】:
标签: java spring spring-integration sftp