0

我正在努力在我的骆驼路线中进行类型转换以处理 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 文件,而无需明确告诉骆驼将其写入磁盘,而类型转换器会在幕后为我自动完成工作?或者我想做的事情是没有意义的,因为我的处理程序想要一个 java.io.File 作为它的输入参数,即我必须将数据写入磁盘才能工作?

4

2 回答 2

0

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

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

于 2013-08-07T07:40:22.757 回答
0

嗯,我建议使用本地文件(我总是使用 ftp 端点这样做)。ftp 端点中有一个名为 localWorkDirectory 的选项,可让您定义一个目录以在进一步处理之前下载文件(通常为 /tmp )。这个想法是为了避免由于网络问题或在处理过程中断开连接而导致的任何错误你可以试试吗它很简单(只需在 uri 中添加 &localWorkDirectory =mydir ),它会为你看到https://camel.apache 的文件。组织/ftp2.html。当然,只要确保你在目录上写权就行了

于 2013-08-02T18:03:51.293 回答