Pram
Pram

Reputation: 2261

Mule xml file rename based on content

We have a working implementation of Mule (v3.1.2) connecting two JMS based endpoints. XML messages are being passed without any problem between the two.

We now have to add an additional file endpoint as a parallel destination for one of the queues. Adding the file endpoint works and the messages are appearing as expected on the file system.

Is it possible to set the file name based on the content of the XML payload? Currently the files are being generated with the name (for example) b8ede5db-9b7a-11e2-9d10-cd8a155d0975.dat which is not particularly meaningful.

So for a file with the content such as below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Acknowledgement UploadDate="Tue Apr 02 05:05:01 EDT 2013" Uploaded="0" Rejected="1" Received="1">
    <Trades Uploaded="0" Rejected="1" Received="1">
        <Trade>
            <ExtRef>1</ExtRef>
            <TradeId>0</TradeId>
            <Status>Rejected</Status>
            <Action>NEW</Action>
            <Error>
                <Message>ERROR-TYPE: 'InvalidData'; ITEM: 'CP'; MESSAGE: 'Invalid CP'; VALUE: 'BLAH BLAH'</Message>
            </Error>            
        </Trade>
    </Trades>
</Acknowledgement>

Would it be possible to instead have a filename based on the "ExtRef" element?

Upvotes: 0

Views: 280

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

You can use the outputPattern attribute on the file:outbound-endpoint to define the pattern for naming files. You can then use an xpath expression to extract a value from the XML to name the file.

For example, based on your XML, the following configuration would create a file named 1.dat on the filesystem:

This xpath expression syntax should work with 3.1.2.

<file:outbound-endpoint path="c:/temp" outputPattern="#[string:#[xpath:/Acknowledgement/Trades/Trade/ExtRef].dat]" responseTimeout="10000" />

Upvotes: 2

Related Questions