【问题标题】:sftp outbound-gateway with get command throws exception when file with the same name already exists当同名文件已经存在时,带有 get 命令的 sftp outbound-gateway 会引发异常
【发布时间】:2015-04-23 15:26:41
【问题描述】:

我正在尝试使用 sftp 出站网关从远程 sftp 服务器下载文件。这是网关配置:

<int-sftp:outbound-gateway id="downloadGateway"                 
                command="get" 
                command-options="-P"
                expression="payload.remoteDirectory + payload.filename"
                session-factory="cachingSessionFactory"
                local-directory="downloads"
                auto-create-directory="true"
                use-temporary-file-name="true"
                mode="REPLACE"                  
                local-filename-generator-expression="#remoteFileName + '.' + @currentDate.getDateStr()"
                />

如果已经存在同名的本地文件,我想用新下载的文件替换它。这就是我将模式设置为“REPLACE”的原因。相反,我得到了一个例外:

Caused by: org.springframework.messaging.MessagingException: Local file downloads\myFile.xml.2015-04-14 already exists
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(AbstractRemoteFileOutboundGateway.java:700)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway$2.doInSession(AbstractRemoteFileOutboundGateway.java:436)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway$2.doInSession(AbstractRemoteFileOutboundGateway.java:432)
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:334)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.doGet(AbstractRemoteFileOutboundGateway.java:432)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.handleRequestMessage(AbstractRemoteFileOutboundGateway.java:394)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.handler.MessageHandlerChain$1.send(MessageHandlerChain.java:123)
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:95)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:248)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:171)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:119)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.handler.MessageHandlerChain$1.send(MessageHandlerChain.java:123)
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:95)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:248)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:171)
at org.springframework.integration.splitter.AbstractMessageSplitter.produceOutput(AbstractMessageSplitter.java:129)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:119)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.handler.MessageHandlerChain$1.send(MessageHandlerChain.java:123)
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:95)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:248)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:171)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:119)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:105)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.handler.MessageHandlerChain.handleMessageInternal(MessageHandlerChain.java:104)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
... 7 more

当网关与 put 命令一起使用时,我是否正确假设模式属性适用于远程文件?我有什么方法可以通过 sftp 出站网关实现我正在寻找的行为?

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    有趣;你是这周的第二个请求。

    目前,除了自己删除文件(或将文件提取到临时目录,然后使用文件出站适配器移动它们 - 确实提供替换模式)之外,没有其他解决方法.

    前几天我开了JIRA Issue来添加这个功能。

    实际上,网关上存在mode 属性是一个错误,目前已被忽略。

    【讨论】:

    • 感谢您的快速回复。添加 让我得到我想要的东西!
    【解决方案2】:

    它是一个旧线程,但如果您正在寻找 mode 的有效值,它们在这里(参考:org.springframework.integration.file.support.FileExistsMode):

       /**
         * Append data to any pre-existing files; close after each append.
         */
        APPEND,
    
        /**
         * Append data to any pre-existing files; do not flush/close after
         * appending.
         * @since 4.3
         */
        APPEND_NO_FLUSH,
    
        /**
         * Raise an exception in case the file to be written already exists.
         */
        FAIL,
    
        /**
         * If the file already exists, do nothing.
         */
        IGNORE,
    
        /**
         * If the file already exists, replace it.
         */
        REPLACE;
    

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 2011-09-10
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 2023-04-02
      相关资源
      最近更新 更多