Search code examples
javamuleesb

foreach in xml-node return null in mule esb


I am using below flow.

 <flow name="mytestFlow1" doc:name="mytestFlow1">
        <http:inbound-endpoint mimeType="text/xml" path="xmltest" exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <foreach collection="#[xpath://file//data//deliveryOrder]" doc:name="For Each" >
            <echo-component />
            <logger level="INFO" message="#[payload]" />
            <logger level="INFO" message="#[rootMessage]" />
        </foreach>
    </flow>

and posting below xml.

<file>
  <data>
    <deliveryOrder>
      <deliveryMethod>TRUCK1</deliveryMethod>
    </deliveryOrder>
    <deliveryOrder>
      <deliveryMethod>TRUCK21</deliveryMethod>
    </deliveryOrder>
    <deliveryOrder>
      <deliveryMethod>TRUCK2</deliveryMethod>
    </deliveryOrder>
  </data>
</file>

when I am running my flow echo component is print correct but logger print null. I also used custom transformer it also print null.

Any suggestion is appreciate.


Solution

  • Problem is sort out using convert it to json first.

    <json:xml-to-json-transformer doc:name="XML to JSON" />
        <foreach doc:name="For Each" collection="#[json:file/data/deliveryOrder]">
            <flow-ref name="insertdatabase" doc:name="Flow Reference" />
    
        </foreach>