Understanding of Compensation Handler and Compensate Scope in Oracle SOA Suite 12C

You can easily understand the utilization of Compensate and compensate scope from its meaning itself. Compensation occurs when BPEL process cana��t complete all process after completing some processes or transactions. BPEL process can use compensation activity by using compensation handler.

For example, if BPEL process is designed as calculator operation (addition, subtraction, division) and for division operation the second input number is zero then the whole BPEL process will perform compensation activity by showing all the output of operations as -2.

  1. Create a separate application for exception example. Go to File -> New -> Application. Select SOA Application under General category. Enter application name CompensateScopeApplication
  2. Click on Next button and enter project name CompensateScopeDemo. Select Composite With BPEL Process in the next wizard.
  3. Click on Finish button and BPEL creation wizard will open. Enter BPEL process name CalculatorBPELProcess and select synchronous BPEL process in template field. Select the checkbox Expose as a SOAP service and input & output value will be remain default.Compensate_Scope_1
  4. Add one more element under process elementCompensate_Scope_2
  5. Create three variables in BPEL processCompensate_Scope_3 Compensate_Scope_4
  6. Place a scope between receiveInput and replyOutput. Add three more scopes within this scope and add three assign activity within each scope like below screenshot.Compensate_Scope_5 Compensate_Scope_6
  7. Initialize the three variables to -1 in Assign activity before all the three scopes.Compensate_Scope_7 Compensate_Scope_8
  8. Edit each assign activity within the scopes. Add the below three expression in three assign activities. A� A� A� A� A� $inputVariable.payload/client:number1 + $inputVariable.payload/client:number2 A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� $inputVariable.payload/client:number1 – $inputVariable.payload/client:number2 A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A� A�$inputVariable.payload/client:number1 div $inputVariable.payload/client:number2
  9. Add Compensation Handler in two scope (addition scope and subtraction scope)Compensate_Scope_9
  10. Drag and drop Assign activity in each Compensation Handler and assign -2 to addResult and subResultCompensate_Scope_10 Compensate_Scope_11
  11. Add an IF condition under division scope. Drag and drop IF condition after Assign_divOutput like the below screenshotCompensate_Scope_12
  12. Add condition in IF condition like when second input variable is zeroCompensate_Scope_13
  13. Now throw the exception when second input will be zero. Drag a Throw activity under IF containerCompensate_Scope_14
  14. Double click on Throw activity and editor window will open. Enter any name of throw activity and enter DivisionByZeroURI as Namespace URI and DivisionByZeroLP as Local PartCompensate_Scope_15
  15. Add a Catch block in the division scopeCompensate_Scope_16
  16. Edit the Catch activity like below screenCompensate_Scope_17
  17. Add an Assign activity in the Catch Block. Assign a value -2 to the variable divResult. Again throw this exception to the Catch All block in the outer scopeCompensate_Scope_18
  18. Select Compensate from BPEL construct and drag and drop it in the Catch All blockCompensate_Scope_19
  19. Add an Assign activity before replyOutput and add an expression like below screenshotCompensate_Scope_20
  20. Deploy the project and test it in EM console. Enter second number as 0 and you will get the below output as all the scope will be compensated by the compensation handler and compensate activity. A� Compensate_Scope_21Now we will discuss about the Compensate Scope activity.
  21. Delete compensate activity from catch all block and drag and drop a Compensate Scope in place of compensate.Compensate_Scope_22
  22. Double click on compensate scope and editor window will open. Select scope2 as target scopeCompensate_Scope_23
  23. Again deploy the project and test it by giving same input. Now this time output will be different. Only scope2 (subtraction operation) will be compensated with -2 and scope1 (addition operation) will give correct result. As target scope is scope2 in the compensate scope, only scope2 will be compensated with the value -2.Compensate_Scope_24

Leave a Reply

Your email address will not be published. Required fields are marked *

Show my latest post here