【问题标题】:spring ftp integration using 'local-filename-generator-expression '使用'local-filename-generator-expression'的spring ftp集成
【发布时间】:2015-12-01 12:01:18
【问题描述】:

我想从 ftp 读取文件并将它的本地存储为与我的根目录下的远程文件相同的路径(我需要它来处理文件)。 远程文件路径是动态的,并根据过滤器而变化。 (文件在service-activator调用方法pull时处理)

<int:channel id="ftpChannel">
      <int:queue/>
</int:channel>

    <int-ftp:inbound-channel-adapter id="ftpInbound"
        channel="ftpChannel" session-factory="ftpSessionFactory"
        auto-create-local-directory="true" delete-remote-files="true"
        remote-directory="/"
        remote-file-separator="/" temporary-file-suffix=".writing"
        local-filename-generator-expression ="/+=#this"
        local-directory="${mfg.root.dir}">
        <int:poller fixed-rate="50000" />
    </int-ftp:inbound-channel-adapter>

     <bean id= "directoryFilter" class="il.co.mit.mfg.filter.FilterClass" scope="prototype" >
        <property name="channelType" value="****"/>
        <property name="rootFolder" value="${mfg.root.dir}"/>
    </bean>

    <int:channel id="pubSubChannel">
       <int:queue/>
   </int:channel>
    <int:channel id="output">
      <int:queue/>
     </int:channel>

    <file:inbound-channel-adapter id="inboundfolder"
        channel="pubSubChannel"
        directory="${mfg.root.dir}"
        prevent-duplicates="false">
    </file:inbound-channel-adapter>

    <int:poller default="true" fixed-delay="5000">
          <int:transactional transaction-manager="transactionManager"  />
    </int:poller>

    <int:service-activator id="inputFileServiceActivator"
        input-channel="pubSubChannel" method="pull" ref="typeAdapter" output-channel="output">
</int:service-activator>

    <bean id="ftpSessionFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="*****" />
        <property name="port" value="21" />
        <property name="username" value="******" />
        <property name="password" value="******" />
        <property name="clientMode" value="0" />
        <property name="fileType" value="2" />
        <property name="bufferSize" value="100000" />
    </bean>

我一直在尝试使用local-filename-generator-expression,但我不确定如何编写 SpEL 表达式。 我是新手,请帮忙

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    不清楚你的意思

    远程文件路径是动态的,根据过滤器变化。

    远程路径是文字;过滤器不能改变它。

    remote-directory="/"
    

    如果您只是想使用远程文件名作为本地文件名 - 这将是默认值 - 只需省略 local-filename-generator-expression

    如果你真的想要动态路径而不是文件名,最好使用ftp outbound gateway;在那里你可以完全控制远程和本地路径。

    【讨论】:

    • 它可以工作,它会创建文件夹但它没有放置文件,我得到异常
    • 原因:java.lang.ClassCastException: com.jcraft.jsch.ChannelSftp$LsEntry 无法转换为 java.io.File
    • 您需要显示完整的堆栈跟踪,但这意味着您使用的是来自spring-integration-fileFileListFilter,而不是来自spring-integration-sftpSftp...Filter
    • 对 sftp 不适用,它与 docs.spring 中的过滤器类相同,但通用的是 LsEntry 类
    • 这与类转换异常无关;您需要准确显示您正在使用的内容和堆栈跟踪。
    猜你喜欢
    • 1970-01-01
    • 2011-05-23
    • 2020-04-21
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    相关资源
    最近更新 更多