WSO2 - 迭代调解员。错误后迭代应该继续

时间:2015-09-09 12:47:45

标签: wso2 wso2esb wso2carbon

在WSO2迭代中介中,如果在一次迭代中发生错误,我希望后续迭代继续。我们如何确保? 我已完成以下操作,但在第一次错误后执行没有继续。

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

1 个答案:

答案 0 :(得分:1)

WSO2中的错误与Java中的错误类似,它们与java中的异常不同。基本上,你不应该处理错误。 这意味着当迭代介体中存在错误时,它将退出循环。
我们通过围绕它设计来解决这个问题我们使用onError属性调用与错误处理序列相同的序列。但我们不处理失败的记录。代码是这样的。

{

declare 
@enddate varchar(6),
@FirstTableMonth int =201505,
@Table_Name sysname,
@TableMonth int,
@end int,
@CurrentMonth int = 0,
@NextYearMonth int = 1

set @enddate = 201611

WHILE @CurrentMonth < 11
BEGIN

    SELECT  @TableMonth =   CASE WHEN (@FirstTableMonth + @CurrentMonth) % 100 < 13 THEN 
                                @FirstTableMonth + @CurrentMonth 
                            ELSE
                                @FirstTableMonth + 100 - (@FirstTableMonth % 100) + @NextYearMonth
                            END,
                    @NextYearMonth =    CASE WHEN (@FirstTableMonth + @CurrentMonth) % 100 < 13 THEN 
                                    @NextYearMonth
                                ELSE
                                    @NextYearMonth + 1
                                END,
                    @end = case when @enddate 
                    @Table_Name =  'xx_'+CAST(@TableMonth as varchar)+'_T' 

                    SET @CurrentMonth = @CurrentMonth + 1
                    print @Table_Name;
END

}