Showing posts with label SOA. Show all posts
Showing posts with label SOA. Show all posts

Tuesday, August 16, 2016

SOA: Fault Handling: Creating a fault policy

Fault handling is a very interesting concept in SOA. It is analogous to Exception Handling per OOPs concepts.

Fault Policy is defined to handle runtime fault exceptions. You can define actions to execute based on the type of exception. Here's a 1-0-1 on defining a simple fault policy:

1 -  Create the fault-policies.xml file

Right Click on the Project > Select From Gallery > Select SOA Tier/Faults > Fault Policy Document > Click Ok

This creates a fault-policies.xml within the project/SOA folder.

2 - Editing the fault policy

Open the fault-policies.xml to edit the fault policy.

Provide a unique ID to the fault policy:
<faultPolicy id="MyFaultPolicy">

Let's define the fault policy to retry 3 time at a interval for 120 sec for any runtime fault:

<faultName>
    <condition>
        <action ref="ora-retry"/>
    </condition>
</faultName>

This means for any fault (since no name is specified) the action "ora-retry" will be executed. The action "ora-retry" is a custom action here. We will need to define what ora-retry means.

3 - Define ora-retry

Add the following action to the fault policy file.

<Action id="ora-retry">
    <retry>
        <retryCount>2</retryCount>
        <retryInterval>60</retryInterval>
        <exponentialBackoff/>
        <retryFailureAction ref="default-terminate"/>
    </retry>
</Action>

4 - Review the Fault Policy

Here is how the fault-policies.xml document looks:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:medns="http://schemas.oracle.com/mediator/faults" xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages">
    <faultPolicy id="MyFaultPolicy">
        <Conditions>
            <faultName>
                    <action ref="ora-retry"/>
            </faultName>
        </Conditions>
        <Actions>
            <Action id="default-termination">
                <abort/>
            </Action>
            <Action id="ora-retry">
                <retry>
                    <retryCount>2</retryCount>
                    <!--<retryInterval>43200</retryInterval>-->
                    <retryInterval>60</retryInterval>
                    <exponentialBackoff/>
                    <retryFailureAction ref="custom-java-send-email"/>
                    <retrySuccessAction ref="default-termination"/>
                </retry>
            </Action>
        </Actions>
    </faultPolicy>
</faultPolicies>


5 - Create the Fault Bindings

Now the fault policy is created. However, the job is not done yet. We need to associate the fault policy to the composite. Thus, whenever there is a fault in the composite the fault policy "MyFaultPolicy" will be invoked.

To do this we need to create the fault-bindings.xml file within Project/SOA folder as follows:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="2.0.1" xmlns="http://schemas.oracle.com/bpel/faultpolicy">
    <composite faultPolicy="MyFaultPolicy" />
</faultPolicyBindings>




Please share your feedback below. Hope this is helpful!


CaptiveCode


Sunday, August 14, 2016

How To: Throw a custom fault/ exception in BPEL (SOA-Fault Handling)

Fault Handling in SOA is analogous to Exception Handling in OOPs. Below is how to throw a fault in a BPEL process:

1 - Define the fault message type

Add the RuntimeFault.wsdl to the Project/SOA/WSDLs folder. This WSDL contains the message definition of the fault that will be thrown at runtime.

<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="RuntimeFault" targetNamespace="http://schemas.oracle.com/bpel/extension"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
    <message name="RuntimeFaultMessage">
        <part name="code" type="xsd:string"/>
        <part name="summary" type="xsd:string"/>
        <part name="detail" type="xsd:string"/>
    </message>
</definitions>

2 - Define the fault variable to hold the fault

Define a new BPEL variable with the message type "RuntimeFaultMessage" created in the step above.

Variable Name: faultVar
Type: Message Type
Namespace: http://schemas.oracle.com/bpel/extension
Local Part: RuntimeFaultMessage

3 - Create a throw activity

Drag and Drop the "Throw" activity from the Components Menu into your BPEL process.

Activity Name: ThrowFault
Namespace: <Target Namespace of your BPEL process>
Local Part: <Name the Fault>
Fault Variable: faultVar (fault variable created in the step above)



Hope you find this information useful.Please share your feedback below. I would love to hear from you.

CaptiveCode

Tuesday, July 5, 2016

SOA: Basics: URLs for SOA Consoles - EM, OSB, B2B

If you are a beginner in middleware practice, keep these URLs handy for your reference!

Get the SOA Server Host Name & Port Number from your SOA Administrator.

Once you obtain that, below are the URLs you will use to access your middleware products:
  • SOA Console: https://host:port/console
  • SOA Enterprise Manager: https://host:port/em
  • OSB Console: https://host:port/sbconsole
  • B2B Console: https://host:port/b2bconsole


Hope you find this information useful.Please share your feedback below. I would love to hear from you.

CaptiveCode

Friday, March 18, 2016

Oracle B2B: How to unit test your Oracle B2B Setup

Oracle provides Shell and PL/SQL scripts to unit test your B2B application. These scripts enable you to enqueue/ dequeue messages B2B queues. Queing messages to the following B2B queues helps simulate inbound and outbound messages to/from Oracle B2B. Thus, enabling unit testing of your B2B Setup.

1) IP_IN_QUEUE - B2B queue for Inbound messages
2) IP_OUT_QUEUE - B2B queue for Outbound messages

Using Shell Scripts:
SOA 11g: B2B - How to Use Scripts to Enqueue a Message (Doc ID 1376541.1)
https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=bu4l6uddl_185&_afrLoop=562365794673522

Using PL/SQL Scripts:
http://www.oracle.com/technetwork/topics/b2b-tn-004-enqueue-dequeue-plsql-132991.pdf

Additional Reference:
Refer the Fusion Middleware User's Guide for Oracle B2B >> Chapter 23 Utilities for Enqueuing and Dequeuing
http://docs.oracle.com/cd/E23943_01/user.1111/e10229/enq_deq.htm#XBBUG1502


Hope you find this information useful.Please share your feedback below. I would love to hear from you.

CaptiveCode

Sunday, March 13, 2016

SOA: Basics: Creating a WSDL using a XSD

This is one of the basic requirements for SOA developers. Today, we will learn how to generate a WSDL file using a XSD. We will use Eclispe to achieve this. So, let's begin!

Our Objective:
To build a HelloWorld WSDL that will have the following inputs, outputs and operations:
  • Inputs:
    • First Name
    • Last Name
  • Outputs:
    • GreetingsMessage
  • Operations:
    • sayGreetings






















Creating the XSD

Create a new Dynamic Web Project > Provide a Project Name (HelloWorldSvc) > Click Finish
Right click the WEB-INF > Click New > Other > Select XML Schema File

Create HelloWorldRequest.xsd


Add the firstName and lastName elements to the HelloWorldRequest.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/HelloWorldRequest" xmlns:tns="http://www.example.org/HelloWorldRequest" elementFormDefault="qualified">
    <element name="hw_Request" type="tns:hw_Request" />
    <complexType name="hw_Request">
    <sequence>
    <element name="firstName" type="string" minOccurs="1" maxOccurs="1"></element>
    <element name="lastName" type="string" minOccurs="1" maxOccurs="1"></element>
    </sequence>
    </complexType>
</schema>


Similarly,
Create HelloWorldResponse.xsd


Add the following elements to the HelloWorldResponse.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/HelloWorldResponse" xmlns:tns="http://www.example.org/HelloWorldResponse" elementFormDefault="qualified">
    <element name="hw_Response" type="string" />
</schema>


Creating the WSDL

Right click the WEB-INF > Click New > Other > WSDL
Provide a name for the WSDL and click Finish

Follow these steps to update the WSDL:

Add the namespace for the request and response xsd to the wsdl

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/HelloWorld/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorld"
targetNamespace="http://www.example.org/HelloWorld/" xmlns:request="http://www.example.org/HelloWorldRequest"
xmlns:response="http://www.example.org/HelloWorldResponse">

Import the schemas for the request and response

<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/HelloWorld/">
<xsd:import namespace="http://www.example.org/HelloWorldRequest" schemaLocation="../xsd/HelloWorldRequest.xsd" />
<xsd:import namespace="http://www.example.org/HelloWorldResponse" schemaLocation="../xsd/HelloWorldResponse.xsd" />
</xsd:schema>
</wsdl:types>

Add the message for the request and response messages

<wsdl:message name="sayGreetingsRequest">
<wsdl:part element="request:hw_Request" name="parameters" />
</wsdl:message>
<wsdl:message name="sayGreetingsResponse">
<wsdl:part element="response:hw_Response" name="parameters" />
</wsdl:message>

Update the process name and message binding
<wsdl:portType name="HelloWorld">
<wsdl:operation name="sayGreetings">
<wsdl:input message="tns:sayGreetingsRequest" />
<wsdl:output message="tns:sayGreetingsResponse" />
</wsdl:operation>
</wsdl:portType>


Generated Output/ Final WSDL

And your WSDL is ready! Here's how it looks!

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/HelloWorld/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorld"
targetNamespace="http://www.example.org/HelloWorld/" xmlns:request="http://www.example.org/HelloWorldRequest"
xmlns:response="http://www.example.org/HelloWorldResponse">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/HelloWorld/">
<xsd:import namespace="http://www.example.org/HelloWorldRequest"
schemaLocation="../xsd/HelloWorldRequest.xsd"></xsd:import>
<xsd:import namespace="http://www.example.org/HelloWorldResponse"
schemaLocation="../xsd/HelloWorldResponse.xsd"></xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="sayGreetingsRequest">
<wsdl:part element="request:hw_Request" name="parameters" />
</wsdl:message>
<wsdl:message name="sayGreetingsResponse">
<wsdl:part element="response:hw_Response" name="parameters" />
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="sayGreetings">
<wsdl:input message="tns:sayGreetingsRequest" />
<wsdl:output message="tns:sayGreetingsResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldSOAP" type="tns:HelloWorld">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="sayGreetings">
<soap:operation soapAction="http://www.example.org/HelloWorld/sayGreetings" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorld">
<wsdl:port binding="tns:HelloWorldSOAP" name="HelloWorldSOAP">
<soap:address location="http://www.example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>



Hope you find this information useful.Please share your feedback below. I would love to hear from you.

CaptiveCode