Sometimes we need to read file content in the mediation flow of WSO2 ESB.
Let's say we have a file named EndPoints.xml with the below content in the registry path of /_system/config/repository/demo as follows.
File Content :
<EndPointsList xmlns:ns1="http://endpoints"> <EP>www.google.com</EP> <EP>www.yahoo.com</EP> </EndPointsList>
Registry Path:
Sample Proxy:
In this proxy service, the file named EndPoints.xml is read and content is printed using log mediator.
Log Output:
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="TestFileReadProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="EndPointList" expression="get-property('registry','conf:/repository/demo/EndPoints.xml')" scope="default" type="OM"/> <foreach xmlns:nm="http://endpoints" id="foreach_1" expression="$ctx:EndPointList//EP"> <sequence> <log level="custom"> <property name="EP:" expression="//EP"/> </log> </sequence> </foreach> <respond/> </inSequence> </target> <description/> </proxy>
Log Output:
TID: [-1234] [] [2016-12-02 11:58:13,964] INFO {org.apache.synapse.mediators.builtin.LogMediator} - EP: = www.google.com {org.apache.synapse.mediators.builtin.LogMediator} TID: [-1234] [] [2016-12-02 11:58:13,966] INFO {org.apache.synapse.mediators.builtin.LogMediator} - EP: = www.yahoo.com {org.apache.synapse.mediators.builtin.LogMediator}