2013-08-24 68 views
0

我的要求是要處理一個文件中的入站端點源目錄中刪除文件,如果處理失敗

使用案例1在故障處理文件

如果該文件未能處理由於一些例外就像驗證錯誤一樣,將文件移動到與源不同的單獨目錄。刪除原始文件中的源目錄

使用案例2 -Successful處理

如果文件處理成功完成,讓文件保留在源目錄。

我嘗試以下,將文件移動到失敗的目錄,但在源文件不會被刪除,如用例需要1

<flow name="InValidFlow1" doc:name="InValidFlow1"> 
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="c:\filelanding\in2" pollingFrequency="100" connector-ref="input_2" moveToDirectory="c:\filelanding\in2" moveToPattern="#[header:originalFilename]-#[function:dateStamp]-Processed"> 
<file:filename-regex-filter pattern="(?!.*Processed|.*Failed)(.*)" caseSensitive="false"/> 
</file:inbound-endpoint> 
<test:component waitTime="20000"></test:component> 
<custom-transformer class="com.XXX.XXX.service.ExceptionService" doc:name="Java"/> 
<file:outbound-endpoint responseTimeout="10000" doc:name="File" path="c:\filelanding\out2" connector-ref="output_2"/> 
<exception-strategy ref="fot_exception_strategy_single" doc:name="Reference Exception Strategy"/> 
</flow> 
<file:connector name="error_output_1" outputPattern="#[header:originalFilename]" doc:name="File"/> 
<choice-exception-strategy name="fot_exception_strategy_single"> 
<catch-exception-strategy when="#[exception.causedBy(java.lang.RuntimeException)]" doc:name="Catch Exception Strategy"> 
<!-- Mark the status as failed--> 
<file:outbound-endpoint connector-ref="error_output_1" responseTimeout="10000" doc:name="File" path="c:\filelanding\backup2" outputPattern="#[header:originalFilename]-#[function:dateStamp]-Failed" > 
</file:outbound-endpoint> 
</catch-exception-strategy> 
</choice-exception-strategy> 

我需要重寫任何現有的騾子功能來實現這一行爲。失敗時的源文件夾不應包含該文件。目標文件夾應具有標記爲「失敗」狀態的文件。

+0

我沒有看到用例2是如何工作的:如果文件保持在同一個目錄中,Mule會反覆輪詢它。 –

+0

感謝大衛,目前處理後我將文件標記爲已處理並放置在同一目錄中。在文件入站端點中,我使用filename-regex篩選器來跳過處理的文件。我的問題是在消息流中出現異常的情況下,我需要將該文件從源文件移動到其他目錄,並刪除源目錄中的原始文件(用例1)。 – user2714010

回答

3

對於用例1,在您的例外策略中,使用MEL表達式組件中的originalFilename中的值將文件移動到任意位置。

對於這個問題,您可以使用org.mule.util.FileUtils.moveFileWithCopyFallback()

PS。 #[header:originalFilename]是舊式表達式語法,在Mule 3.3及以上使用MEL #[message.inboundProperties.originalFilename]

+0

我在異常策略中定義的java組件中使用了FileUtils.moveFileWithCopyFallback(sourceFile,destinationFile),但源文件未被刪除 – user2714010

+0

所以在異常策略中,我刪除了文件出站端點並添加了一個java組件<組件class =「com.XXX.XXX.service.RemoveUnprocessedFiles」doc:name =「Java」/> – user2714010

+0

對此有任何幫助,自此以後一直困在這個問題 – user2714010

相關問題