2014-02-20 17 views

回答

3

我前一陣子做過。在文件使用者中,文件實際上並沒有被加載,直到你觸摸到文本。文件路徑與其他一些變量一起在頭文件中傳遞。在轉換它之前,主體將包含一個org.apache.camel.component.file.GenericFile對象。每個消息只有一個文件不是文件列表。

假設這是您正在使用,如果你有以下的路徑,工作文本文件:

<from uri="file:d:/Inbox?delay=5000&amp;move=.donebackup/placement/${date:now:yyyyMMdd}/${file:onlyname.noext}_DONE_${date:now:yyyyMMddHHmmss}.${file:name.ext}&amp;readLock=changed&amp;include=.*.dl&amp;maxMessagesPerPoll=0&amp;sortBy=${file:length}"/> 
<convertBodyTo type="java.lang.String"/> 
<log message="Converted File To String:${date:now:yyyy-MM-dd HH:mm:ss} handing data to File To DB route."/> 
<to uri="seda:fileToDB"/> 

你的身體就包含字符串。這是由於我在路由上發送它之前將身體從org.apache.camel.component.file.GenericFile轉換爲字符串。

但是,如果你有:

<from uri="file:d:/Inbox?delay=5000&amp;move=.donebackup/placement/${date:now:yyyyMMdd}/${file:onlyname.noext}_DONE_${date:now:yyyyMMddHHmmss}.${file:name.ext}&amp;readLock=changed&amp;include=.*.dl&amp;maxMessagesPerPoll=0&amp;sortBy=${file:length}"/> 
<to uri="seda:fileToDB"/> 

,身體會不會因此加載郵件正文將在seda:fileToDB路線上包含org.apache.camel.component.file.GenericFile並且只包含頭文件路徑。就像我之前提到的那樣,文件不會被加載直到你使用body。

如果你有一個二進制文件的工作,你會加載身體是這樣的:那麼

byte[] filedata = exchange.getIn().getBody(byte[].class); 

,身體會包含byte[]

如果你這樣做File file = msg.getIn().getBody(File.class);身體將包含一個文件對象。

所以這取決於你在時間之前對身體所做的事情。如果您將其轉換爲一些適當的數據類型,它可能會包含類型,否則這將是org.apache.camel.component.file.GenericFile

link on camel包含了一些有趣的例子。