Tuesday, October 29, 2013

SOA - No silver bullet in software development at all

With the emerge of a new technology, there always some people would tell the people that technology would solve the problem and make the development successful. But people found that is not true soon and got disappointed as the silver bullet they expected is not true at all.

When the Java appeared in our development life, the people praises it is a revolution as it has garbage collection and is Object-Oriented. Also, it makes the software runs anywhere by using JVM. Theoretically, Java can improve the re-usability and  readability of code. Later, I saw many many developers create giant classes and giant methods without any OO concept, and there is no re-usability and readability at all. I do agree that it is not for all of developers, but pretty a lot did, especially some developers who worked with C previously.

When the SOA was introduced, people felt they found another extreme weapon to solve the development issues and make the project much successful. But I cannot believe it. If the developers don't follow the best practices and related disciplines, nothing can get better but more difficult to trace the problem.

When I first began to learn SOA Suite on 2010, the trainer told me a lot of advantage of it and gave me wonderful picture of it. But I couldn't believe it completely. The SOA Suite allow you to build BPEL process by dragging and dropping and I supposed it should make the process much easy to understand and be clear.  It should bring agility too. Later, I see some developers are creating giant complicated BPEL processes. It is too big to look at it and too complicated to understand it. Some giant one really make me scared.

After so many years, I have to say there is no silver bullet in software development as the issue is created by people not the technologies. For Java, the developer should create proper classes and extract proper methods to put the logic in different places leveraging the advantages of OOP and design patters to make the code re-usable and readable. For BPEL, the developer should create multiple BPEL processes to make the processes as clear as possible and as unique as possible to make it understandable and re-usable.

I still strongly believe the software programming/development is still an Art and really need the people think more and do more.  Otherwise, the people just create another mess when they criticize the mess made by somebody else.

Wednesday, July 31, 2013

OSB-Error handling with Resume action to execute the process continously without throw the exception

In some scenarios, we want the process continuously executes the further steps and ignore the error. In Java code, it is pretty easy and what you need to do just uses a try..catch and then properly set the variables and not throw the exception again. In OSB, it has a little bit difference and a Resume action must be introduced to make the process resumed and executed continuously to handle the further steps.

Error Handler Actions
When an error handler processes an error, it can finish with one of two actions:
Table 18-1 Error Handler Actions
Error Actions
If you assign this action, an error response is immediately created for the proxy service client. All further Message Flow processing stops and a response message is sent based on the message-related context variables. In this instance, you can configure the error handler to send a simple reply to the proxy service or a more detailed reply stating that an error occurred.
The difference between HTTP reply with success and reply with failure is as follows:
  • Reply with success sends status code 200 and $body
  • Reply with failure status sends status code 500 and $body
When this action is included in a message flow, message flow processing continues as though no error has occurred. Processing continues after the node or stage in which the error handler is configured. You may need to configure the error handler with compensating logic to set the context variables and message state to correspond with the variable and message state expected by subsequent message flow logic. Configure the compensating logic prior to the Resume action.
If neither the Reply nor the Resume action is initiated, the error is rethrown. In this case, the error is pushed forward and handled by the next level error handler. Unless otherwise specified, the rethrow action is the default action of an error handler.

Thursday, June 20, 2013

OSB-Create an fault with customized error code and error message

When you developed in OSB, you may want to provide a customized error code instead of BEA-xxxxxxx when you catch a fault. By the follow steps, you can replace the error code in fault and reply a fault with your customized error code.

In error handler,
1. Replace the error code with the customized error code by xpath ./ctx:errorCode  in fault2. Replace reason with your customized error message by xpath ./ctx:reason in fault
3. Replace the node contents by xpath . in body with $fault
4. Put a Reply at the end of error handling and select the radio button With Failure

For more detail about error handling in OSB, you can refer the follow blog of Eric.

Oracle Service Bus 11g, handling SOAP Faults

Thursday, June 06, 2013

OSB-Parallel Programming with Static and Dynamic Split-Join


In Java language, we can make one Thread to wait for another by using join method. 
private void startThreads(int nfOfThreads) {
  Thread[] threads = new Thread[nfOfThreads];
  //start the threads
  for (int i = 0; i < threads.length; i++) {
    threads[i] = new ThreadTestWithoutJoin.MyThread();
  //join the threads
  for (int i = 0; i < threads.length; i++) {
    try {
    } catch (InterruptedException e) {}

In the above code, there are two for-loops, the first to create and start each thread, and the second loop to join each thread. If each thread is joined right after start, the effect is these threads are executed sequentially, without the desired concurrency.
// The following is NOT concurrent:
private void threadTest(int numOfThreads) {
 Thread[] threads = new Thread[numOfThreads];
 for (int i = 0; i < threads.length; i++) {
     threads[i] = new foo.ThreadTest.MyThread();
     try {
     } catch (InterruptedException ignore) {
(Refer http://javahowto.blogspot.ca/2007/05/when-to-join-threads.html)


In WLI, Parallel node represents a point in a business process at which a number of activities are executed in parallel. By default, parallel nodes contain an AND join condition. In this case, the activities on all branches must complete before the flow of execution proceeds to the node following the parallel node. You can change the join condition to OR

Parallel branches of execution in a business process are logically parallel; physically the branches are executed serially by the business process engine. While one branch of execution is waiting for a response, another branch of execution in the parallel flow can progress.
(Refer http://docs.oracle.com/cd/E13214_01/wli/docs102/bpguide/bpguideParallelDesign.htmlhttp://docs.oracle.com/cd/E13214_01/wli/docs102/jpdtutorial/tutWLIProcessParallel.html)


In OSB, Split-Join feature lets you split a service payload, such as an order, into individual messages for concurrent processing. Concurrent processing, as opposed to sequential processing, greatly improves service performance. Split-Join achieves this task by splitting an input message payload into sub messages (split), routing them concurrently to their destinations, and aggregating the responses into one overall return message (join). This process of payload splitting and response aggregation is called a Split-Join pattern.we can create Split-Join flow for parallel programming. There are two types of Split-Join, one is static and another one is dynamic.

The Static Split-Join can be used to create a fixed number of message requests
The Dynamic Split-Join can be used to create a variable number of message requests.

Any webservice needs a WSDL, Split-Join flow is the same and the first thing we need to do is to create a WSDL. Every Split-Join is based upon a WSDL operation. When you first create a Split-Join, you will be asked to browse to the appropriate WSDL file and to select an operation as part of the creation process. The WSDL of Split-Join flow can be same as the proxy service which will invoke the flow or you can defined a totally different WSDL. The choice is really based on your requirement.

For dynamic Split-Join, please refer the follow blogs. As these blog is pretty detail, I won't write anything.

For static Split-Join, I got few help from the internet. But it is pretty easy when you have done a dynamic one.
First, create a new Split Join based on the WSDL operation you want to use.  In the Split-Join editor, you can see following flow, which consists of a Start Node, a Receive, a Reply. By clicking the triangle icon beside of Start Node, you can see the Start Node contains both a Request Variable and a Response Variable that have been determined by the WSDL operation initially selected. You can change the variables' name same as what you did in dynamic Split-Join. The Receive Node receives the incoming request message, and the Reply Node generates a response message and sends it back to the client.
Debugging a proxy service
Second, add an Assign Node after the Receive Node to initialize the Response Variable in a form such that the later nodes can work on the data within it. This output message is relayed to the final Reply node in the Split-Join and, in turn, returned to the original client.
Third, add a Parallel Node. The Parallel Node contains two main branches at the beginning, you can add more by clicking on the plus icon. Each branch is composed of a number of actions, the sequence and general configuration being the same for both branches.
Debugging a proxy service

Forth, add an Invoke Service Node. On the properties tab, config the service and operation. Select the Input Variable to create a new request variable and then select the Output Variable to create response variable. The result will be stored in the output Variable. The service you reconfigured for each branch may be not the same based on your requirement.

Fifth, add an Assign/Copy/Insert/Replace before the Invoke Service Node to prepare the input variable for service invocation. As the service invoked may be different, the logic in the node is not the same.

Sixth, add an Assign/Copy/Insert/Replace after the Invoke Service node to put the data in the Output Variable to the response variable of flow.

When you done everything you need, you can follow the steps in dynamic Split-Join to generate a business service. Then you can invoke it and test it in a proxy service.

If you have the book The Definitive Guide to SOA, you can look at the chapter 7 Parallel Calls with Split-Join for help as there is more detail.
(Reference http://docs.oracle.com/cd/E13159_01/osb/docs10gr3/eclipsehelp/tasks.html#wp1150654)

When I opened the source code of flow in text editor, I found the flow is implemented with BPEL instead of genera OSB xml.

Tuesday, May 14, 2013

OSB-SOAP Action Header Issue

Recently, I worked on an existing code developed by somebody else long time ago and a defect was opened for SOAP action header issue. The invoked web service always complained 'no SOAPAction header!'.

As the business service was developed by vendor and they used RPC style, we have to define the business service as any XML service. (If we defined as a WSDL webservice, OSB threw exception when it got the response - unrecognized response.) As the business service was set an any XML service, it looks like the the OSB can automatically set soap action header.

In OSB proxy service, before the service callout, put a replace action to replace the soap action hdead in outbound.
In this application, I just used the soap action header of inbound to replace the one of outbound by the easiest way. (From the OSB console, I saw the soap action header is empty string for the initial request and same as the one needed for the service call, then I just copied them from Inbound Request.)

Note: A Transport Headers action looks like not work properly and the soap xml was modified by OSB automatically and caused an additional soap body was added to the soap envelop incorrectly.

SOAPAction References:

Wednesday, May 08, 2013

Java synchronized methods: lock on object or class


In section 8.1.1 of the Java Language
Specification, third edition. The valid modifiers for a class are any
annotation, public, protected, private, abstract, static, final, or
strictfp. It is illegal to place the keyword "synchronized" in front of
a class.

The Java Tutorials say: "it is not possible for two invocations of synchronized methods on the same object to interleave." What does this mean for a static method? Since a static method has no associated object, will the synchronized keyword lock on the class, instead of the object?

Synchronized method acquires a monitor (§17.1) before it executes. For a class (static) method, the monitor associated with the Class object for the method's class is used. For an instance method, the monitor associated with this (the object for which the method was invoked) is used.

One point you have to be careful about (several programmers generally fall in that trap) is that there is no link between synchronized static methods and sync'ed non static methods, ie:
class A {
static synchronized f() {...}
synchronized g() {...}


A a = new A();
Thread 1:

Thread 2:

f() and g() are not synchronized with each other and thus can execute totally concurrently.

Unless you implement g() as follows:
g() {
synchronized(getClass()) {
I find this pattern useful also when I want to implement mutual exclusion between different instances of the object (which is needed when accesing an external resource, for example).

SOA - Set Loopback for SOA suite installation on a DHCP host

In order to install SOA suite on a DHCP host, we need to set the loopback. If you have installed VM ware or Virtual Box, you are lucky and the loopback had been created. If not, just follow the follow steps to create a loopback.

(From http://docs.oracle.com/cd/E16764_01/install.1111/e14318/qisoa.htm#BGBJEFDH)

3.7 Installing on DHCP Hosts

If you are installing Oracle SOA Suite on a DHCP host, you must follow the configuration steps in this section for your platform.

3.7.1 For UNIX Platforms

On UNIX operating systems, configure the host to resolve host names to the loopback IP address by modifying the /etc/hosts file to contain the following entries: hostname.domainname hostname localhost.localdomain localhost
After doing so, check that the hostname resolves to the loopback IP address by entering the following command:
/bin/ping hostname.domainname

3.7.2 For Windows x86 Platforms

On Windows systems, install a loopback adapter on the DHCP server (see Section 3.7.3, "Installing a Loopback Adapter (Windows Only)"). This assigns a local IP address to your computer.
After installing the adapter, add a line to the %SYSTEMROOT%\system32\drivers\etc\hosts file with the following format, immediately after the localhost line:
IP_address   hostname.domainname   hostname
Replace IP_address with the local IP address of the loopback adapter.

3.7.3 Installing a Loopback Adapter (Windows Only)

To install a loopback adapter on Windows 2003 or Windows XP:
  1. Open the Windows Control Panel.
    Windows 2003: Select Start > Control Panel > Add Hardware.
    Windows XP: Select Start > Control Panel, then double-click Add Hardware.
  2. In the "Welcome" window, click Next.
  3. In the "Is the hardware connected?" window, select Yes, I have already connected the hardware, then click Next.
  4. In the "The following hardware is already installed on your computer" window, in the list of installed hardware, select Add a new hardware device, then click Next.
  5. In the "The wizard can help you install other hardware" window, select Install the hardware that I manually select from a list, then click Next.
  6. In the "From the list of hardware types, select the type of hardware you are installing" window, select Network adapters, then click Next.
  7. In the "Select Network Adapter" window, make the following selections:
    • Manufacturer: Microsoft
    • Network Adapter: Microsoft Loopback Adapter
  8. Click Next.
  9. In the "The wizard is ready to install your hardware" window, click Next.
  10. In the "Completing the Add Hardware Wizard" window, click Finish.
  11. If you are using Windows 2003, restart your computer.
  12. Right-click My Network Places on the desktop and choose Properties. This displays the Network Connections Control Panel.
  13. Right-click the connection that was just created. This is usually named "Local Area Connection 2". Choose Properties.
  14. On the "General" tab, select Internet Protocol (TCP/IP), then click Properties.
  15. In the "Properties" dialog box, click Use the following IP address and do the following:
    1. IP Address: Enter a non-routable IP for the loopback adapter. Oracle recommends the following non-routable addresses:
      192.168.x.x (x is any value between 1 and 255)
    2. Subnet mask: Enter
    3. Record the values you entered, which you will need later in this procedure.
    4. Leave all other fields empty.
    5. Click OK.
  16. In the "Local Area Connection 2 Properties" dialog, click OK.
  17. Close Network Connections.
  18. Restart the computer.

3.7.4 Removing a Loopback Adapter (Windows Only)

To remove a loopback adapter on Windows 2003 or Windows XP:
  1. Start the System Control panel.
    Windows 2003: Select Start > Control Panel > System.
    Windows XP: Select Start > Control Panel, then double-click System.
  2. In the "Hardware" tab, click Device Manager.
  3. In the "Device Manager" window, expand Network adapters. You should see Microsoft Loopback Adapter.
  4. Right-click Microsoft Loopback Adapter and select Uninstall.
  5. Click OK.

Oracle SOA Suite Basic

In SOA suite, we must understand the follow concepts.

  • Adapter - used to connect resources
  • Mediator - Route and Transform
  • Rule Engine - Business Rules
  • BPEL Process - Orchestration
  • Human Workflow - Involve human beings
  • Security Framework - Policy-based security
  • BAM - Business Activity Monitor, visualization of process running

What is SCA?

SCA - Service Component Architecture, which is a specification backed by a growing number of leading industry vendors (http://www.OSOA.org) and being standardized at OASIS, the international open standards consortium . SCA is:
  • language-neutral
  • component model 
  • assembly model
SCA terminologies:
  • Composite: deployment unit
  • Service: entry-point into composite
  • Component: provides logic
  • Reference: refers to external services
  • Wire: connects services, components and references – no special semantic.
SOA Composite:
  • SOA composite is a standards-based deployment unit
  • Leverages the SCA assembly model
  • Can mix variety of components: Mediator, BPEL, Human Workflow, etc.

Thursday, April 25, 2013

Token Configurations in Oracle SOA Suite PS6

Eventually, we find a way to deploy our application easier and can modify the endpoint of service instead of redeploy the application with deployment plan.


Handle a transaction between OSB and SOA suite

Recently looked at how to handle a transaction between OSB and SOA suite. From all of document I found, the HTTP protocol can not support transaction however you set your service. If we want them to support transaction, we have to use direct binding.
In composite, we need to modify the reference to set <binding.direct> .
For SOA-OSB, we should set the transport protocol to sb protocol of proxy service.
For OSB-SOA, we should set the transport protocol to soa-direct of business service.

For the features of SOA-Direct, see OSB-SOA Direct transport

For how to implement a global transaction, we can refer to Edwin blog.
Global Transactions and Quality of Service in OSB