Use Case-
Reading student details from a csv based file if data is not correct than placing the incorrect data file to a different location.
To handle the rejected messages we will use Fault Handling Framework.
First Create a SOA Application StudentInfo and a SOA project ReadStudentInfo.
Create a Bpel Process ReadDetails with Define Service Later template.
Next Step is to create a Sample .txt file that we will use to configure the FileAdapter.
Now add a file adapter and configure it to read files of this format.
Select the Read operation give the fie location from where you want to read the file and specify the file format for example here *.txt. Specify the polling frequency.
Next Step to select the Native Format Builder explained in detailed manner in my previous blog:- http://oraclesoasolution.blogspot.in/2016/11/generating-csv-file-with-header-name.html
.
Wire the FileAdapter and Bpel process and create receive activity with create instance checked option in bpel to receive input.
Create a folder in your local system where you want the rejected messages to come, say C:\temp\students\error .
Create a new file fault-policies.xml and add the following code in it.
<?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:ReadInfo">
<condition>
<action ref="writeToFile"/>
</condition>
</faultName>
</Conditions>
<Actions>
<Action id="writeToFile">
<fileAction>
<location>c:/temp/students/error</location>
<fileName>stud_%TIMESTAMP%.txt</fileName>
</fileAction>
</Action>
</Actions>
</faultPolicy>
</faultPolicies>
Notice that the name of the fault attribute refers to the adapter name that we configured in the previous step.
<faultName xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages" name="rjm:ReadInfo ">
In the actions section, we have specified a file action. We can specify four types of actions here:-
- File action
- Java handler
- Queue
- Web service
Now create another file called fault-bindings.xml and add following code
<faultPolicyBindings version="2.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<service faultPolicy="RejectedMessages">
<name> ReadInfo </name>
</service>
</faultPolicyBindings>
The fault policy given here, “RejectedMessages”, needs to match what we gave as Id in fault-policies file.
Make sure that the adapter is not polling recursively by checking the adapter .jca file.
Deploy the code
Put a file named student.txt with incorrect format, such as below.
Check the folder specified there you will find the file with that data also check the em console there you will see the error message.
If we did not specify a location in the fileAction, then by default, the messages are stored in the directory:- <<domain_name>>/rej_msgs/<<wls_server_name>>/<<composite name>>