如果处理失败,请删除源目录中的文件

时间:2013-08-24 17:21:23

标签: mule

我的要求是在入站端点处理文件

用例1-处理文件失败

如果由于某些异常(例如验证错误)导致文件处理失败,请将文件移动到与源不同的单独目录中。删除源目录中的原始文件

用例2 - 成功处理

如果文件处理成功完成,请将文件保留在源目录中。

我尝试了以下操作,文件被移动到失败的目录,但源文件未按用例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>

我是否需要覆盖任何现有的mule功能才能实现此行为。失败时的源文件夹不应包含该文件。目标文件夹应该具有标记为“失败”状态的文件。

1 个答案:

答案 0 :(得分:3)

对于用例1,在您的异常策略中,使用MEL表达式组件中的originalFilename中的值将文件移动到您想要的任何位置。

您可以使用org.mule.util.FileUtils.moveFileWithCopyFallback()

PS。 #[header:originalFilename]是旧样式表达式语法,在Mule 3.3及更高版本上使用MEL #[message.inboundProperties.originalFilename]

相关问题