Sujith Babu
Sujith Babu

Reputation: 359

WSO2 - Iterate mediator. Iteration should continue after error

In WSO2 iterate mediator, if an error happens in one iteration, I want the subsequent iterations to continue. How do we ensure that? I have done the following, but the execution does not continue after the 1st error.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="IterateErrprTest" onError="onErr2Cric">
   <payloadFactory media-type="xml">
      <format>
         <format xmlns="">
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
               <soapenv:Body>
                  <LIST>
                     <DETAIL></DETAIL>
                     <DETAIL></DETAIL>
                  </LIST>
               </soapenv:Body>
            </soapenv:Envelope>
         </format>
      </format>
   </payloadFactory>
   <iterate xmlns:ns="http://org.apache.synapse/xsd" continueParent="true" expression="//LIST/DETAIL" sequential="true">
      <target sequence="2Cric"></target>
   </iterate>
</sequence>
<!--- In my target sequence 2Cric, I have introduced an error by calling a non-existent website -->
<sequence xmlns="http://ws.apache.org/ns/synapse" name="2Cric" onError="onErr2Cric">
   <log>
      <property name="KKLK" value="KKLK KKLK"></property>
   </log>
   <callout serviceURL="http://www.cricinfo22.com">
      <source type="envelope"></source>
      <target key="Output"></target>
   </callout>
</sequence>

<!--- The error sequence  -->
<sequence xmlns="http://ws.apache.org/ns/synapse" name="onErr2Cric">
       <log>
          <property name="onErr2CricError" value="2Cric error has happened"></property>
       </log>
</sequence>

Upvotes: 1

Views: 1289

Answers (1)

Sujith Babu
Sujith Babu

Reputation: 359

The errors in WSO2 and similar to errors in Java and they are not the same as exceptions in java. Basically, you are not supposed to handle errors. This means that when there is an error in the iterate mediator, it will exit from the loop.
We handled this by designing around it. We called the same sequence as our error handling sequence with the use of onError attribute. But we do not process the failed record. The code is some what like this.

<sequence xmlns="http://ws.apache.org/ns/synapse"
          name="MySequence"
          onError="MySequence"
          trace="enable"
          statistics="enable">
  <!-- Error logging is done -->
  <!-- Get the list of records to process from the database excluding the ones failed -->
<!-- Our code here does not get the failed  -->

Upvotes: 1

Related Questions