Friday, May 2, 2014

In previous post, we discussed file error handler which handle the rejected file and put that to custom folder with custom file name. In this post we will discuss about next error handler which is web service handler.

In web service handler rejected message is handled by web service, there is predefined WSDL interface which have to use to create web service which will handle the rejected message.

Below is the schema that we need to use for that web service.

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://xmlns.oracle.com/pcbpel/errorHandling"
        xmlns:tns="http://xmlns.oracle.com/pcbpel/errorHandling"
        elementFormDefault="qualified">
  <element name="RejectedMessage" type="tns:RejectedMessageType"/>
    <complexType name="RejectedMessageType">
        <sequence>
       <!-- base64 encoded strings" -->
          <element name="MessageHeader" type="string"/>
          <element name="MessagePayload" type="string"/>
          <element name="RejectionReason" type="string"/>
        </sequence>
      <attribute name="RejectionId" type="string"/>
    </complexType>
</schema>

Follow below steps to use web service handler for rejected file.

Web Service Handler Service

First create a web service for web service handler which will handle rejected file. Use above mentioned schema and make sure web service has only one port type and one input operation.


You can add required logic to it. For this post, we will not add any logic to it.

Save the composite and deploy it to the server.

Below is the endpoint of web service handler.





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-ws">
  <invokeWS uri="WebServiceURI"/>
<!-- format - <Absolute wsdl path>|service name|port name -->
</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-ws"/>
        </condition>
      </faultName>
    </Conditions>
    <Actions>
      <!--invoke web service for rejected messag-->
      <Action id="ora-ws">
        <invokeWS uri="http://localhost:8001/soa-infra/services/default/WebServiceHandler/webservicehandlerbpel_client_ep?WSDL|webservicehandlerbpel_client_ep|WebServiceHandlerBPEL_pt"/>
      </Action>
    </Actions>
  </faultPolicy>
</faultPolicies>



Save your changes and deploy this composite to server.


Testing

Put file corrupted file to polling location. You should see new instance of web service handler.




Download sample code from here.


Next post explains about next error handler, File rejection Handler- JMS queue error Handler for File Adapter.


3 comments :

  1. Hi Vivek,

    One question regarding the fault policy. Is the action 'invokeWS' been removed from the version 11.1.1.7 or the format to invoke a deployed webservice changed in this version ? I am trying to call a weservice using fault-policy in my code, but the 'invokeWS' part is not working and gives 'java.lang.NullPointerException'. Do you have any idea regarding this scenario ?

    However if I try to call the action 'writeToFile' or 'human-intervention' these are working fine. But only the 'invokeWS' part is not working using :


    Thanks,
    Vatan

    ReplyDelete
    Replies
    1. Hi Vatan,

      I haven't tested this on 11.1.1.7 version. I tested it on 11.1.1.5 version. I know there was one bug in 11.1.1.5 version for custom java handler and that was corrected in next version but not aware if they made any changes for web service handler.

      Vivek

      Delete
  2. Hi Vivek,
    How can we handle invokeWS URI dynamically - If we move from Dev to QA to Prod, is any way we can control via EM Console ?

    Sri

    ReplyDelete