Tuesday, July 28, 2015

File Adapter Error Handling through Fault Policy Framework for rejected files.

Hi,

In this post, let us see how to handle rejected files.

File Adapters/ FTP Adapters which are used in scenarios where files are polled in SOA Suite, there are cases where corrupt or bad files can come or be present.

By default, File Adapter uses a default location to put rejected files as per the control directory which is configured in the Adapter configuration in weblogic. The instance is faulted in EM console corresponding to the rejected file case. The moment happens before an instance is created through BPEL/Mediator and after the JCA based File Adapter polls the file.

Here is a diagram which explains something about Fault Policy Framework
image : www.ateam-oracle.com

 
The fault policy framework works for File Adapter error scenarios if in place.

Here is a sample:

Below is an extract from Fault Binding xml file. A fault binding file is structured for composite, component, reference and service faults. Here, file adapter read is a service so I have added "RejectedMessages" as the fault policy to refer to. There are two composites which uses File/FTP adapter to read the files.

-ReadOrderFile
-ReadPaymentFile
 

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="2.0.0"
                     xmlns="http://schemas.oracle.com/bpel/faultpolicy"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <composite faultPolicy="ErrorFaultPolicy"/>
    <component faultPolicy="ErrorFaultPolicy"/>
    <reference faultPolicy="ErrorFaultPolicy"/>
    <service faultPolicy="RejectedMessages">
        <name>ReadOrderFile</name>
        <name>ReadPaymentFile</name>
    </service>
</faultPolicyBindings>


Forany service related error, we can configure the Fault Policy framework to handle it.

Let us see the Fault policy file.

<faultPolicy version="2.0.0" id="RejectedMessages">
    <Conditions>
      <faultName xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages"
                 name="rjm:ReadOrderFile">
        <condition>
          <action ref="ReadOrderFile_001"/>
        </condition>
      </faultName>
      <faultName xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages"
                 name="rjm:ReadPaymentFile">
        <condition>
          <action ref="ReadOrderFile_002"/>
        </condition>
      </faultName>
...
...
...
 <Actions>
      <Action id="ReadOrderFile_001">
        <fileAction>
          <location>/../../../error</location>
          <fileName>Order_Error_%ID%_%TIMESTAMP%.dat</fileName>
        </fileAction>
      </Action>
      <Action id="ReadOrderFile_002">
        <fileAction>
          <location>/../../../error</location>
          <fileName>Payment_Error_%ID%_%TIMESTAMP%.dat</fileName>
        </fileAction>
      </Action>
...
...

So you can see here, that rejected files will be thrown to the given sample location with a generated ID and TIMESTAMP. The location and fileName tags defines those details about the File Action.

The actions are choice. We can either call a java service, a bpel composite , retry , rethrow etc for the way we want to handle the fault.

The best practice is to push the rejected files into a particular location shared to the application response for generating file data. Further, any manual/automated activity can be executed to decide actions taken on those corrupted files.

Thanks.


Friday, July 24, 2015

Dynamic Endpoint Url Invocation in BPEL

Hi,

I would like to share how to dynamically call a Web Service through BPEL using Endpoint Reference.

Firstly lets understand what use the Dynamic Endpoint Invocation could be. In scenarios where you have a good number of Services whose consumption parameters are same, ie input-output, to avoid code multiplication, we use DEI. Else a developer would end up creating as many partner links as the number of isomorphic services exists.

image : msdn.microsoft.com




First of all, you need to have the URL generated at runtime either through DVM / any source service request/ Database/ MDS etc.

In BPEL, assign the URL to a variable say ServiceToInvokeVar


ex:
 1
<assign name="Set_ServiceToInvokeVar">
      <copy>
        <from variable="inputVariable" part="payload"
              query="/ns3:******/ns3:*******/ns3:AbcsEndPointUrl"/>
        <to variable="ServiceToInvokeVar"/>
      </copy>
    </assign>
2
 <assign name="Assign_Endpoint">
      <copy>
        <from>
<EndpointReference xmlns="http://schemas.xmlsoap.org/ws/2003/03/addressing">
            <Address/>

 </EndpointReference>
</from>
        <to variable="EndpointReferenceVar" query="/ns1:EndpointReference"/>
      </copy>
      <copy>
        <from variable="ServiceToInvokeVar"/>
        <to variable="EndpointReferenceVar"
            query="/ns1:EndpointReference/ns1:Address"/>
      </copy>
      <copy>
        <from variable="EndpointReferenceVar"/>
        <to partnerLink="ABCSService"/>
      </copy>

    </assign>


If the above seems complicated to you, here I can explain here,

1. Assigned your runtime populated Endpoint to a variable say X.
2. Assign the EndpointReference WS-Addressing structure to a variable say E with null address.
3. Assign X to "/ns1:EndpointReference/ns1:Address"
4. Assign  E to your partner link.

Thats it !