Friday, May 2, 2014

In previous post, we discussed about in-build error handling for file and ftp adapter. In-build error handling will put the corrupted file to default rejected message folder.

In this post, we will discuss about File Rejection Handler i.e. how to use Fault Handling Framework to handle errors when we encounter corrupt file during file polling.

Following error handler we can define inside fault policies to handler error.

·         Web Service Handler
·         Custom Java Handler
·         JMS Queue
·         File


We will discuss each error handler one by one. In this post we will discuss about “File” Rejection handler.

File Rejection Handler

By default adapter put the rejected message to default folder (C:\Oracle\Middleware\user_projects\domains\base_domain\rejmsgs) so we can configure this error handler if we want to put that rejected message to other location.

We need to use Fault Handling Framework to configure the error handler so we need to have fault-binding.xml and fault-policies.xml file.

Create a new fault-binding.xml file in the same project and add below content to it.

<?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">
   <service faultPolicy="RejectedMessage">
      <name>PollCustomerData</name>
   </service>
</faultPolicyBindings>

Please note that “PollCustomerData” is name of the adapter that poll the file.



Now create a fault-policies.xml file where we add fault and required action.

For this error handler below is the format for the action.

<Action id="ora-file">
  <fileAction>
    <location>FOLDER_LOCATION</location>
    <fileName>FILE_NAME</fileName>
<!-- FILE_NAME will support %ID%(rejected message instance id) or %TIMESTAMP% wildcards -->
  </fileAction>
</Action>

Use below content for fault-policies.xml file.

<?xml version="1.0" encoding="UTF-8" ?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy">
  <faultPolicy version="2.0.1" id="RejectedMessage">
    <Conditions>
      <!-- remote fault: -->
      <faultName xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages"
                 name="rjm:PollCustomerData">
        <condition>
          <action ref="ora-file"/>
        </condition>
      </faultName>
    </Conditions>
    <Actions>
    <!--write rejected message to file-->
      <Action id="ora-file">
        <fileAction>
          <location>D:\rejectedmsgs</location>
          <fileName>rejmsg_%ID%_%TIMESTAMP%.xml</fileName>
        </fileAction>
      </Action>
    </Actions>
  </faultPolicy>
</faultPolicies>




Please not that fault policy id should be same in both fault-binding.xml and fault-policies.xml file.

Save your changes and deploy your composite.

Testing Result


Now put corrupted file to poll folder. You will see file got deleted and see two files in D:\rejectedmsgs folder.

rejmsg_40003_1399012637053 file contains file content.
rejmsg_40003_1399012637053_metadata file contains metadata information.




Download sample code from here.


Next post explains about next error handler, File Rejection Handler, Web Service Error Handler for File Adapter.

13 comments :

  1. hi vivek i got the following errors when i tried the above process ,
    in fault-policies.xml
    Warning(16,21): schema - (Error) Element 'fileAction' not expected.
    Warning(20,16): schema - (Error) Element not completed: 'Action'

    warnings in fault-bindings.xml
    Warning(5,43): schema - (Error) Element 'service' not expected.

    and in some cases i am getting like
    Warning(2,66): schema - (Error) Can not find definition for element 'faultPolicies'

    ReplyDelete
    Replies
    1. Please paste your both the files here. One of the error says , you didn't close the "Action" tag in the file.

      Vivek

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. vivek my fault policies are not getting posted here..i dont no y??

      Delete
    5. You can send it to my email id.

      Vivek

      Delete
    6. Ever get past this error, I'm getting the same thing. Just curious if there was a trick.

      Delete
    7. That was just a warning message, if you deploy your composite with this warning, your composite will work as expected.

      Vivek

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. fault bindings code



    ftpReceiveFlexcubeData



    fault policys code














    /nfssoa/files/SOA4FSI_PROD/rejmsgs/FCUBS06BillPayPaymentCayInterface
    INVALID_MSG_FCUBS06BillPayPaymentCayInterface.*.dat






    issue is the rejected file is moving to default rejected messages, that file need in this path /nfssoa/files/SOA4FSI_PROD/rejmsgs/FCUBS06BillPayPaymentCayInterface
    what i have to do?

    ReplyDelete
    Replies
    1. you can simply mention "/nfssoa/files/SOA4FSI_PROD/rejmsgs/FCUBS06BillPayPaymentCayInterface" path in location field.

      Delete
  4. Hi Vivek,

    I am using FTP adapter to get files. Is there a way to redirect the rejected messages to same FTP server?

    Thanks,
    Ram

    ReplyDelete
  5. Hi Vivek,

    Iam using FTP adapter to read files from remote server. Is there a way to write the rejected messages to some location iin the same FTP server instead of writing them in local SOA server.

    Thanks,
    Ram

    ReplyDelete