1

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.

jvas
  • 440
  • 1
  • 7
  • 19

3 Answers3

2

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

jvas
  • 440
  • 1
  • 7
  • 19
1

You could import the custom configuration file in following way :-

<spring:beans>
    <spring:import resource="domain-A-config.xml" />
    <spring:import resource="domain-B-config.xml" />
    <spring:import resource="admin-config.xml" />
  </spring:beans>

Please find the reference below :- http://www.mulesoft.org/documentation/display/current/Modularizing+Your+Configuration+Files+for+Team+Development

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
1

One way to get the contents of a file into a flow variable is to create a spring bean with the contents of the file as described in this Stack Overflow question. Then, you can refer to it using MEL:

<set-variable variableName="niftyData" value="#[app.registry['myBeanName']]" />
Community
  • 1
  • 1
Ryan Hoegg
  • 2,415
  • 2
  • 14
  • 15
  • Thanks. This worked fine. Just to be clear, I am adding my flow to the answer as well. – jvas Nov 11 '14 at 09:42