user3190009
user3190009

Reputation: 43

wso2esb issue with iterate mediator

I'm quite new to WSO2 and XML/XPath and I'm having issues with getting an iterate mediator expression to work. My scenario is the follwing. I'm given a .csv file which is then transformed into XML with the Smooks mediator and a simple XSLT Transformation - both of which work fine, I tested them earlier. They result of this process has the following structure (and is put into a SOAP environment by the esb):

<?xml version='1.0' encoding='utf-8'?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Body>
          <Orderlist xmlns="http://ws.apache.org/ns/synapse">
              <Order>
                  <Nr>1234</Nr>
                  <Sender>
                      <!-- some child elements here -->>
                  </Sender>
                  <Recipient>
                      <!-- some child elements here -->
                  </Recipient>
              </Order>
              <Order> <!-- same as above --> 
              </Order>
              <!-- more orders here -->
           </Orderlist>
      </soapenv:Body>
  </soapenv:Envelope>

Now I'm using the following proxy to perform my transforms and then iterate over the Order elements:

    <proxy name="Aufgabe3Proxy" startOnLoad="true" trace="disable"
  transports="https http vfs" xmlns="http://ws.apache.org/ns/synapse">
  <target>
    <inSequence>
      <!-- transformations are done here, producing the above message -->          
      <iterate expression="$body/Orderlist/Order" preservePayload="true">
        <target>
            <sequence>
                <log level="full"/>
                <send>
                    <property expression="$body/Order/Start/text()"
                        name="uri.var.loc1" scope="default" type="STRING"/>
                    <property expression="$body/Order/Ziel/text()"
                        name="uri.var.loc2" scope="default" type="STRING"/>
                    <endpoint key="MapsEndpoint"/>
                </send>
            </sequence>
        </target>
      </iterate>
    </inSequence>
    <outSequence>
      <log level="full"/>
        <aggregate>
            <onComplete expression="//Orderlist">
                 <property name="transport.vfs.ReplyFileName" scope="transport"
                        type="STRING" value="responses-out.xml"/>
                 <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
                 <send/>
            </onComplete>
        </aggregate>

    </outSequence>
    <faultSequence/>
  </target>
  <parameter name="transport.PollInterval">5</parameter>
  <parameter name="transport.vfs.FileURI">file://C:\Users\admin\Desktop\Daten\MapsPaare\in</parameter>
  <parameter name="transport.vfs.ContentType">text/plain</parameter>
  <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
  <parameter name="transport.vfs.MoveAfterFailure">file://C:\Users\admin\Desktop\Daten\MapsPaare\fail</parameter>
  <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
  <parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
  <parameter name="transport.vfs.MoveAfterProcess">file://C:\Users\admin\Desktop\Daten\MapsPaare\out1</parameter>

    </proxy>

When I run this and put my .csv into the in-folger, the log only prints the read message and the Outcome of the transformations, but nothing more. Also it doesn't write the Responses-out.xml file (and does not create it). Can you please point me to the errors I'm making here?

Edit: A thing I tried out so far is: Since the ESB puts my Orderlist into a namespace, I tried to adjust my Iterate Expression like that:

<iterate expression="$body/OL:Orderlist/OL:Auftrag" preservePayload="true"
     xmlns:OL="http://ws.apache.org/ns/synapse">

However, when this is run the log gives me an error saying: "SynapseXPath Evaluation of the XPath expression $body/OL:Auftragsliste/OL:Auftrag resulted in an error" and Points out that it's unable to resolve the namespace prefix OL.

Upvotes: 0

Views: 1112

Answers (2)

Jean-Michel
Jean-Michel

Reputation: 5946

The thing you tried in your edit is the good way to do. Don't know why the node 'order' become 'Auftrag', but this iterate must work :

<iterate expression="$body/OL:Orderlist/OL:Order" preservePayload="true" xmlns:OL="http://ws.apache.org/ns/synapse">

Verify if the error in ESB log don't come from another part of your mediation

Upvotes: 0

user3190009
user3190009

Reputation: 43

Just to have a marked answer: the solution was like I wrote in a comment above. Replacing

<iterate expression="$body/Orderlist/Order" preservePayload="true">
    <target>
        <sequence>
            <log level="full"/>
            <send>
                <property expression="$body/Order/Start/text()"
                    name="uri.var.loc1" scope="default" type="STRING"/>
                <property expression="$body/Order/Ziel/text()"
                    name="uri.var.loc2" scope="default" type="STRING"/>
                <endpoint key="MapsEndpoint"/>
            </send>
        </sequence>
    </target>
  </iterate>

with

<iterate xmlns:OL="http://ws.apache.org/ns/synapse" expression="//OL:Orderlist/OL:Order" preservePayload="true">
    <target>
        <sequence>
            <log level="full"/>
            <send>
                <property expression="//OL:Order/OL:Start"
                    name="uri.var.loc1" scope="default" type="STRING"/>
                <property expression="//OL:Order/OL:Ziel"
                    name="uri.var.loc2" scope="default" type="STRING"/>
                <endpoint key="MapsEndpoint"/>
            </send>
        </sequence>
    </target>
  </iterate> 

did fix the issue.

Upvotes: 0

Related Questions