-->

How Can I handle Error sequence in WSO2ESB

2019-09-09 08:24发布

问题:

i want handle error using fault sequence but i wish to customize it with delete operation my scenario is while i am inserting in 2 tables if error occurred in 2nd table insertion i need to delete 1 st row insertion also my config is below

<proxy xmlns="http://ws.apache.org/ns/synapse" name="ErrorHandling" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target >
      <inSequence onError="fault">
         <property name="eno" expression="//eno/text()" scope="default" type="STRING"/>
         <property name="ename" expression="//ename/text()" scope="default" type="STRING"/>
         <property name="esal" expression="//esal/text()" scope="default" type="STRING"/>
         <property name="deptname" expression="//deptname/text()" scope="default" type="STRING"/>
         <property name="deptid" expression="//deptid/text()" scope="default" type="STRING"/>
         <payloadFactory>
            <format>
               <p:insert_emp_operation xmlns:p="http://ws.wso2.org/dataservice">
                  <xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
                  <xs:ename xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:ename>
                  <xs:esal xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:esal>
               </p:insert_emp_operation>
            </format>
            <args>
               <arg expression="get-property('eno')"/>
               <arg expression="get-property('ename')"/>
               <arg expression="get-property('esal')"/>
            </args>
         </payloadFactory>
         <send receive="Error_Seq">
            <endpoint>
               <address uri="http://localhost:9764/services/emp_DataService/" format="soap11"/>
            </endpoint>
         </send>
         <log level="full"/>
      </inSequence>
      <outSequence  onError="fault">
         <send/>
         <log level="full"/>
      </outSequence>
   </target>
   <description></description>
</proxy>

and sequence is like this

<sequence xmlns="http://ws.apache.org/ns/synapse" name="Error_Seq" onError="fault">
   <property xmlns:f="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="//f:ID/text()" scope="default" type="STRING"/>
   <log>
      <property xmlns:ns="http://org.apache.synapse/xsd" name="faisal" expression="get-property('ID')"/>
   </log>
   <payloadFactory>
      <format>
         <p:insert_dept_operation xmlns:p="http://ws.wso2.org/dataservice">
            <xs:deptno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:deptno>
            <xs:deptname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:deptname>
            <xs:deptid xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:deptid>
         </p:insert_dept_operation>
      </format>
      <args>
         <arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ID')"/>
         <arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptname')"/>
         <arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptid')"/>
      </args>
   </payloadFactory>
   <send>
      <endpoint>
         <address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
      </endpoint>
   </send>
</sequence>

fault sequenceis like this

<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault">
   <property xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="get-property('ID')" scope="default" type="STRING"/>
   <log level="full">
      <property name="MESSAGE" value="Executing default 'fault' sequence"/>
      <property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
      <property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
      <property xmlns:ns="http://org.apache.synapse/xsd" name="Property" expression="get-property('ID')"/>
   </log>
   <payloadFactory>
      <format>
         <p:Delete_Op xmlns:p="http://ws.wso2.org/dataservice">
            <xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
         </p:Delete_Op>
      </format>
   </payloadFactory>
   <send>
      <endpoint>
         <address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
      </endpoint>
   </send>
</sequence>

but its not working its working while the DSS Is in OFF mode let me know when DSS is In Running mode how to delete the 1st table row

回答1:

In your scenario when update fails at DSS, it will send back a SOAP fault to the ESB. Since ESB this is still just another message response, and it will not goto the fault sequence, unless you explicitly check the message and do the necessary actions. So you have to declare comming message is a SOAP_FAULT so you hace to say it is a SOAP_FAULT and force it to error sequance. This is explained in [1].

[1] http://maharachchi.blogspot.com/2012/09/now-you-can-send-soapfaults-to-fault.html