2013-06-20 40 views
4

我一直在努力春季整合<int-ftp:outbound-gateway>,我能夠從遠程服務器下載文件與ftp-outbound-gateway,但有一個問題,我還解決不了,如果遠程目錄包含文件系統的工作,並將完成沒有任何問題,但如果沒有文件系統掛起沒有執行從這一點。我想繼續系統。遠程文件夾是否包含文件或沒有,春季整合ftp-outbound-gateway沒有遠程文件

這裏是我的FTP下載

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:int="http://www.springframework.org/schema/integration" 
     xmlns:p="http://www.springframework.org/schema/p" 
     xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp" 
     xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp 
     http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd 
     http://www.springframework.org/schema/integration 
     http://www.springframework.org/schema/integration/spring-integration.xsd 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 

    <context:property-placeholder location="classpath:host.properties"/> 

    <int:gateway id="gw" service-interface="com.util.ToFtpFlowGateway" 
       default-request-channel="inbound"/> 

    <bean id="downloadProcessBean" class="com.util.FTPDownloadInterceptor"> 
     <property name="fileType" value="txt"/> 
     <property name="sourceType" value="ftp"/> 
     <property name="destinationName" value="destinationName"/> 
     <property name="destinationQueName" value="destinationQueName"/> 
     <property name="sourceAddressDetails" value="sourceAddressDetails"/> 
     <property name="sourceName" value="sourceName"/> 
    </bean> 

    <bean id="ftpSessionFactory" 
      class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"> 
     <property name="host" value="${local.host}"/> 
     <property name="port" value="${local.availableServerPort}"/> 
     <property name="username" value="${local.userid}"/> 
     <property name="password" value="${local.user.password}"/> 
    </bean> 

    <int-ftp:outbound-gateway id="gatewayLS" cache-sessions="false" 
           session-factory="ftpSessionFactory" 
           request-channel="inbound" 
           command="ls" 
           command-options="" 
           expression="payload" 
           reply-channel="toSplitter" reply-timeout="10" /> 

    <int:channel id="toSplitter"> 
     <int:interceptors> 
      <int:wire-tap channel="logger"/> 
     </int:interceptors> 
    </int:channel> 

    <int:logging-channel-adapter id="logger" log-full-message="true" /> 

    <int:splitter id="splitter" input-channel="toSplitter" output-channel="toGet"/> 

    <int-ftp:outbound-gateway id="gatewayGET" cache-sessions="false" 
           local-directory="/home/udeshika/project/req/local/download" 
           session-factory="ftpSessionFactory" 
           request-channel="toGet" 
           reply-channel="toRemoveChannel" 
           command="get" 
           command-options="-P" 
           expression="payload.remoteDirectory + '/' + payload.filename" reply-timeout="10"/> 

    <int-ftp:outbound-gateway id="gatewayRM" 
           session-factory="ftpSessionFactory" cache-sessions="false" 
           expression="payload.remoteDirectory + '/'+ payload.filename" 
           request-channel="toRemoveChannel" 
           command="rm" 
           reply-channel="aggregateResultsChannel" 
           auto-create-local-directory="true" 
           reply-timeout="10" 

      /> 
    <!--<bean id="fileDownloadIntecepter" class="shipxpress.util.FTPDownloadInterceptor"/>--> 
    <int:channel id="toRemoveChannel"> 
     <int:interceptors> 
      <int:wire-tap channel="logger2"/> 
      <!--<int:ref bean="fileDownloadIntecepter" />--> 
     </int:interceptors> 
    </int:channel> 

    <bean class="org.springframework.integration.file.FileReadingMessageSource" 
      p:directory="${download.directory}"/> 

    <int:logging-channel-adapter id="logger2" log-full-message="true" /> 

    <int-ftp:outbound-gateway id="gatewayRM" 
           session-factory="ftpSessionFactory" cache-sessions="false" 
           expression="headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']" 
           request-channel="toRemoveChannel" 
           command="rm" 
           reply-channel="aggregateResultsChannel"/> 

    <int:aggregator input-channel="aggregateResultsChannel"/> 

</beans> 

誰能幫我清除此,

預先感謝您 Udeshika,

回答

3
配置

該流程的問題是LS返回一個空列表;當它碰到分離器時,它不會產生消息,流程停止。調用網關的線程正在永久(默認情況下)等待答覆。

向網關添加回復超時,如果未收到響應,它將返回空值。

<int:gateway id="gw" service-interface="org.springframework.integration.samples.ftp.ToFtpFlowGateway" 
    default-request-channel="inbound" default-reply-timeout="100" /> 

只要您使用直接渠道,沒有網關超時的危險時,有真正的工作要做,因爲定時器沒有啓動,直到線程返回到網關尋找這是任何答覆由下游流量產生。

+0

謝謝,它的工作 – 123Ex

+0

這是另一個問題,我該如何處理Null消息? – 123Ex

+0

我不知道你的意思是「處理Null消息」。 \t \t'List rmResults = toFtpFlow.lsGetAndRmFiles(「fooDir /」);''if(lmResults == null){logger.debug(「no files transferred」)}' –