Showing posts with label BPEL. Show all posts
Showing posts with label BPEL. Show all posts

Thursday, April 25, 2013

Examples of Date and Time Formatting

Example: Gregorian Calendar
The following examples show a selection of dates and times and the way they might be formatted. These examples assume the use of the Gregorian calendar as the default calendar.

Required Output
Expression
2002-12-31
format-date($d, "[Y0001]-[M01]-[D01]")
12-31-2002
format-date($d, "[M]-[D]-[Y]")
31-12-2002
format-date($d, "[D]-[M]-[Y]")
31 XII 2002
format-date($d, "[D1] [MI] [Y]")
31st December, 2002
format-date($d, "[D1o] [MNn], [Y]", "en", (), ())
31 DEC 2002
format-date($d, "[D01] [MN,*-3] [Y0001]", "en", (), ())
December 31, 2002
format-date($d, "[MNn] [D], [Y]", "en", (), ())
31 Dezember, 2002
format-date($d, "[D] [MNn], [Y]", "de", (), ())
Tisdag 31 December 2002
format-date($d, "[FNn] [D] [MNn] [Y]", "sv", (), ())
[2002-12-31]
format-date($d, "[[[Y0001]-[M01]-[D01]]]")
Two Thousand and Three
format-date($d, "[YWw]", "en", (), ())
einunddreißigste Dezember
format-date($d, "[Dwo] [MNn]", "de", (), ())
3:58 PM
format-time($t, "[h]:[m01] [PN]", "en", (), ())
3:58:45 pm
format-time($t, "[h]:[m01]:[s01] [Pn]", "en", (), ())
3:58:45 PM PDT
format-time($t, "[h]:[m01]:[s01] [PN] [ZN,*-3]", "en", (), ())
3:58:45 o'clock PM PDT
format-time($t, "[h]:[m01]:[s01] o'clock [PN] [ZN,*-3]", "en")
15:58
format-time($t,"[H01]:[m01]")
15:58:45.762
format-time($t,"[H01]:[m01]:[s01].[f001]")
15:58:45 GMT+02:00
format-time($t,"[H01]:[m01]:[s01] [z]", "en", (), ())
15.58 Uhr GMT+02:00
format-time($t,"[H01]:[m01] Uhr [z]", "de", (), ())
3.58pm on Tuesday, 31st December
format-dateTime($dt, "[h].[m01][Pn] on [FNn], [D1o] [MNn]")
12/31/2002 at 15:58:45
format-dateTime($dt, "[M01]/[D01]/[Y0001] at [H01]:[m01]:[s01]")

Example: Non-Gregorian Calendars
The following examples use calendars other than the Gregorian calendar.
These examples use non-Latin characters which might not display correctly in all browsers, depending on the system configuration.
Description
Request
Result
Islamic
format-date($d, "[D١] [Mn] [Y١]", "Islamic", "ar", "AH", ())
٢٦ ﺸﻭّﺍﻝ ١٤٢٣
Jewish (with Western numbering)
format-date($d, "[D] [Mn] [Y]", "he", "AM", ())
‏26 טבת 5763
Jewish (with traditional numbering)
format-date($d, "[Dאt] [Mn] [Yאt]", "he", "AM", ())
כ״ו טבת תשס״ג
Julian (Old Style)
format-date($d, "[D] [MNn] [Y]", "en", "OS", ())
18 December 2002
Thai
format-date($d, "[D๑] [Mn] [Y๑]", "th", "BE", ())
๓๑ ธันวาคม ๒๕๔๕

########

Friday, December 14, 2012

DB Adapter Message Throttling in Oracle SOA 11g

DB throttling is the mechanism to control the number of database records processed by the SOA engine in a particular interval through DB Adapter. 
Throttling also can be used to control the number of records send to the end systems. If the throttling is not defined, the end systems may flood with number of messages that will affect the functioning of the end systems. Throttling parameters should be configured based on the end systems capacity to process the incoming messages.
Until Oracle SOA 11.1.1.6.0 the message throttling will not work as we expect, all the messages matching the where condition of the polling sql are processed in the same polling interval.
As of Oracle Adapters release 11.1.1.6.0 we can set the inbound DBAdapter property RowsPerPollingInterval to control the throttling. It acts as a limit on the number of records which can be processed in one polling interval. The default value is unlimited.
The Patch 12881289 should be applied to enable this for SOA 11.1.1.5.0 and earlier versions.
The maximum rows processed per second are:
Number of active nodes in SOA cluster x NumberOfThreads x RowsPerPollingInterval / PollingInterval
MaxTransactionSize can be thought of as RowsPerDatabaseTransaction or DatabaseFetchSize that is how many records will be fetched to DB Adapter engine from the database for each transaction. It does not affect how many rows can be processed in one polling interval period.
The one exception is the following configuration:
-distributed polling checked, usesSkipLocking="false"


In this one case RowsPerPollingInterval will default to MaxTransactionSize instead of unlimited in case of RowsPerPollingInterval property is not specified in the jca file.
If RowsPerPollingInterval is set to lower than MaxTransactionSize or MaxRaiseSize, they will be effectively lowered to RowsPerPollingInterval that means the value RowsPerPollingInterval will considered for MaxTransactionSize and MaxRaiseSize.
There is no UI support to add the RowsPerPollingInterval property. We have to add the property manually to the db.jca file for the inbound polling service. Add it to the same section as the properties MaxRaiseSize, MaxTransactionSize, and PollingInterval, in any order.

########

Friday, May 11, 2012

Oracle Fusion Middleware 11g (ofm11g) on Centos 5

Because of a little illness Lucas was a bit faster with the publish of his article :) but i decided to still post it on my blog.
In the new Fusion 11g, Oracle added a new extension to the bpel language for the coordination of master- and detail processes.
With this add on it is possible to relate a master process with his detail processes and give signals to each other when to start and when parts are finished.

Let’s start with building something
We created a new composite application and added 3 bpel processes to it.
The first process is the master process and this one will invoke 2 detail processes.
The idea is to let both detail process only get started when they receive a ‘signal’ from the master processes. If they receive it,
they’ll execute their own logic and when either finished or at some point they want to communicate back to the master process, they give a ‘signal’ back.
In the master process, after the the receive add the first signal

1<bpelx:signal name="doDetail1" label="doDetail1" to="details"/>
This will give the first detail process a signal so it will be able to receive
Now we need to invoke the first detail process
1<invoke name="invokeDetail"
2        inputVariable="invokeDetail_process_InputVariable"
3        partnerLink="MyDetail.mydetail_client" portType="ns1:MyDetail"
4        operation="process"
5        bpelx:detailLabel="detailProcessComplete1"
6        bpelx:invokeAsDetail="true">
Two things in here are needed. The first is the bpelx:invokeAsDetail=”true” and the second is the bpelx:detailLabel=”detailProcessComplete1″
The last property is used in cases in which we have multiple detail processes and the signals need to get correlated back with the master process.
Now lets see what is needed in the first detail process to receive the signal and eventually send one back to the master process.
The first activity after the receive is the receive signal
1<bpelx:receiveSignal name="WaitOnSignalFromMaster"
2                     label="doDetail1" from="master"/>
This will receive the signal from its master process and after that will carry on. Without the signal the detail process won’t get started. So you will only be able to trigger this detail/sub process from it’s master process.
After receiving the signal the detail process can execute some logic and eventually send back the signal to the master process
1<bpelx:signal name="ReplyBackToMaster"
2              label="detailProcessComplete1" to="master"/>
In the master process we use the receiveSignal activity to receive it back from the detail process and go on with the process.
1<bpelx:receiveSignal name="waitForDetailProcess1"
2                     label="detailProcessComplete1" from="details"/>
The same code is needed to invoke the second detail process. It’s up to you to decide wether or not the second detail process can run parallel to the first one.
If this is not the case we need to wait on the receiveSignal from the first detail process before we can start the second one.

If both processes can execute their logic and eventually send the signal back we can also receive both signals on the end of the master process. If both signals are receive we can do the callback because the whole process (master and all his details have been completed).
And in this case we can invoke the detail processes like oneway processes, but still inform the master process about the state of all these oneway (long running?) processes. At the end aggregate all the signals and do the callback or some other activity which is needed as soon all the detail processes reported back.

Testcase1
What will happen if we remove one of the receiveSignals from the Master process.

the master process will wait on the receivesignal activity until it receveid it.
Testcase2
What will happen when we do not send the signal from the master process to the detail process but leave the receiveSignal in the detail process.


The master process will wait on the receiveSignal from detail process1. Since the invoke of the both detail processes are oneway and we do the ‘check’ on the receiveSignals at the end, detail process1 will just complete and send the signal back to the master process. After this the master process will keep on waiting on the signal from detail process1.
Testcase3, when all just works




Eventually the flow of the master process can look like this.
In here i placed the receiveSignals to the end of the process. You can also place them after the invokes of the detail processes, so you’re sure they will wait on each other.

########

Oracle BPEL Fault Policy Framework handling custom business faults

From the Oracle forum and from the comments on my article about Oracle BPEL Fault Policy Management i get a lot of questions about how to let the framework handle my own custom defined ‘business faults’.
In certain situations the default set of faults defined by Oracle aren’t suited enough and you need to define your own faults.
If we look into the examples which got supplied by Oracle we can see an example over here. In this example they defined their own NegativeCredit-fault.
The Oracle BPEL Fault Policy Framework by default only handles the faults which are getting returned on an invoke-activity.
So we have our own custom fault and the knowledge we can only let this fault getting catched by the framework by use of an invoke.
So we need atleast for this testscenario 2 bpel processes. One mainprocess which calls a subprocess, and this subprocess will throw the custom business fault.
This fault will get propogated back to the mainprocess and in here we will be able to let the framework handle the fault.
bpel-invoke
BPEL Processes
Mainprocess
mainprocess
Subprocess
subprocess
Just a simple invoke of the subprocess from the mainprocess. The subprocess with throw a fault, and this fault will be catched in the mainprocess.
throwThe fault to be thrown
From the console start the mainprocess and wait till it comes back with a fault messageinvoke-faultedClick the activity to see the thrown fault
01[2009/02/13 16:24:41]
02"{http://nl.iteye/integration/faults/business}BusinessFault" has been thrown.
03 
04<BusinessFault xmlns="http://nl.iteye/integration/faults/business">
05<part name="payload">
06    <BusinessFault xmlns="http://nl.iteye/integration/faults/business">
07      <FaultCode>999</FaultCode>
08      <FaultMessage>Something went wrong!</FaultMessage>
09    </BusinessFault>
10  </part>
11</BusinessFault>
Ok nice!
So the custom fault we defined in the subprocess reaches the mainprocess.
Now we need to config the fault policy framework so it will get active on our custom business fault.
From the fault we pasted above we need the faultname (BusinessFault) and the namespace (http://nl.iteye/integration/faults/business).
Edit /bpel/domains/default/config/fault-policies/DefaultPolicy.xml and add the next fault :
1<faultName xmlns:flt="http://nl.iteye/integration/faults/business" name="flt:BusinessFault">
2         <condition>
3                 <action ref="ora-human-intervention"/>
4         </condition>
5</faultName>
For testing we will just let this fault getting handled by human-intervention.
Now restart the components
opmnctl stopall
opmnctl startall
Now start the mainprocess again and wait till it fails.
invoke-faulted-frameworkIt looks like the framework got active (activity yellow marked) on our custom business fault.
invoke-faulted-audit
Go to the activities-tab
list-activities
And click the activity which faulted.
edit-activity
Now we can edit some of the values and let the subprocess get re-invoked.
So, at this moment we’re able to throw our custom business faults and let them getting catched by the framework. Since the fault is only getting catched on the invoke of a partnerlink, we aren’t able to let our custom business fault getting throwned to the process in which we maybe want do something with the data for which we actually throwed the custom business fault. So maybe we want to stay in the subprocess and somehow get the custome business fault thrown inhere, let the framework catch it and update the values of this subprocess with new values an re-execute the subprocess.
The next solution will get this done.
The mainprocess won’t get changed but in the subprocess we will invoke a new process called AllBusinessFaults.
New subprocess 2
subprocess2
AllBusinessFaults
all-business-faults
The AllBusinessFaults will throw the custom business fault we ‘request’ back on the invoke in this subprocess. Now it wil get catched by the framework and we will be able to change the values of the subprocess instead of the mainprocess.
list-activities2
By using the AllBusinessFaults bpel service like a sort of composite service, we can add the custom business faults in it and throw the one we would like to get thrown. This will work if the collection of custom business faults isn’t that big. I’m sure there will be better solutions for this, but for the scenario i wanted to describe inhere it was good enough for me.

########

Getting started with Oracle SCA, SOA, BPEL, OSB, AIA

As I do SOA projects for a few years, many users are just entering this service oriented architecture world. For me the technology is common sense and I expect often that Service Oriented Arcitecture (SOA), Business Process Execution Language (BPEL), Enterprise Service Bus (ESB) is well known. But off-course this is not the case. When I started working with SOA/BPEL/ESB it was, and still is, a steep learning curve. The Oracle developers world comes from a traditional approach; thinking in functions and entities and since Java came to us, we are even thinking about objects and inherited them.
With SOA it is different, you have to think about processes; functional and technical. The gap between the functional people and technical people is reduced. Processes are part of the business, otherwise they do not have any reason for existence. While processes are running, the can fail, wait on other process, they finish, started, run in parallel etc. So SOA is a mind shift from the traditional development approach point of view.
In July 2009 the major milestone was reached, release 11g is out. This release has technically a new foundation; the Oracle WebLogic server; running on Java 1.6; new enterprise manager console for all FMW components and last but not least the service component architecture (SCA)
In 2008 Oracle announced the Oracle Application Integration Architecture. This is an add-on on the Oracle SOA Suite, which defines an abstract message layer that can be used to interface various systems; Siebel / SAP / Protal BRM / Cordys via a centralized system (Oracle SOA + AIA). This messages layers are created specific for different industries, for example the telecommunication market.

To start with Oracle SOA here are some of useful links:

Oracle SOA Suite general

Oracle SOA Suite software

Oracle Application Integration Architecture Documentation
Installation
Performance
API Tutorials Oracle Blogs Oracle Forum Oracle General
Useful tools Webservice standards

########

Oracle BPEL 11g - Correlation Sets

Correlation Sets is as set of configurations that allow the process to receive messages during its execution even if the invoker doesn't have the Correlation ID necessary to indicate to the engine to which instance the message needs to be delivered. With Correlation Sets a group of business data can be used to inform the engine how to match the message received with the correct instance that is already in execution.

To understand correlation sets is necessary to know some main concepts:
  • Property: like a variable, a property stores the information that will be used to match when a new message arrives.
  • Property Alias: is used in two situations - as a assign, to define what information needs to be stored in the property, and as a query, to match the information received in a message with the information stored in the property.
Itens below is a step-by-step showing how to configure Correlation Sets:

1 - Create a new operation in the process interface, allowing it to receive a message during process execution
  • Open the WSDL that describes BPEL service interface. Find messages and operations already defined.
  • Create a new message and a new operation in the inbound PortType that uses the message created. You can use some data type already defined, define a new data type at the XSD file already imported by the WSDL or import any XSD to use a data type defined externally.
  • Verify that the new operation is available at the process interface.

2 - Change the process to use the new operation during the process execution
  • Open the BPEL process and add a new Receive activity in the middle of process execution. Before and after this Receive you may have as many activities as necessary. Point the new activity to the PartnerLink that represents the process interface.
  • Select the operation defined previously on WSDL and create a new variable to store the message that will be received.

3 - Create and initialize the Correlation Set with business value that will be used to match the message that will be received
  • Open the Receive activity that starts the process. Select the "Correlation" tab and click on "Create" button. Important: to initialize the Correlation Set you could use any Invoke or Receive activity before the Receive activity you will receive the message that you want to match.
  • Define Correlation Set name and click on "Add" button.
  • Choose the "input" field from "InputVariable". Click on "+" button right to "Property" field and define the name of the property that will store the input field value.
  • Click "OK" once to confirm Property creation, again to confirm Property Alias creation and one more time to confirm Correlation Set creation. Change "Initiate" field to "yes". This will indicate to the engine that you want to initilize the Property with the field content defined by the XPath expression of the Property Alias.

4 - Match the incoming message
  • Open the Receive activity that will receive the intermediate message. Select the "Correlation" tab and click on "Add" button.
  • Select the Correlation Set previously created and click on "OK".
  • Select the Correlation Set added and click on "Edit" button.
  • Select the Property of the Correlation Set an click again on "Edit" button.
  • Choose the "input" field from Intermediate Receive's variable and click "OK". Then, click "OK" again to confirm the Correlation Set change. This will create a new Property Alias that matches intermediate message value received with the value stored in the Property initialized previously.
  • This time, leave the "Initiate" field as default ("no"), because we don't want to change the property value. We just want to match its value with the value received by the Intermediate operation message.

With this configuration, BPEL engine can match business value stored in the property (initialized in the first Receive activity) with the the message value received by the Intermediate Operation and deliver the message for the correct running instance.


To download this sample, click here.

########

BPEL - Correlation, fault handling, and compensation

The previous entries have covered the fundamentals of BPEL, providing an understanding of the activities defined and how they can be combined together using structured activities and the <link> construct. In this entry, the advanced properties of the language that are essential to the definition and execution of a business process are covered. BPEL uses correlation to match returning or known customers with a long-running business process, fault handling to recover from expected as well as unexpected faults, and compensation to "undo" already committed steps in case something goes wrong in the middle of the process or, for example, a client wishes to explicitly cancel a transaction.
Introduction
Now that I've covered the fundamental concepts of BPEL in the previous entries, it is time to dive into some of the more advanced topics. This entrt will provide you with an overview of message correlation, fault handling, and compensation as it applies to a BPEL environment.
Message correlation
Message correlation is the BPEL mechanism which allows processes to participate in stateful conversations. It can be used, for example, to match returning or known customers to long-running business processes. When a message arrives for a Web service which has been implemented using BPEL, that message must be delivered somewhere -- either to a new or an existing instance of the process. The task of determining to which conversation a message belongs, in BPEL's case the task of locating/instantiating the instance, is what message correlation is all about.
In many distributed object systems, one component of the routing of a message involves examining the message for an explicit instance ID which identifies the destination. Although the routing process is similar, BPEL instances are not identified by an explicit instance field, but are instead identified by one or more sets of key data fields within the exchanged messages. For example, an order number may be used to identify a particular instance of a process within an order fulfillment system. In BPEL terms, these collections of data fields which identify the process instance are known as correlation sets.
Each BPEL correlation set has a name associated with it, and is composed of WSDL-defined properties. A property is a named, typed data element which is defined within a WSDL document, and whose value is extracted from an instance of a WSDL message by applying a message-specific XPath expression. In WSDL, a propertyAlias defines each such mapping. The mappings are message specific, hence a single property can have multiple propertyAliases associated with it. For example, a WSDL document might say that property name corresponds to part username of WSDL message loginmsg and to part lastname of ordermsg. Together, the properties and propertyAliases provide BPEL authors with a way to reference a single, logical piece of information in a consistent way, even if it might appear in different forms across a set of messages.
Using correlation sets
To use a correlation set, a BPEL author defines the set by enumerating the properties which comprise it, and then references that set from receive, reply, invoke, or pick activities. A BPEL runtime uses the definition and references to determine the interesting pieces of information that it should examine during different points of executing the process. Each instance of the process has an instantiation of each of the correlation sets which are defined for the process. Each of these instantiations is initialized exactly once during the execution of the process instance, and is subsequently only used during comparisons involving incoming and outgoing messages. If an attempt is made to reinitialize a correlation set, or to use one which has not been initialized, then the runtime will throw a bpws:correlationViolation. Extracting values for a correlation set referenced by an activity, either for initialization or comparison purposes, involves applying the processAlias, which corresponds to the particular WSDL message being examined, for each of the properties which comprise the referenced correlation set.
As receive and pick activities provide the entry points into a process, correlation sets often appear on them to enable message-to-instance routing. If a correlation set appears on a receive or pick activity, and it does not have the initiation attribute set to 'yes', then when a message arrives for that particular receive or pick, the values of the properties which comprise the correlation set are extracted from the incoming message and compared to the values stored for the same correlation set in all of the instances of that process, and the message is routed to the instance which has matching values. Similarly, correlation sets on reply and invoke activities, which deal with outbound operations, are often used to validate that outgoing messages contain data which is consistent with the data contained within specified correlation set instances. For example, if a correlation set appears on a reply activity, and it does not have the initiation attribute set to 'yes', then the values of the properties which comprise the correlation set are extracted from the outgoing message and compared to the values store for the instance's instantiated correlation set. If the values in the message which correspond to the correlation set are found to be different from those contained within the instance's correlation set, the runtime throws a bpws:correlationViolation. On all of the activities on which correlation sets may appear, the initiation attribute indicates to the runtime that the correlation set should be initialized using the values contained within the message which is input to the current activity. Correlation sets which appear within invoke activities have an additional attribute, pattern, which specifies during the execution of the invoke activity the correlation set that is to be applied. The pattern attribute may have a value of 'in', meaning that the correlation set is to be applied when the response comes back for the invocation, 'out', meaning that the correlation set is to be applied when the invocation is made, or 'both', which naturally means that it is to be applied during both phases.
Multiple correlation sets, some of which are initialized and some of which are used for comparison, can appear on a single activity. The current BPEL specification does not define the semantics of locating an instance based on multiple correlation sets.
Error handling and roll-back
When executing a BPEL process, errors might occur either in the services being invoked or within the process itself. BPEL provides a mechanism to explicitly catch such errors and handle them by executing subroutines specified in fault handler elements. Additionally, activities that have completed might later need to be undone because they form part of a longer transaction that had to be aborted. Compensation handlers allow the creator of the process to define certain actions that should be taken to undo a unit of work and restore the data to what it was before that work was done.
The handling of such situations usually affects a set of activities that are associated with each other. In BPEL, this is done by enclosing them in the scope structured activity. A scope provides the context for the activities nested within it, and it is where fault and compensation handlers are defined. Therefore, you can think of the scope as encapsulating a possibly compensatable, recoverable unit of work.
The entire process provides the global scope: it contains one main activity and allows the specification of fault and compensation handlers. It is also able to define data containers and correlation sets. However, the future directions of BPEL state that all scopes will be able to do the same, and that containers defined in a scope will be visible only to activities nested within that scope.
In order to understand how a scope catches or propagates a fault that originated within it, I will first recap the life cycle of a BPEL activity. An activity remains dormant, waiting to be activated by its parent activity and its incoming links. Once it gets control from its parent, and all its incoming links come in, it can evaluate its join condition at which point one of two things can happen: it either throws a joinFailure fault because the join condition was not satisfied, or it runs. Assuming the latter, after it has run successfully, it ends by evaluating and firing all its outgoing links.
On the other hand, the activity might fault while it is running because it was an invocation that returned a fault, one of the built-in BPEL faults occurred while it was executing, or because it is a throw activity. In this case, it notifies the scope it belongs to. Upon receiving a fault, the scope must stop all its nested activities. One other reason can cause an activity not to run successfully; it might never receive all its links or control from its parent. For example, this will happen to an activity in the same scope as the one that faulted but that was slated to run later on, or to an activity that is a branch of a switch statement that was never taken. In both of these cases where an activity cannot successfully run and complete, it needs to send out all its outgoing links with a negative value.
Handling faults
BPEL includes the ability to catch and handle errors at different levels of activity nesting. A fault handler can be defined on any scope and either bound to a particular kind of fault (defined by the fault's qualified name, or its message type) or to any faults not caught by a more specific handler. A handler simply contains an activity that will run in case an error occurs. For example, it might contain a reply activity that notifies a partner that an error has occurred.
As noted earlier, the first thing a scope does once it receives a fault is to stop all its nested activities. In the default case, the scope stops its activities, and then rethrows the fault to its parent and so on until the top-level process is reached. When a scope rethrows the fault, the scope itself then ends abnormally, and it sends out all its outgoing links with a negative value. However, handlers allow any scope to intercept a fault and take appropriate action. Once a fault is handled in a scope, the scope ends normally with the values of its outgoing links being evaluated as usual. This is illustrated in Figure 1.
Figure 1. Handling faults

In this figure, the activity faults because one of its links came in with a negative value and its join condition is a boolean and of the link values. It therefore throws the fault to its scope, and you see all the links leaving it go negative. The scope itself has no handler for the fault, so it rethrows the fault. The next scope up is the process itself. You see the links of the inner scope get negative values because it could not take care of the problem itself and so terminated abnormally. The process has a handler, takes care of the fault, and completes normally. It follows that if the handler had been on the inner scope, the links leaving it would have been evaluated regularly, and the fault would not have been thrown to the process.
The invoke activity exhibits a short-cut mechanism for defining handlers directly on its definition. The behavior is effectively that it becomes wrapped in a scope that will have these specified handlers.
BPEL defines a set of built-in faults that notify of errors such as assignment type mismatches, a scope forcing the termination of a nested scope, and activating a reply activity that doesn't have a matching receive activity. The BPEL engine is responsible for detecting these faults and throwing them to the appropriate scope.
Compensation
While a business process is running, it might be necessary to undo one of the steps that have already been successfully completed. The specification of these undo steps are defined using compensation handlers that can be defined at the scope level. Each handler contains one activity which is run when a scope needs to be compensated.
The activities within such a handler must see the container data to be that which it was when the scope completed. Due to activities sharing containers and loops caused by while activities, completing scopes that are compensation-enabled must save a snapshot of the data for the handler to possibly use later.
Once a scope completes successfully, its compensation handler becomes ready to run. This can happen in either of two cases: explicit or implicit compensation. Explicit compensation occurs upon the execution of a compensate activity. This activity may occur anywhere, and refers to the name of the scope that it wants compensated. Scopes that might be rolled back in this manner must therefore be named. BPEL further specifies that names of scopes must be unique within a BPEL process. When a compensate activity is reached, it runs the compensation handler on the specified scope.
On the other hand, implicit compensation occurs when faults are being handled and propagated. Consider the scenario in which a scope A contains a compensatable scope B that has completed normally, but then another nested activity in A throws a fault. Implicit compensation ensures that whatever happened in scope B gets undone by running its compensation handler. Therefore, implicit compensation of a scope goes through all its nested scopes and runs their compensation handlers in reverse order of completion of those scopes.

########

SOA ,OSB,REST and Middleware Related Stuff

Basic Fault Handling in SOA 11g

In this post, I am going to illustrate the basics of fault handling in Oracle SOA 11g.For the sake of illustration, I am going to create a a sample application.So , let's get started.

In Oracle SOA 11g, faults can be categorized broadly into two categories:- System Faults and Custom Faults.So, let us get started to see how it works.In this first example, we are going to see how faults are propagated.

First,open JDev and create a new SOA Application and a SOA project, select empty composite template.Now drag and drop a  BPEL process onto your composite application.Name it FaultHandlerBPEL and choose synchronous template;leave the default input and output and make sure the "Expose as SOAP service" check box is checked.


 Hit ok once you are done.In the FaultHandlerBPEL process, we are going to handle the faults.Drag another BPEL process.Name it FaultThrowerBPEL.Like before, choose synchronous template and accept the default input and output.However, do not expose this BPEL process .i.e. the check box "Expose as SOAP service" should be unchecked.


As the name implies, the FaultThrowerBPEL process throws a fault Now wire the FaultHandlerBPEL to the FaultThrowerBPEL process.Your composite should look like the following image:-



Now, double click on the FaultThrowerBPEL process to open the BPEL process editor.Now,drag a Throw activity between the receive and reply activity.Name the activity ThrowFault.






Now double click on the Throw activity.A window will pop up.Click on the magnifying glass as shown in the image below to select the fault.



In the fault chooser window, expand the System Faults node and select remoteFault.Hit ok once you are done.



This will bring you back to the previous window.Now click on the green plus sign to add a fault variable as shown in the image below:-


Accept the default name and scope in the variable creation window.Hit Ok twice to come back to the BPEL process.


So in the previous steps, what we have done is we have created a throw activity which throws a remoteFault.While throwing the fault, we have also specified a fault variable.Using the throw activity, we can throw system faults and custom faults.However, the custom faults are discussed later.So, if you are familiar with java, up to now we have written something like this:-

     throw new Exception();

Notice that, once we create a fault variable, a new WSDL file is added to our project.The name of the WSDL file is RuntimeFault.wsdl.The wsdl file is a simple one which contains a message on which the fault variable is based on.It is important to mention here that in SOA 11g, the fault variables must be WSDL message based,be that a custom fault variable or a system fault variable.

Now, drag and drop an Assign activity just before the Throw activity.Name it AssignFaultDetails.The BPEL file should look like the following image:-


Now double click on the assign activity.Add a copy operation.



Choose expression on the from side and enter the string '007'.On the to side,expand the FaultVar node and select the code  part.


Hit Ok once you are done.Now,add another copy operation.On the from side, select expression and enter the string 'My Fault Summary'.On the to side, expand the FaultVar node and select the summary part
.

Add another copy operation.Like before, on the from side select expression and enter the string 'My Fault Details'.On the two side, expand the FaultVar node and select detail node.Hit Ok twice to complete the Assign activity.

So the assign activity populates the fault variable with some dummy data before the fault is thrown. This completes our FaultThrowerBPEL process.

Next open the composite.xml and double click on the FaultHandlerBPEL to open the BPEL editor.Next, drag and drop an Invoke activity onto the BPEL process between the Receive and Reply activity.Double click on the invoke activity.Enter the name InvokeFaultThrower.Next click on the magnifying glass beside the Partner  Link as indicated in the following image:-





The partner link chooser dialog opens.Select the FaultThrowerBPEL.faultthrowerbpel_client partner link and hit ok.




Back in the invoke dialog, create input and output variables.Choose the default name.Your BPEL process should look like the following image.


Add an Assign activity before the invoke activity.Name it initialize variable.Create a copy operation as shown in the follwing image:-
Hit Ok twice to come back to the BPEL process.Add another activity after the Invoke activity and before the Reply activity.Call it IntializeOutput.Create a new copy operation as shown in the following image:-


Hit Ok twice to come back to the BPEL process.Now click on the validate icon on the upper left corner of the BPEL process as shown on the image below:-


All the warning signs from the BPEL process should disappear now.If you test the process now and invoke the FaultHandlerBPEL, when executing the invoke activity InvokeFaultThrower, a fault is going to be thrown.This is because the FaultThrowerBPEL is going to be invoked which is going to throw a remoteFault.As we do not have any catch or catchAll activity in the FaultThrowerBPEL, the fault is going to be propagated to the FaultHandlerBPEL.

Now add a catch all branch.To do this, click on the add catch all branch icon as indicated in the image below:-




A new catch all branch is going to be added to the BPEL process.Expand the catch all activity and drag and drop an Assign activity under the catchAll activity and name it PopulateOutput.The BPEL process should now look like the following image:-





Double click to open the Assign activity and add a copy operation.On the from side select, expression,open the expression builder and enter expression:-

concat(ora:getFaultName(),'::',ora:getFaultAsString())

On the to side, select the result element as shown in the image below:-



The function ora:getFaultName() returns the fault name i.e. remoteFault in this case.The function ora:getFaultAsString() returns the details of the fault which contains all the parts i.e. code, summary and detail.Next drag and drop a Reply activity under the catchAll branch just below the PopulateOutput Asign activity.Your BPEL process should look like the following image:-





Double click to open the Reply activity.Enter replyOutput as the name.Now select the partner link as before.In the partner link chooser, select the faulthandlerbpel_client partner link.Hit ok to comeback to the previous window.


Now click on the magnifying glass beside the Variable chooser as shown in the image below:-








In the variable chooser, choose the output variable.


Hit Ok twice to complete the Reply activity.In the previous steps, we created a catch all branch synonymous to java "catch(Exception e){}".Now,inside the catch all, we have implemented an Assign activity which update the output variable with the details of the fault and a Reply activity which replies to the calling process.

Now deploy and test the service from the EM console.A fault is going to be returned when you invoke the ErrorHandlerBPEL from the EM console.


Returning a fault from a synchronous BPEL process:-

Now we are going to see how we can return a fault from a synchronous BPEL process.To do this, open the FaultThrower BPEL process. Next add a catch branch by clicking on the add catch branch as indicated in the image below:-


Now double click on the catch branch that is created .Now we are going to choose the fault that we intend to catch which is, in this case, a remoteFault.Click on the magnifying glass icon as indicated in the image below to bring up the fault chooser window.

 


In the fault chooser window, select remoteFault.Hit Ok once you are done.



 Next click on the magnifying glass icon as indicated in the image below to select a fault variable.Here, we are going to reuse the same variable that we created while throwing the fault.Alternatively, you can create a new fault variable by clicking on the green plus icon.In this case, the fault variable is going to be automatically populated when the fault is caught.
.


Next, choose the FaultVar and hit Ok once you are done.Hit Ok again to complete the catch activity.So in java syntax, we have written something like this:-
                       catch(RemoteFault faultVar){}


Now drag and drop a Reply activity under the catch activity.Your BPEL process is going to look like the following image.



Next we are going to configure the reply activity to reply with a fault.Double click on the Reply activity.Enter ReplyFault as name.Choose the faultthrowerbpel_client partner link.Now, select the fault variable as the variable.Next click on the magnifying glass as indicated in the following image  to choose the fault that we intend to return.

In the fault chooser dialog, select remoteFault.Hit Ok once you are done.



The reply activity should look like as shown in the following image.


 Hit Ok to complete the reply activity.The BPEL process should look like the following image.


 Next,we have to configure the operation for the FaultThrower BPEL to indicate that he process can return a fault.To do this, open the FaultThrower.wsdl file and go to source.Notice that the RuntimeFault.wsdl is imported into this WSDL automatically.



Now, add a new fault inside the operation.The fault should be based on the message as defined in the RuntimeFault.wsdl.file.Make sure the namespace is declared.


This completes the BPEL process.Now deploy and test the web service.The behavior is going to be the same;this time though, the fault is caught by the FaultThrowerBPEL.Once caught, the FaultThrowerBPEL replies to the calling BPEL i,e, the FaultHandlerBPEL in this case with a remoteFault.This remoteFault is then caught by the catchAll activity inside the FaultHandlerBPEL.So in java syntax, we are doing something like this in the FaultThrowerBPEL:-


                                ....
                                catch(RemoteFault faultVar){
                                                throw new RemoteFault(faultVar);
                                }

########