Wednesday, 9 November 2011

Lesson09-Event Delivery Network

Event Delivery Network allows publish-subscribe type of loose coupling between SCA components. This is similar to JMS/AQ model except that user is spared from remembering and using low level JMS connectivity details. Instead, SOA framework neatly abstracts these details in the Even Delivery Network so that users can purely focus on publishing and subscribing to events.
This approach is highly useful when an event publisher doesn’t know about the number or type of potential subscribers beforehand. Events can be published/subscribed from both as well as components.
In the present example, we will discuss about an event published from BPEL and subscribed by Mediator component. Mediator component shall write the event information to a File on SOA Server to make sure event subscription has successfully been processed.
image
Steps to implement above example:
Step 1. Publish Event using BPEL
Create an SOA project and name it EventDeliveryExample. Select “Composite with BPEL Process” template.
image
image
Create one-way BPEL process and name it EventPublisherProcess. Use following screenshot for other parameter values.
image
Import Order.xsd into the project and select orderDetails as Input element for the BPEL process. Click OK to complete project creation.
image
image
Open composite.xml and click on “Event Definition Creation” icon from top left corner of the window as shown below.
image
Specify “OrderEventDefinition” for EDL File Name.
image
Click on “+” icon in the Events section to create a new event. Select orderDetails element for Element field. Specify “OrderPublishingEvent” for Name field. Click on OK to add event.
image
Click OK from Event Definition dialog.
image
Open EventPublisherProcess from composite.xml. From Component Palette, drag and drop an Invoke activity on to BPEL process.
image
Open Invoke_1 activity. Specify “Invoke_Event” for Name field. Select “Event” as Interaction Type. For Event, select “OrderPublishingEvent” created in the previous steps. Create a new event input variable. Click OK to close Invoke activity.
image
image
Drag and drop an Assign activity. Assign BPEL input variable to event’s input variable.
image image
This completes Event publishing part using BPEL.
Step 2: Subscribe to Event using Mediator component.
Drag and drop a Mediator component on to Components pane in composite.xml. Specify “MediatorSubscriber” as Name. Select “Subscribe to Events” Template. Select “OrderPublishingEvent” from Event section.
image
Now Mediator component has successfully subscribed to OrderPublishingEvent.
image
Lets create a File Adapter to write file to SOA Server’s File System. Drag and drop a “File Adapter” on to “External References” pane.
From Adapter Configuration Wizard, click Next. Enter “OrderWriterService” for Service Name. Click Next and Next again. From Operation dialog, select “Write File” as Operation Type. Specify “WriteOrder” as Operation Name. Click Next.
image image
Enter appropriate Directory Name for Outgoing Files. Specify File Naming Convention as “Order_%SEQ%.txt”. This ensures Order file get a serial number suffix (Example: Order_1.txt, Order_2.txt). Click Next.
image
In Messages section, click on “Define Schema For Native Format” icon next to URL field. Click Next.
image image
Leave default values in “Choose Type” screen.
image
Save following text to Order.txt file and select this file for “File name” field.
ItemName,OrderType,PurchaseDate,FirstName,LastName,AddressLine1,AddressLine2,City,State,Zip,Country
CT,EXPRESS,2011-02-01,Josh,Roy,Flat 14 Sunrise Heights,12 Martin Road,London,Greater London,EXX 5XX,UK
image
Click Next and Next again. Enter appropriate names for Target Namespace. Specify OrderCollection and Order for multiple collection and single record elements respectively. Click Next and Next.
image
From Field Properties section, select “Use the first record as the field names”. Click Next. In the final step, give an appropriate name for generated schema and Finish.
image
From Messages section, click Next and Finish.
image
In composite.xml, wire MediatorSubscriber and OrderWriterService.
image
Double click on MediatorSubcriber. In Static Routing section, click on Transformation icon next to “Transform Using” field. Select “Create New Mapper File” and leave the default name. Click OK.
image
Click on orderDetails  in <sources> and drop on to OrderCollection element in <target>. Save All.
image
Finally, Deploy EventDeliveryExample project. Launch the process by specifying values in Test screen.
image
Order_1.txt should have been created in Outgoing File Directory with the values entered in above screen. This completes the implementation.
You can download the complete JDeveloper project from here.

Lesson08-Notification Services

Downloads:
  1. Gmail IMAP SSL Certificate for  incoming mails
  2. Gmail SMTP SSL Certificate for outgoing mails
  3. Gmail Keystore containing IMAP and SMTP SSL Certificates
In order to setup Gmail notification services in SOA server, we first need to import SSL certificates. Though I’ve made them available in the Downloads section above, here are the steps to import one yourself.
OpenSSL is required to import SSL certificates from google website. If you already have one, please ignore the installation section.
OpenSSL Installation
  1. Install Visual C++ 2008 Redistributables.
  2. Install OpenSSL from here.
Import Certificates
  1. Open command prompt and go to OpenSSLHome/bin.
  2. Run following commands to create SSL certificates. Ignore any reported errors. If command hangs, press Ctrl+C to cancel. This will have no impact on certificate import.
    • openssl s_client -connect imap.gmail.com:993 > imap.cert
    • openssl s_client -connect smtp.gmail.com:465 > smtp.cert
  3. Edit imap.cert and smtp.cert to remove everything before
    • Everything before —–BEGIN CERTIFICATE—–
    • Everything after —–END CERTIFICATE—– image
  4. Import above two certificates into keystore. Enter your choice of password when prompted for a new and confirmation password. You can find keytool executable from JAVA_HOME/bin either in standalone JDK6 or JDEV_HOME/jdk160_18\bin.
    • keytool -import -alias imap.gmail.com -keystore gmailcertstore.jks -file imap.cert
    • keytool -import -alias smtp.gmail.com -keystore gmailcertstore.jks -file smtp.cert
  5. Modify setDomainEnv.cmd from WLS_HOME/user_projects/domains/<soadomain>/bin to specify truststore.
    • -Djavax.net.ssl.trustStore=<path>/gmailcertstore.jks  -Djavax.net.ssl.trustStorePassword=<password you used>
  6. Save setDomainEnv.cmd
Configure UMS (User Messaging Service)
Login to Weblogic Enterprise Manager and open Workflow Notification Properties from SOA>soa-infra>SOA Administration.
image
Set Notification Mode as Email. Enter your choice of From, Actionable and ReplyTo email addresses.
image
Click on Go to the Message Driver page. From Associated Drivers page, click on Configure Driver.
image
Modify Driver properties as follows:

MailAccessProtocol IMAP
ReceiveFolder Inbox
OutgoingMailServer smtp.gmail.com
OutgoingMailServerPort 465
OutgoingMailServerSecurity SSL
OutgoingUsername Your choice of email id. Ex: orafmwtraining@gmail.com
OutgoingPassword Password for OutgoingUsername
IncomingMailServer imap.gmail.com
IncomingMailServerPort 993
IncomingMailServerSSL select checkbox
IncomingMailIDs saileshan007@gmail.com
IncomingUserIDs saileshan007@gmail.com
IncomingUserPasswords Password for IncomingUserID
Restart SOA Server.

Lesson07-Business Activity Monitoring

What is ?
Business Activity Monitoring is a tool that is useful in monitoring business services and processes. It actively collects data, applies rules and reports information to users. When something goes wrong in business processes, BAM can be configured to take corrective measures such as emailing administrators/support team.
How does BAM interface with other SOA applications?
BAM uses Data Objects to capture and store information from other sources. It uses Real Time Data Streaming to stream data through Adapter, JMS connector, ODI or web service API.
We are going to explore the features of BAM through a simple use-case as shown below:
image
Description: Employee information is sent to BAM Example Process (). sensors sends this information through BAM Adapter to populate Employee Data Object in BAM. Employee Dashboard report will capture this information and show in the form of a 3D Bar chart.
Steps to implement use-case:
  1. Create Employee Data Object
  2. Create BAM Report
  3. Configure BAM Adapter
  4. Create BPEL Sensor Activity and Sensor Action
1. Create Employee Data Object
  • Open BAM console using http://<yourhost>:9001/OracleBAM
  • Open BAM Architect
image
  • Click on "Create Data Object" and enter "Employee" in the name field.
  • Click on "Add Field" and add following fields: id (Auto-incrementing Integer), name (String), department (String).
orafmwschool_bam05
  • Click on "Create Data Object" to finish creation. You can optionally create a sub-folder to hold Employee object.
  • Make sure Employee object is visible under Data Objects section.
image
2. Create BAM Report
  • Open Active Studio
image
  • Click on "Create a New Report".
image
  • Click on first option: Single tiled Report.
  • Enter "Employee Dashboard" for Report title and select "3D Bar Chart" as report type.
image
  • Select "Employee" object from Data Objects section at the bottom and click on Next button.
  • Select “Department” in Group By section, “id” in Chart Values and “Count” in Summary Function(s). Click on Next and then Finish button.
image
  • Save this report and it will be visible through "Recent Reports" in Home tab. This report now shows Employee count grouped by Department.
3. Configure BAM Adapter
  • Open Weblogic Server Administration Console.
  • From left side Domain Structure section, select Deployments.
image
  • Search and select "OracleBamAdapter".
  • Click on "Configuration" and "Outbound Connection Pools" from OracleBamAdapter settings page.
image
  • We can see predefined connection pools for RMI and SOAP connections. Expand both connection factory links. We need to configure these connection pools to use BAM server.
image
Important: Repeat following steps for both "eis/bam/rmi" and "eis/bam/soap".
  • Open “eis/bam/rmi” link and enter Outbound connection properties as follows. Replace connection parameters as per your installation. Hit “Enter” key after entering each property value. Click on Save once you’ve finished.
image
  • Open “eis/bam/soap” and enter connection parameters as follows. Hit “Enter” key after entering each property value. Click on Save once you’ve finished.
image
Note: The UserName field should contain an Oracle BAM user who is a member of application-level role Administrator or Report Architect. “weblogic” user by default is an Administrator.
  • Clik on OracleBamAdapter from Deployments page. Go to Control tab. Select OracleBamAdapter, click on Stop and then Start buttons. Now, Oracle BAM Adapter is ready for use.
4. Create BPEL Sensor Activity and Sensor Action
  • Create an empty Generic Project and name is BAMExample.
  • Import following employee.xsd file into BAMExample project.
  • Create one-way BPEL process and name it BAMExampleProcess. Select Employee element from Project Schema Files for Input message for the service.
image
  • Double click on BAMExampleProcess in composite.xml to open the BPEL process.
  • Click on Monitor button at the top right corner of the process window to change to Monitor view.
image
  • Right click on receiveInput activity and create sensor.
image
  • Change Evaluation Time to Completion. This will activate sensor after the completion of receiveInput activity. Select Employee element for inputVariable as shown below.
image
  • From BAMExampleProcess Structure window, right click on Sensor Actions and Creatte –> BAM Sensor Action …
image
  • Select ActivitySensor_1 for Sensor property. Choose Employee Data Object from BAM Data Object Chooser.
  • Select “Insert” as Operation type. One other interesting operation is Upsert that stands for Update/Insert. This operation creates an object if one does not exist or updates an existing one.
  • Ensure BAM Connection Factory JNDI value is “eis/bam/rmi”. We can specify “eis/bam/soap” in case BAM and BPEL servers are separated by a Firewall.
image
  • Create a new mapping between BAM data object and BPEL input variable as shown below.
image
  • Establish XPATH mapping.
image
  • Click on OK to close Sensor Action creation Dialog.
  • Right click on BAMExample bpel process and deploy to SOA Server.
Test BAMExample process
  • Go to BAMExample in Enterprise Manager and Test the process.
image
  • Enter Oracle1 and ORACLE for name and department respectively. Click on Test Web Service.
image image
  • Open BAM Active Viewer. Click on “Select Report” and choose “Employee Dashboard” report we saved earlier. We can see the updated graph. Experiment with different values.
image
Complete JDeveloper project for above use-case can be downloaded from here.

Lesson06-Fault Management

In this tutorial we will examine how to handle run time and business faults, in case of synchronous and asynchronous requests. Here is the flow chart of the use-case we’ll implement.
image
image Client sends a one-way synchronous request message through .
image If Mediator detects invalid XML message  (schema validation) runtime exception is directly returned to the client.
image Mediator sends a request to process through “queued” type routing rule. This is equivalent to starting an asynchronous process.
image BPEL exceptions (both runtime and business faults) are sent back to Mediator. These exceptions are handled as per policies defined in Fault Management Framework.
image When faults are corrected through human intervention/retry, control goes back to the component that raised the exception initially and request completes successfully.

Above flow chart describes an Address validation process. A BPEL process and Mediator are created based on an existing WSDL. High level definition of Address Validation process artefacts:
Address schema contains definitions for Address Line1, Line2, City, State, Zipcode and Country. Each of these elements have a length restriction of 16.
<xsd:element name="address" type="tAddress"/>
<xsd:complexType name="tAddress">
<xsd:sequence>
<xsd:element name="line1" type="tFixedLengthString"/>
<xsd:element name="line2" type="tFixedLengthString"/>
<xsd:element name="city" type="tFixedLengthString"/>
<xsd:element name="state" type="tFixedLengthString"/>
<xsd:element name="zip" type="tFixedLengthString"/>
<xsd:element name="country" type="tFixedLengthString"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="tFixedLengthString">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>

Address Fault is defined as follows:
<xsd:complexType name="tAddressFault">
<xsd:sequence>
<xsd:element name="code" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="desc" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

Address Validation process has one operation that includes a business fault along with request and response messages.
<wsdl:portType name="AddressValidationProcess">
<wsdl:operation name="process">
<wsdl:input message="client:AddressValidationProcessRequestMessage"/>
<wsdl:output message="client:AddressValidationProcessResponseMessage"/>
<wsdl:fault name="AddressBusinessFault" message="client:AddressValidationProcessFaultMessage"/>
</wsdl:operation>
</wsdl:portType>

Initial sanity check is performed in Mediator component. Mediator performs following checks:
1. Input XML content validation as per schema. If any of the field has more than 16 characters, ValidationError is thrown. Since it is a synchronous request, error is directly returned to the client. Do note that Schema validation happens even before any routing rule is triggered. So, Mediator inherits the transaction of the requestor.
2. Schematron Validation for post code: Post code should contain 6 to 8 characters. Otherwise, Schematron Validation error is thrown. However, since Schematron validation happens for a payload of a routing rule that is of “queued” type. This makes the Validation Error propogated to Fault Management Framework.
ORAMED-01301:[Payload custom validation]Schematron validation fails with error <ns1:ValidationErrors xmlns:ebo="http://orafmwschool.com/training/faultmanagement/xsd/AddressValidation" xmlns:ebm="http://orafmwschool.com/training/faultmanagement/ebm/AddressValidation" xmlns:ns1="http://xmlns.oracle.com/pcbpel/validationservice"> <error>Zip code should be atleast 6 characters long.</error> </ns1:ValidationErrors> Possible Fix:Fix the payload.
If these checks are successful, request is sent to BPEL process that is designed to throw two of the following exceptions:
Validation Exception: XML content validation can also be performed in BPEL through “Validation” activity. In such cases invalidVariable runtime fault is thrown. This fault is sent back to Mediator and handled through fault policy defined in fault management framework.
System Fault :
ORAMED-03303:[Unexpected exception in case execution]Unexpected exception in request response operation "process" on reference "AddressValidationProcess.AddressValidationService". Possible Fix:Check whether the reference service is properly configured and running or look at exception for analysing the reason or contact oracle support. Cause:faultName: {{http://schemas.oracle.com/bpel/extension}invalidVariables} parts: {{ summary=<summary>Failed to validate bpel variable. validation of variable inputVariable failed. The reason was: Invalid text ‘This is a long string.’ in element: ‘line1′. Pleasehandle the exception in bpel. </summary>}
This fault can be recovered.
AddressBusinessFault: When City name is London, BPEL process will throw AddressBusinessFault. This fault is declared in WSDL. Mediator will catch this exception and is automatically handled through fault management framework.
Business Fault

Error Message: Encountered a business fault(Qname – {http://orafmwschool.com/training/faultmanagement/service/AddressValidation}AddressBusinessFault).
faultName: {{http://orafmwschool.com/training/faultmanagement/service/AddressValidation}AddressBusinessFault} messageType: {{http://orafmwschool.com/training/faultmanagement/service/AddressValidation}AddressValidationProcessFaultMessage} parts: {{ payload=<AddressFault xmlns="http://orafmwschool.com/training/faultmanagement/ebm/AddressValidation"/>}
If these checks are successful, request is sent to BPEL process that is designed to throw two of the following exceptions:
Following Fault Policies are defined in fault-policies.xml:
When AddressBusinessFault occurs, request is sent for human intervention through fault management framework. This request can be accessed through Enterprise Manager.
<faultName xmlns:addr="http://orafmwschool.com/training/faultmanagement/service/AddressValidation"
           name="addr:AddressBusinessFault">
  <condition>
    <action ref="ora-human-intervention"/>
  </condition>
</faultName>
<Action id="ora-human-intervention">
  <humanIntervention/>
</Action>
When any other runtime fault occurs in BPEL or Schematron validation error,  it is mapped to MediatorFault. Fault Policy is defined to retry such requests for three times. If issue is still unresolved, it will be sent for human intervention.
<faultName xmlns:medns="http://schemas.oracle.com/mediator/faults"
           name="medns:mediatorFault">
  <condition>
    <action ref="ora-retry"/>
  </condition>
</faultName>
<Action id="ora-retry">
  <retry>
    <retryCount>3</retryCount>
    <retryInterval>5</retryInterval>
    <exponentialBackoff/>
    <retryFailureAction ref="ora-human-intervention"/>
    <retrySuccessAction ref="ora-terminate"/>
  </retry>
</Action>
For any other fault, validation error is mapped to generic fault handler and is sent for human intervention.
<faultName>
  <condition>
    <action ref="ora-terminate"/>
  </condition>
</faultName>


Here are the steps to install and test this sample:
  1. Download complete JDeveloper project from here and open FaultManagementExample.jpr
  2. Deploy FaultManagementExample project to SOA Suite 11g.
  3. Use “Test” button in Enterprise Manager to perform following tests on the composite:
Testcase 1: Schematron Validation causing Mediator Fault to be thrown.
Enter post code of either less than 6 characters or more than 8 characters. Sample payload:
<ns1:AddressValidationRequest>
<ns2:address>
<ns2:line1>TEST</ns2:line1>
<ns2:line2>TEST</ns2:line2>
<ns2:city>TEST</ns2:city>
<ns2:state>TEST</ns2:state>
<ns2:zip>E10</ns2:zip>
<ns2:country>TEST</ns2:country>
</ns2:address>
</ns1:AddressValidationRequest>

A Mediator Fault will be thrown and Fault Management framework retries the process three times, before sending for human intervention. You can see that the process status as “Recovery Needed”.
Testcase 2: Invalid XML document – Input String more than 16 characters.
Give a value of more than 16 characters for “line1” element. Sample payload:
<ns1:AddressValidationRequest>
<ns2:address>
<ns2:line1>This is a long string.</ns2:line1>
<ns2:line2>Address Line2</ns2:line2>
<ns2:city>City</ns2:city>
<ns2:state>State</ns2:state>
<ns2:zip>E10 5QS</ns2:zip>
<ns2:country>UK</ns2:country>
</ns2:address>
</ns1:AddressValidationRequest>
BPEL throws invalidVariables fault that will be sent to Mediator. Mediator maps it to MediatorFault. As per policy, Fault Management framework retries this process three times, before sending for human intervention. You can see that the process status as “Recovery Needed”.
Testcase 3: AddressBusinessFault – Specify London as city name.
BPEL process is designed to perform a check for city name. If city is “London” then BPEL thrown a business fault: AddressBusinessFault that will be caught by Mediator. Since this fault is already declared in WSDL, Mediator will not map it to MediatorFault.
As per the fault policy defined, this request will be sent for human intervention and can be accessed through Enterprise Manager.
Sample payload:
<ns1:AddressValidationRequest>
<ns2:address>
<ns2:line1>test</ns2:line1>
<ns2:line2>test</ns2:line2>
<ns2:city>London</ns2:city>
<ns2:state>test</ns2:state>
<ns2:zip>E10 5QS</ns2:zip>
<ns2:country>UK</ns2:country>
</ns2:address>
</ns1:AddressValidationRequest>

Hope this sample was useful in understanding Fault Management in SOA Suite 11g.

Lesson05-Mediator Error Hospital

One of the powerful features in Oracle SOA Suite is out-of-the-box Error Hospital. In order to use this feature, component should have parallel routing rules. Each parallel routing starts a new transaction and can be independently controlled through EM console.
Please refer to Human Workflow Example to understand this lesson better.
MyBay synchronizes its items with MyDel’s datastore at frequent intervals. MyDel expects items from all received Orders to be present in its datastore before further processing. However, due to synchronization issues, sometimes MyBay order items are not found in MyDel’s datastore. In such cases, instead of discarding the entire batch of orders, MyDel needs to selectively retry failed orders after rectifying the issues.
In the present lesson, lets see how Error Hospital can come to rescue. We will first run Human Workflow Example with incorrect values and see how transaction fails. Then, we will  make slight change to the Mediator to see how the failed transaction can be retried.
Lets create an entry in Orders.txt file with an item that doesn’t exist in ITEMS table. In my case, ITEMS table contains two items with IDs 1 and 2.
orafmwschool_hwflow82
Lets create an order entry in Order.txt with ItemId 3.
orafmwschool_hwflow81
When Order.txt is placed in file poller directory, as expected, transaction fails.
orafmwschool_hwflow83
Click on Instance ID to go to process Flow Trace. We can see the transaction has failed because of Foreign Constraint violation.
orafmwschool_hwflow84
We can’t retry this transaction. Lets slightly modify Order Router mediator to change this behaviour.
Open OrderRouter from composite.xml and go to Routing Rules section. Observe the both routing rules we defined earlier are “sequential” type. Change them to “parallel”. Click OK for any information dialogs you get in the process.
orafmwschool_hwflow79
orafmwschool_hwflow85
Redeploy the composite and copy same Order.txt file to the poller directory. Go the EM Dashboard and see deployed process instance. We can that it is in “Recovery Needed” state.
orafmwschool_hwflow87
We can see the process instance is in “Recovery Needed” state instead of “Faulted”. Click on “Recover …” link at the bottom of the page as shown above.
orafmwschool_hwflow88
Fault Trace shows the details of recoverable error. Click on error message to see error details. Below error message, we can see editable payload with an option to either Retry or Abort the transaction.
orafmwschool_hwflow89
Change Item ID to 1 and Retry the transaction.
orafmwschool_hwflow91
Go back to the Process Dashboard and click on Instance ID again to go to Flow Trace. We can see the transaction is successfully completed.
orafmwschool_hwflow92
Though it solves bulk of our requirements, we may still want to refine fault handling by fault category. We also may want to extend fault handling to BPEL processes. In such cases, we can make use of Fault Management Framework.
Next lesson, to be published very soon, will show usage of Fault Management Framework through simple example. Stay tuned…

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...