camel ftp路由和文件类型转换器

时间:2013-08-02 17:46:17

标签: apache-camel

我在处理ftp文件的骆驼路线中正在努力进行类型转换。我的路线看起来像这样(在Spring DSL中):

<route id="processIncomingFtpFile" errorHandlerRef="parkingCitErrHandler">
      <from uri="{{ftp.parkingcit.input.path}}"/>
      <bean ref="ftpZipFileHandler"/>
      <unmarshal ref="bindyCsvFormat"/>
      <bean ref="parkingTicketsHandler"/>
      <split>
          <simple>${body}</simple>
          <marshal ref="jaxbFormatter"/>
          <convertBodyTo type="java.io.File"/>
      <to uri="{{ftp.parkingcit.output.path}}"/>
      </split>
   </route>

我的处理程序签名如下:

public File handleIncomingFile(File incomingfile)...

但是,这会产生以下类型转换问题:

org.apache.camel.InvalidPayloadException: No body available of type: java.io.File but has value: RemoteFile[test.zip] of type: org.apache.camel.component.file.remote.RemoteFile on: test.zip. Caused by: No type converter available to convert from type: org.apache.camel.component.file.remote.RemoteFile to the required type: java.io.File with value RemoteFile[test.zip]. Exchange[test.zip]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.file.remote.RemoteFile to the required type: java.io.File with value RemoteFile[test.zip]]

我的问题是:我是否应该能够在内存中处理我的ftp文件,而没有明确告诉camel将其写入磁盘,类型转换器为我在幕后自动完成工作?或者我正在努力做到毫无意义,因为我的处理程序想要一个java.io.File作为其输入参数,即我必须将数据写入磁盘才能使其工作?

2 个答案:

答案 0 :(得分:0)

嗯,我建议使用本地文件(我总是使用ftp端点)。 ftp端点中有一个名为localWorkDirectory的选项,允许您在进一步处理之前定义下载文件的目录(通常为/ tmp)。我们的想法是避免因网络问题或在处理过程中断开连接而导致的任何错误 你可以尝试吗这很容易(只需在uri中添加&amp; localWorkDirectory = mydir)它会为你找到该文件 见https://camel.apache.org/ftp2.html。 只需确保您已在目录上正确写作,当然

答案 1 :(得分:0)

java.io.File用于文件系统,而不用于FTP文件。

您需要将bean方法签名中的类型更改为Camel的GenericFile或来自Camel使用的commons-net FTP客户端库的实际类型。