用骡子移动文件

时间:2013-10-03 15:45:51

标签: file copy mule

我想使用Mule来移动和处理文件。我正在尝试使用流和“所有路由器”将相同的文件移动到不同的文件夹,但它失败了。

这有效:

    <flow name="testflow2Flow1" doc:name="testflow2Flow1">
    <file:inbound-endpoint path="C:\IN" fileAge="10000" responseTimeout="10000" doc:name="File"/>
    <set-variable variableName="tempfilename" value="#[header:originalFilename]" doc:name="Variable"/>
    <file:outbound-endpoint path="C:\OUT" responseTimeout="10000" doc:name="File"/>
</flow>

enter image description here

但这不是!

    <flow name="testflow2Flow1" doc:name="testflow2Flow1">
    <file:inbound-endpoint path="C:\IN" fileAge="10000" responseTimeout="10000" doc:name="File"/>
    <set-variable variableName="tempfilename" value="#[header:originalFilename]" doc:name="Variable"/>
    <all doc:name="All">
        <processor-chain>
            <file:outbound-endpoint path="C:\OUT" responseTimeout="10000" doc:name="File"/>
        </processor-chain>
    </all>
</flow>

enter image description here

我得到了这个例外:

INFO 2013-10-03 20:22:19,072 [[testflow2] .connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver:在文件中获取的锁:C:\ IN \ test.txt.txt ERROR 2013-10-03 20:22:19,088 [[testflow2] .testflow2Flow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:


消息:无法使用流有效内容复制邮件。 Payload类型是“org.mule.transport.file.ReceiverFileInputStream”。消息有效内容的类型为:ReceiverFileInputStream

代码:MULE_ERROR - 2

异常堆栈是: 1.无法使用流有效负载复制邮件。 Payload类型是“org.mule.transport.file.ReceiverFileInputStream”。消息有效内容的类型为:ReceiverFileInputStream(org.mule.api.MessagingException)

org.mule.routing.outbound.AbstractSequenceRouter:74(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html

Root异常堆栈跟踪: org.mule.api.MessagingException:无法使用流有效内容复制邮件。 Payload类型是“org.mule.transport.file.ReceiverFileInputStream”。消息有效内容的类型为:ReceiverFileInputStream     at org.mule.routing.outbound.AbstractSequenceRouter.route(AbstractSequenceRouter.java:74)     在org.mule.routing.outbound.AbstractOutboundRouter $ 1.process(AbstractOutboundRouter.java:105)     at org.mule.routing.outbound.AbstractOutboundRouter $ 1.process(AbstractOutboundRouter.java:100)     + 3个以上(设置调试级别日志记录或'-Dmule.verbose.exceptions = true'用于所有内容)


2 个答案:

答案 0 :(得分:4)

在入站端点之后添加此<object-to-byte-array-transformer/>转换器将使其正常工作。

<flow name="testflow2Flow1" doc:name="testflow2Flow1">
    <file:inbound-endpoint path="C:\IN" fileAge="10000" responseTimeout="10000" doc:name="File"/>
    <object-to-byte-array-transformer/>
    <set-variable variableName="tempfilename" value="#[header:originalFilename]" doc:name="Variable"/>
    <all doc:name="All">            
        <file:outbound-endpoint path="C:\OUT" responseTimeout="10000" doc:name="File"/>
        <file:outbound-endpoint path="C:\OUT1" responseTimeout="10000" doc:name="File"/>        
    </all>
</flow>

我认为它失败的原因是因为mule试图将文件作为流读取并写为流;你的第一种情况很好。

但是在第二个流程中,因为你想要写入多个地方,这是不可能的流媒体。通过添加此变换器,现在您可以在内存中拥有完整的有效负载,并且可以写入多个。

答案 1 :(得分:0)

您需要将InputFileStream转换为byt数组。 设置全局转换器(转到文件连接器属性 - &gt;转换器 - &gt;添加)。 选择“文件到字节数组”选项。连接器配置将如下所示。

file:inbound-endpoint path =“C:\ File Input”responseTimeout =“10000”transformer-refs =“File_to_Byte_Array”doc:name =“File”/&gt;

您无法将InputFileStream复制到变量。