menu

Wednesday, October 22, 2014

Using Throw/CatchAll In SOA

Introduction:

     In this paper, I'll try to explain how throw and catchAll activities can be used in bpel process in Oracle SOA Suite environment.In the write of "healthcare example", we had thrown faults to clients. However we may catch all the faults that the application may throw and instead of throwing on error conditions we can return a result code and a result message to the client.In this way we can get both great performance improvement getting rid of the heavy throw statements and we could have the possibility of collecting all the error conditions and return it to the client at once.In either way we should include the result codes and messages at the documentation of the application since the client will distiguish the messages by this code and messages whether its an error condition or not.Also the client doesn't need to deal with catching the process anymore by this way.
In the example, we'll use assing, transformation, if, throw and catchAll activities.At the end of the write we should get the following composite and bpel process.

Using Throw/CatchAll In SOA
Figure 1

Using Throw/CatchAll In SOA
Figure 2

Create Bpel Process and Define Xsd and Wsdl Files:

    Create a synchron bpel process and open and edit the xsd and wsdl files according to the Figure 3 and Figure 4.We'll have two input fields as string and int, two output fields as resultCode and resultMessage, and a fault with two variables errorCode and errorMessage.

Using Throw/CatchAll In SOA
Figure 3

Using Throw/CatchAll In SOA
Figure 4

Define the Scope in Which We'll Use CatchAll:

     To use catchAll activity for the whole bpel process, drag and drop a scope from the Structured Activities to the place after the receiveInput.Now lets build the pseudo logic to see how throw and catchAll activities work.
First drag and drop an assing activity in the scope after the component receiveInput and just to be an example concat the input1 and input2 in the assign and set to the resultMessage.See in Figure 5 and 6.

Using Throw/CatchAll In SOA
Figure 5

Using Throw/CatchAll In SOA
Figure 6

Then, drag and drop an if activity after the assign statement and type the expression like in Figure 7. We simply want the lenght of concat of input1 and input2 to be greater than 5 and input2 to be greater than zero.

Using Throw/CatchAll In SOA
Figure 7

Before continue define a variable from the defined bpel fault message type to use in the throw activity.See in Figure 8.

Using Throw/CatchAll In SOA
Figure 8

Drag and drop an assign activity and a throw activity for the if condition is true.Assing for errorCode and errorMessage and throw with the predefined bpel fault using the previously defined fault message like in Figure 9 and 10.

Using Throw/CatchAll In SOA
Figure 9

Using Throw/CatchAll In SOA
Figure 10

For the else condition define another if activity for the condition input2 is zero and throw a builtin system fault invalidVariables.See in Figure 11 and 12.

Using Throw/CatchAll In SOA
Figure 11

Using Throw/CatchAll In SOA
Figure 12

Drag and drop another assign activity for the input2 is not zero condition and set the resultCode and resultMessage indicating the result is successful like in Figure 13.

Using Throw/CatchAll In SOA
Figure 13

Define CatchAll Activity:

     Now, we're ready to define catchAll activity. Go to the bpel editor, and choose catchAll from the scope we defined for the whole process like in Figure 14.

Using Throw/CatchAll In SOA
Figure 14

Drag and drop a xslt transformation under the catchAll activity and set the resultCode and resultMessage.If the errorCode and errorMessage are not empty we use them, otherwise we set "unexpected error" message with code 11.See in Figures 15, 16 and 17 for both design and xsl source.

Using Throw/CatchAll In SOA
Figure 15

Using Throw/CatchAll In SOA
Figure 16

Using Throw/CatchAll In SOA
Figure 17

Run the Application:

     We're ready to run the application.Just right click the application and choose Deploy and then choose Debug after placing breakpoint pair to the service reference in the composite. For details of how to test and debug the application you can have look at the "Debug and Test the Application" part of this write. Below we see the various results indicating success and error conditions in Figures 18,19 and 20.

Using Throw/CatchAll In SOA
Figure 18

Using Throw/CatchAll In SOA
Figure 19

Using Throw/CatchAll In SOA
Figure 20

Conclusion:

     Today, I talk about throw and catchAll activities and how to develop a fault handling strategy in Oracle SOA Suite environment.You can either choose to throw faults to the client or catch them and return result code and messages.The later has the advantage in performance and flexibility as you can collect all the errors and show the client.In any way, you should share the message codes and messages with the clients especially in the second case, since the client cannot distinguish the error and success conditions without having a fault.

You can download the source code from here.

2 comments:

  1. i followed the above steps but i didnt get the fault handling. Could you please help me

    ReplyDelete
  2. Good artcile, but it would be better if in future you can share more about this subject. Keep posting. SME Matching Grant

    ReplyDelete