Tuesday, September 14, 2010

Rejection Handling in SOA Suite 11g

Rejection handling in SOA Suite 11g is totally different from rejection handling in SOA Suite 10g in terms of configuration.

For a working example and illustration of rejection handler in SOA Suite 10g you can refer to the following document

In 10g we used to configure it in bpel.xml but in 11g we configure it through fault binding and fault policies.

We will just see an example and try to understand what all needs to be taken care of in order to create a successful rejection handling process.

I will create a sample process which has file adapter which will be polling for records in certain folder,it will be looking for a particular format of file and when we will pass some other format it will cause error and that should be handled or taken care of.

You can download my working sample from following location


Open up you jdeveloper

Create an empty composite in Jdeveloper

Now drag and drop a file adapter in the exposed service swimlane



Provide service name as

GetRejection



it will be a read operation and it will read data from local folder location




input parameter can be anything so i have given it as *.*



For schema selection create a native schema



Create a delimited file



now choose the file for input format,i just created a file input.txt which contains some delimited value,i will just choose the input.txt and it will create the number of records as per the number of delimited element as can be seen below



Keep on saying next till it ask for element name,specify some name to it



It will automatically crate an xsd as shown



NOw keep saying next and complete the wizard.

Now again in the composite drag and drop a bpel process and choose define service later option.

connect it to the adapter we have created earlier and go in to the bpel process.



This process will do nothing and just receive the input variable from file adapter and assign it to some local variable,so my process will look something like this.




so now compile and deploy this process to server.

Once deployed copy a image file of file of some different format in the input polling location and you should see a fault getting generated in em console.




Now we will create a fault policy to handle it

Followed document
http://download.oracle.com/docs/cd/E12839_01/integration.1111/e10231/life_cycle.htm#BABGIGGI

and created a fault-bindings.xml and fault-policies.xml file

placed it in the same folder where my composite.xml lies.


Now these are the things one need to take care
<faultPolicyBindings version="2.0.1" xmlns="http://schemas.oracle.com/bpel/faultpolicy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<service faultPolicy="RejectedMessages">
<name>GetRejection</name>
</service>
</faultPolicyBindings>


as you can see the name is GetRejection which is basically the name of my file adapter.

Again faultPolicy="RejectedMessages" which has to be matched in both the fault-policies.xml and fault-bindings.xml so my fault-policies.xml (id="RejectedMessages)looks like


<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies>
<faultPolicy version="2.0.1" id="RejectedMessages">
<Conditions> <!-- All the fault conditions are defined here -->
<faultName xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages" name="rjm:GetRejection"> <!-- local part of fault name should be the service name-->
<condition>
<action ref="writeToFile"/> <!-- action to be taken, refer to Actions section for the details of the action -->
</condition>
</faultName>
</Conditions>
<Actions> <!-- All the actions are defined here -->
<Action id="writeToFile">
<fileAction>
<location>/refresh/home</location>
<fileName>emp_%ID%_%TIMESTAMP%.xml</fileName>
</fileAction>
</Action>
</Actions>
</faultPolicy>
</faultPolicies>

Here again as you can see "rjm:GetRejection"

service name is the name of the file adapter service.


Once these changes are done you just need to make entry in your composite.xml for these fault policies

<property name="oracle.composite.faultPolicyFile">fault-policies.xml</property>
<property name="oracle.composite.faultBindingFile">fault-bindings.xml</property>

so my composite.xml will look like this

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SOA Modeler version 1.0 at [9/15/10 9:20 AM]. -->
<composite name="RejectionHandler" revision="1.0"
label="2010-09-15_09-20-51_734" 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/">
<import namespace="http://xmlns.oracle.com/pcbpel/adapter/file/Application1/RejectionHandler/GetRejection"
location="GetRejection.wsdl" importType="wsdl"/>
<service name="GetRejection" ui:wsdlLocation="GetRejection.wsdl">
<interface.wsdl interface="http://xmlns.oracle.com/pcbpel/adapter/file/Application1/RejectionHandler/GetRejection#wsdl.interface(Read_ptt)"/>
<binding.jca config="GetRejection_file.jca"/>
</service>
<property name="oracle.composite.faultPolicyFile">fault-policies.xml</property>
<property name="oracle.composite.faultBindingFile">fault-bindings.xml</property>
<component name="BPELProcess1">
<implementation.bpel src="BPELProcess1.bpel"/>
</component>
<wire>
<source.uri>GetRejection</source.uri>
<target.uri>BPELProcess1/GetRejection</target.uri>
</wire>
</composite>


There are few things which have been pointed out to me.

once you will create this process and compile it you may get an warning


Warning(2,18): Schema validation failed for fault-policies.xml: XML-24538: (Error) Can not find definition for element 'faultPolicies'


Well this is just a warning message and this should not affect the working of the business process that we have created.

There are some workaround given that is to add some name space to fault policies

so it should look like

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

but even after doing that the compilation error comes up as


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

Warning(23,16): Schema validation failed for fault-policies.xml: XML-24521: (Error) Element not completed: 'Action'


This is a bug and it is supposed to be fixed in next release of SOA.

But this doesnot affect the working of this process.

Because as soon as i keep the file in input polling folder a fault is generated and the fault message in particular format gets generated in the location defined in fault policy.


One more thing to keep in mind is that

If you do not configure rejection handlers as mentioned in Configuring Rejection Handlers, then a default file-based rejection handler will kick in and the rejected messages will be directed to <domain_home>/rejmsgs/<wls_server_name>/<composite_name>.


if you don't have a rejmsgs folder already with installation you can create it manually.Let me know if you have any issues in the same.

4 comments:

Anonymous said...

I have created a similar process as defined..However the fault policy seems to be not invoked somehow and the rejected file is not written in the predefined folder.

Can you please comment. I am using SOA 11g 11.1.1.3

Mikku said...

What is the error you are getting in soa diagnostic logs?

Anonymous said...

Hi,

I've followed the same process as you've shown above and even I'm getting those warning messages which you have mentioned i.e., 1. Element not completed: 'Action' 2. Element 'fileAction' not expected. 3. Element 'service' not expected.

And files are not getting written on to the location I've mentioned in fault-policies.xml.

NOTE: I'm using FTP Adapter

Mikku said...

I have to admit that i have not tried it with FTP Adapter.
But there are few things you can try
1> Try with a putty or winscp to copy a file to the FTP location.

2>Check the soa server logs for the exact error message.

2> AS you can see in the fault policy the action write to file is pointing to file action. For an FTP we need to explicitly provide the authentication details so that server can connect and write the data to that particular location.
So we might need to specify some properties which could pass the host and port details for the server. By default the port is 22.
You can try to find out the properties through which these details can be passed and try.