2013-08-02 38 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

這不正是我一直在試圖做的本身,但它會完成這項工作,我想。謝謝。 –