3
votes

I want to use Mule for moving and processing files. I'm trying to move the same file to different folders with a flow and an "all router" but it fails.

This works:

    <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

But this don't!

    <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

I get this exception:

INFO 2013-10-03 20:22:19,072 [[testflow2].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\IN\test.txt.txt ERROR 2013-10-03 20:22:19,088 [[testflow2].testflow2Flow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:


Message : Cannot copy message with a stream payload. Payload type is "org.mule.transport.file.ReceiverFileInputStream". Message payload is of type: ReceiverFileInputStream

Code : MULE_ERROR--2

Exception stack is: 1. Cannot copy message with a stream payload. Payload type is "org.mule.transport.file.ReceiverFileInputStream". Message payload is of type: 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 Exception stack trace: org.mule.api.MessagingException: Cannot copy message with a stream payload. Payload type is "org.mule.transport.file.ReceiverFileInputStream". Message payload is of type: ReceiverFileInputStream at org.mule.routing.outbound.AbstractSequenceRouter.route(AbstractSequenceRouter.java:74) at org.mule.routing.outbound.AbstractOutboundRouter$1.process(AbstractOutboundRouter.java:105) at org.mule.routing.outbound.AbstractOutboundRouter$1.process(AbstractOutboundRouter.java:100) + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)


2
Please share your mule configCharu Khurana
Now I added the XML-config. I can't understand why adding the all router breaks the functionality.user1912657
and what is the exception you are getting?Charu Khurana
Thanks Learner, I had a similar issue, and resolved it by going to my File Reference in Global Elements and changed my streaming value to 'false'! Many Thanks.user3332366

2 Answers

4
votes

Adding this <object-to-byte-array-transformer/> transformer after your inbound endpoint will make it work.

<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>

I think why it failed is because mule was trying to read file as stream and write as stream; which was fine in your 1st case.

But in second flow because you want to write to more than one place, thats not possible with streaming. With addition of this transformer, now you have complete payload in memory and that can be written to more than one.

0
votes

You need to transform InputFileStream to a byt array. Set a global transformer(Go to File connector properties-->Transformers-->Add). Select File to Byte Array option. Connector config will look like this.

file:inbound-endpoint path="C:\File Input" responseTimeout="10000" transformer-refs="File_to_Byte_Array" doc:name="File"/>

InputFileStream you can not copy as it is to a variable.