Search code examples
mulemule-el

Mule ESB - How to load a config xml (custom) file in Mule flow


I am trying to find a way to load a custom xml file to a mule flow and may-be get it as a variable. For eg;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
       <LastName>Smith</LastName>
       <Sales>16753</Sales>
       <Country>UK</Country>
       <Quarter>Qtr 3</Quarter>
    </record>
    <record>
       <LastName>Johnson</LastName>
       <Sales>14808</Sales>
       <Country>USA</Country>
       <Quarter>Qtr 4</Quarter>
    </record>
</data-set>

Please help.


Solution

  • I followed the answer by @Ryan Hoegg and after a few modifications my answer is as below:

    Global Element:

    <spring:beans>
        <spring:bean id="LoadFile" name="Bean" class="java.lang.String">
            <spring:constructor-arg>
                <spring:bean id="Test" name="org.springframework.util.FileCopyUtils" class="org.springframework.util.FileCopyUtils" factory-method="copyToByteArray">
                    <spring:constructor-arg type="java.io.InputStream" value="classpath:MSG_IDENTIFIER.xml"/>
                </spring:bean>
            </spring:constructor-arg>
        </spring:bean>
    
    </spring:beans>
    

    To Retrieve:

    <set-variable variableName="Contents" value="#[app.registry['LoadFile']]" doc:name="Variable"/>
    

    P.S - I placed the file under src/main/resources