2013-08-02 35 views
0

我与类型转换挣扎在我的骆驼航线处理FTP文件。我的路线是这样的(在Spring DSL):骆驼FTP路径和文件类型转换器

<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中作为输入参数,即我必须将数据写入磁盘这个工作?

回答

0

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

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

+0

现在看来很明显,你指出了。谢谢。 –

0

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

+0

这不正是我一直在试图做的本身,但它会完成这项工作,我想。谢谢。 –