Thursday, August 05, 2010

Fault handling in Oracle SOA Suite 11g-Example

We have already seen the theory part of fault handling as how it works,now in this section we will create a simple scenario to throw and then take appropriate action as per fault policies.

Pre requisite for this exercise is

SOA Suite 11.1.1.2
JDeveloper 11.1.1.2


Example.
===========

Create a new project in Jdeveloper





give some logical name to BPEL process make it a synchronous bpel process and say finish.




So now your composite should look like this.Drag and drop a BPEL process in your composite



Now again make this as a synchronous BPEL process and deselect the exposed as web service option.




So now the process should look like this.




now double click on Throw fault bpel process and drag and drop a throw activity in between .NOw double click on throw activity and choose one of the system fault



Create a fault variable also.

Once you will create it you will find that a wsdl is automatically added to your project RuntimeFault.wsdl

Now drag and drop an assign activity in between the throw and Receive input

In the assign activity assign some values to the fault Variable you have created.

So i have assigned some values as



So you bpel process which throws a fault should look like this



NOw connect the throw block with Catch Block as shown



Now go to the Catch Bpel process and drag and drop an invoke activity ,now connect the invoke activity with the throw partnerlink as shown below




NOw add a catch block to catch the fault,this will catch the same remote fault for which you have defined it.

NOw drag and drop a assign activity and copy the fault code to the output variable.

Again drag and drop a reply activity and send this output variable to the client.

We are doing so because we have only one client application here and we want that he should get the error.So when we reply the output to client we are basically throwing the fault to the calling application.

So now your fault handling process is ready,now we will add our fault policy to this project.

copy your fault-binding.xml and fault-policies.xml file in the same folder where you have your composite.xml lies

my fault-binding.xml file look something like this


xmlns="http://schemas.oracle.com/bpel/faultpolicy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

CatchFault


and my fault-policies.xml file looks like



xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.oracle.com/bpel/faultpolicy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

name="bpelx:remoteFault">















There are two important things that you need to note down

1>if you can see in your falut-binding.xml you can see an entry like

component faultPolicy="bpelFaultHandling"

this is baiscally a reference id which is passed to the fault-policies.xml so correpsonding to that

we have an entry in fault-policies.xml

faultPolicy version="2.0.1" id="bpelFaultHandling"

So the important thing is that this refernce id should match in the two files.

In my case it is bpelFaultHandling in both the case.


2>You can again see in your fault-bindings.xml an entry like this


CatchFault

This CatchFault is the name of the BPELProcess which is catching the fault.In my case the name of process which is
catching fault is CatchFault.


Now again we need to make two more addition in to our composite to make him aware that fault policies are added

fault-policies.xml
fault-bindings.xml

This should be added just after the service tag finishes

I am just pasting my composite.xml for example.




mode="active" state="on" xmlns="http://xmlns.oracle.com/sca/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy"
xmlns:ui="http://xmlns.oracle.com/soa/designer/">
location="CatchFault.wsdl" importType="wsdl"/>
location="ThrowFault.wsdl" importType="wsdl"/>




fault-policies.xml
fault-bindings.xml







catchfault_client_ep
CatchFault/catchfault_client


CatchFault/ThrowFault.throwfault_client
ThrowFault/throwfault_client




NOw you are done with your BPEL process.

Compile and deploy this project to your application server.

ONce deployed invoke the process you will get an option like this in the em console



Here we are getting an option of manual recovery as we have defined in our fault policy for manual intervention.Let me know if you have issues in it.


21 comments:

Kulin Desai said...

Hi Arpit

Have you ever tried other Fault Handlers such as FileAction, enqueue etc. Surprisingly it throws warning during compilation

Warning(15,17): Schema validation failed for fault-policies.xml: XML-24534: (Error) Element 'fileAction' not expected.

Thanks

Mikku said...

I must admit that i have not tried for FileAction and enqueue.If you could give me more information on the same,i can try it at my end and get back to you on that.

Kulin Desai said...

Thanks Arpit. Here is what I'm trying to Achieve

I'm reading a File and Processing it Using BPEL and Again Writing to a File. Now there is a fault called Rejected messages, which means if XML in the file which I'm reading is not a valid XML it will throw rejected messages exception. This can not be handled through BPEL catch exception. Also it does not archives the file if the file is rejected. So trying to use a File Based Rejection handler as mentioned in File Adapter Guide in conjunction with Composite I added Fault-Policies.xml and Fault-Binding.xml in the directory where Composite.xml is there. Also updated Composite.xml with

fault-policies.xml
fault-bindings.xml

And here is the extract from my fault-policies.xml












/xx/xx/xx/xxx/Inbound
xxxx.xml





And here is how my fualt-bindings file Look




Read

Kulin Desai said...

I just figured out the solutions. Found a bug in Oracle documentation Thanks though.

Mikku said...

You can also use bpel process rejection handler as explained in following post

http://soa-bpel-esb.blogspot.com/2010/05/bpel-process-rejection-handler.html

Kulin Desai said...

Thanks Arpit, I saw your example but not sure which version of SOA Suite you are using in that example, IN 11 g version Oracle dont support BPEL.xml for Rejection Handlers, that what they have written in Adapter Guide. Here is the wording from Oracle doc

"In the 10.x release, rejection handlers were defined in the deployment descriptor
(bpel.xml) of an Oracle BPEL process. However, in the 11g release, you must define
rejection handlers by using fault policies."

Mikku said...

Yes you are right, I have created it in 10g version.I believe i need to learn a lot in 11g,Thanks for keeping me updated with the latest informations.

Saurabh said...

Kulin

You mentioned that you found a bug in Oracle Documentation, can you please let me know what that bug was? I am facing the same issue

"Warning(22,21): Schema validation failed for fault-policies.xml: XML-24534: (Error) Element 'fileAction' not expected."

And have no idea how to fix this, please help!

Saurabh

Mikku said...

Saurabh,

I just create a simple scenario to test this,yes i am also getting this error message but this is only a warning message and it is not causing me any issues to deploy.For me the rejection handler is working fine,this is a warning which you can ignore.

Mikku said...

Saurabh you can just review my post

http://soa-bpel-esb.blogspot.com/2010/09/blog-post_14.html

i have attached a sample also.

Check the same and let me know if it works for you or not

Anonymous said...

Hi Mikku,

I want to create an business fault throw in BPEL. Instead of using a catch branch i want the fault policies to handle the fault and call a custom java code. I am able to this without using the Thrown for technical faults in BPEL such as remotefaults.

When defining the thrown business fault in the fault policies its not picked up.

I hope you can provide a solution.

Thanks

SR

Mikku said...

I didn't exactly get the issue ,Could you please explain it in detail or upload me your project for review.

Regards
Miku

Anonymous said...

Hi mikku,

Thanks for your reply. I have created an example to illustrate what I am trying to archieve.

I will email you.

Thanks

SR

Mikku said...

SR,

I reviewed your process and i have some queries on the same

1>Are you fault policies are in MDS repository ?

Reason i can see the fault policies in same directory as composite.xml

hence in this case you need not specify reference for fault policies as

oramds:/apps/definition/faultPolicies/

rather you can have your refernce for fault policies like this.

<property name="oracle.composite.faultPolicyFile">SyncFaultPolicy.xml</property>
<property name="oracle.composite.faultBindingFile">SyncFaultPolicyBindings-Composite.xml</property>

Next you do not have reference for the bpel process in you fault policy

It should have an entry for subprocess

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="2.0.1" xmlns="http://schemas.oracle.com/bpel/faultpolicy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<composite faultPolicy="SynchronousFaultPolicy"/>
<name>SubProcess</name>
</faultPolicyBindings>

These are the two points that you need to check.let me know your result once you make the changes.

Mikku said...

you also have defined in your fault policy

faultName xmlns:ns1="http://example/schema/common/error/V1"
name="flt:BusinessFault"

However namespace "flt" is not defined any where.

Anonymous said...

Hi Mikku,

Thanks for your feedback. I will have a look the moment I am back from my holiday.

SR

Anonymous said...

Hi Mikku,

I have tested the SCA composite (SubProcess) including your changes. Unfortunately the functional fault I am trying to catch in the fault policies is not working.

I start to wonder if it’s possible throwing a functional fault and catching the fault in the fault policies of the same process.

The reason is that BPEL expects to catch a fault thrown. If you don't specify a catch all branch at compile time JDeveloper will give a warning: No Fault Handler is found inside the faultHandlers block. Inside the faultHandlers activity, no catch or catchAll activity is found.

I think a thrown fault can only be handled in BPEL and not the fault policies. I am curious about your point of view and whenever the example process I have provided can catch the functional fault in the fault policies.

Thanks for your time.

SR

Mikku said...

It is possible,ONce i will be back will have a look in the same

Anonymous said...

Thanks a lot for your article..

Rohan said...

Hi Arpit,
Can you post your sample code there .It is no more in the specified location

Mikku said...

Hey Rohan,I think the link has expired,I will try to check in my repository if i still have the process or will try to create a new process and post it for the reference