Sunday, May 4, 2014

In previous post, we discussed about Queue error handler. In queue error handler rejected message is enqueued to advanced queue. In this post we will discuss about next error handler which is Custom Java error handler.

In Custom Java error handler error is handled by java framework. In this error handler we create custom java class which implements below IfaultRecoveryJavaClass interface.

package oracle.integration.platform.faultpolicy;
public interface IFaultRecoveryJavaClass
{
    public void handleRetrySuccess( IFaultRecoveryContext ctx);
    public String handleFault( IFaultRecoveryContext ctx);
}

Follow below steps to use Custom Java error for rejected file.

Custom Java Error Handler

First create a new java project in Jdeveloper. Name the project and name the default package as well.



For Custom Java error handler we need to implement IFaultRecoveryJavaClass interface and for this interface we need add fabric-runtime.jar to our project.

You can find this file at below location.

C:\Oracle\Middleware\Oracle_SOA1\soa\modules\oracle.soa.fabric_11.1.1



Now right click on your project and add a new Java class. Name your Java class and choose IFaultRecoveryJavaClass from Oracle à integration àplatform àfaultpolicy path.



Now add required logic to your class. For this post, we didn't add much logic; we will just show some message on console.



Now build your code and create jar file of above java class. To build jar file you need to choose “Client JAR File” and name your deployment profile.



You need to put above generated jar file to below location so that fault policy file can refer it.
C:\Oracle\Middleware\user_projects\domains\base_domain\lib

Now you need to restart the SOA server.

File Polling Service

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-java">
  <javaAction className="<package>.<javaClass>" defaultAction="<Action>">
    <returnValue value="SUCCESS" ref=”<Action> "/>
    <returnValue value="FAILED" ref="< Action>"/>
  </javaAction>
</Action>

  
Please add below content to 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-java"/>
        </condition>
      </faultName>
    </Conditions>
    <Actions>
      <!--Rejected Message to AQ-->
      <Action id="ora-file">
        <fileAction>
          <location>D:\rejectedmsgs</location>
          <fileName>rejmsg_%ID%_%TIMESTAMP%.xml</fileName>
        </fileAction>
      </Action>
      <Action id="ora-java">
        <javaAction className="filerejectionhandler.sampleclass"
                    defaultAction="ora-terminate">
          <returnValue value="Success" ref="ora-file"/>
        </javaAction>
      </Action>
    </Actions>
  </faultPolicy>
</faultPolicies>




Save your changes and deploy this composite to server.

Testing

Put file corrupted file to polling location. You should see log message to your console.

You also two files in rejected message folder because java function return “Success” and when it return Success “ora-file” action get invoked.




Download code from here.


0 comments :

Post a Comment