简体   繁体   中英

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.

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

PS - I placed the file under src/main/resources

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

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']]" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM