当前位置: 首页 > 知识库问答 >
问题:

spring Integration中如何解决ftp-gateway中的连接超时?

黄向明
2023-03-14

感谢大家的关注我在spring项目中使用了spring集成,我的项目是一个简单的文件处理,用ftp适配器从ftp获取文件int-FTP:Outbount-Gateway并运行批处理作业将ouput文件放到ftp上,我觉得当文件大小或从服务器获取的文件数太大时,会引发连接超时异常,我的代码如下:

   <int:inbound-channel-adapter expression="'/'" channel="inbound">
        <int:poller fixed-delay="${directory.server.polling.interval}"/>
    </int:inbound-channel-adapter>

    <int-ftp:outbound-gateway id="gatewayLS"
                                  session-factory="ftpSessionFactory"
                                  request-channel="inbound"
                                  command="ls"
                                  command-options="-R"
                                  expression="payload"
                                  reply-channel="inputFileSplitter"/>
    <bean id="splitter" class="com.ali.integration.handler.splitter.Splitter"/>
        <bean id="router" class="com.ali.integration.handler.router.Router"/>
        <int:splitter input-channel="inputFileSplitter" ref="splitter" method="inputFileSplitter" output-channel="FilesChannel"/>
        <int:channel id="FilesChannel"/>
        <int:router input-channel="FilesChannel" ref="router" method="routInputFile"/>
        <int-ftp:outbound-gateway id="gatewayGET"
                                  local-directory-expression="@fileUtil.backupRootPath + #remoteDirectory"
                                  session-factory="ftpSessionFactory"
                                  request-channel="readyToGetFilesChannel"
                                  reply-channel="readyFileToRemoveFromServerChannel"
                                  command="get"
                                  mode="REPLACE"
                                  command-options="-P"
                                  expression="payload.remoteDirectory + '/' + payload.filename"/>
2015-11-18 10:55:11.676 ERROR 6228 --- [ask-scheduler-5] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessagingException: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
    at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:120)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
    at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:166)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
    at org.springframework.integration.splitter.AbstractMessageSplitter.produceOutput(AbstractMessageSplitter.java:156)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:231)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:154)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:102)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
    at org.springframework.integration.endpoint.SourcePollingChannelAdapter.handleMessage(SourcePollingChannelAdapter.java:161)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:251)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:57)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:176)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:173)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:330)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:324)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(AbstractRemoteFileOutboundGateway.java:811)
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway$3.doInSession(AbstractRemoteFileOutboundGateway.java:534)
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway$3.doInSession(AbstractRemoteFileOutboundGateway.java:530)
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:410)
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.doGet(AbstractRemoteFileOutboundGateway.java:530)
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.handleRequestMessage(AbstractRemoteFileOutboundGateway.java:471)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    ... 67 more
Caused by: org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
    at org.apache.commons.net.io.Util.copyStream(Util.java:134)
    at org.apache.commons.net.ftp.FTPClient._retrieveFile(FTPClient.java:1873)
    at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1845)
    at org.springframework.integration.ftp.session.FtpSession.read(FtpSession.java:81)
    at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(AbstractRemoteFileOutboundGateway.java:798)
    ... 75 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at java.io.PushbackInputStream.read(PushbackInputStream.java:186)
    at org.apache.commons.net.io.FromNetASCIIInputStream.read(FromNetASCIIInputStream.java:166)
    at org.apache.commons.net.io.FromNetASCIIInputStream.read(FromNetASCIIInputStream.java:144)
    at org.apache.commons.net.io.Util.copyStream(Util.java:100)
    ... 79 more
.  
    10/18/2015 11:10:47 AM - test (127.0.0.1)> disconnected.
.  

共有1个答案

秦钟展
2023-03-14

不幸的是,这是网络或服务器的问题,框架无法改善这一点。

您可以尝试使用wireshark或类似工具来跟踪网络通信量。

 类似资料:
  • 我一直在使用ftp在android应用程序的服务器上上传图像,我正在使用以下代码连接ftp。它在Wi-fi中工作正常,但如果我切换到3G或2G连接,就会出现连接超时错误。那么,你能告诉我如何处理这种情况吗。我的客户在Veriozon也面临这个问题,Sprint,ATT网络提供商。它的iPhone版本在所有网络中都运行良好。 代码: 错误: JAVA网ConnectException:无法连接到主机

  • 我已经使用弹性Beanstalk在EC2实例中部署了springboot java jar。jar中的api在将用户添加到DB后会发送一个确认邮件。这个功能在localhost中运行良好,但是在aws实例上,我得到了gatway超时504。 这里是SMTP服务器的设置(它是不使用用户名、密码的smart服务器,并且我在服务器中添加了我的EC2公司的公共ip地址)Java SMTP设置: java.

  • 我正在迁移一个带有MySQL数据库的Java应用程序。现在连接会在某个时候超时,尽管使用相同参数的同一个连接在以前的几个事务中工作得很好。代码如下: 公共类DBConnection{ } 和我的日志: null 2016-06-21 15:53:31,436警告[com.arjuna.ats.arjuna](Transaction Reaper Worker 0)arjuna012108:Chec

  • 问题内容: 我有以下设置: 在路线中,我有: 路线:: get(’articles’,’ArticlesController @ index’); 控制器中的index方法很简单: 并在视图中: 我试图更换: 与 这样我才能真正显示最新的文章。我得到了错误: 调用堆栈为: …等等 我已经将控制器方法恢复到原来的状态,但是错误仍然存​​在。 您能告诉我如何解决这个问题吗? 问题答案: 超过30秒 的

  • 我的gradle构建脚本有问题: 我收到以下错误消息: 无法放入文件:425无法打开到端口55080的数据连接:连接超时 显然它对其他人有效。我在在像FileZilla这样的FTP客户机上运行良好,我不会超时。我也在本地FTP服务器上尝试过同样的方法,但是由于传输没有带宽限制,所以传输是即时的 如何防止超时?端口是否应该引起我的关注? 我之前也做了一些调试,我确保,和变量包含正确的信息。

  • 我正在用Node、Express和MongoDB构建一个REST api服务。我安装了MongoDB,它在我的PC上运行正常,本地主机:27017。我可以添加集合并阅读它们。在我的app.js文件中,我有这样的设置 我总是得到一个错误-mongoerror-cannot connect UNKNOWN我搜索了几个小时,没有找到任何解决方案。我该如何修复它,使它可以连接到MongoDB(工作正常).