Search This Blog

Sunday, August 9, 2015

JMS Queue -- Message Rollback

CASE:
One of most commonly used mechanism/component in many of the integration projects is JMS queue to send the messages back and forth among participating applications at the same time they will run into different issues like configuring JMS queue or constructing JMS Adapter etc... and the current topic is a bit different from our regular issues. 

In real time integration's most of the call outs to web services will occurs on a particular event in that case sending the payload to web service ends source application responsibility after that it is receiver web service responsibility to hold the received payload and ensure that data is delivered successfully.

Scenario:
One of the scenario I have faced was source application delivers the data to my web-service upon an event and I need to enrich this and have to send across multiple participating applications in this integration where we need to convert the data into corresponding format which can be accepted by destination systems.

In this scenario, as soon as I receive the data from source application I used to store data in JMS queue which is created on Weblogic server where SOA resides.

Now the problem is after de-queue the data from this queue any of the end-systems may be down in that case my data will be sent to only to the applications which were up and running i.e. I can't keep all the participating applications in sync.

So, to over come this problem, I selected a synchronous BPEL service which as soon as de-queue the data from above mentioned JMS queue I will check all the participating end-system's are up and running or not.
Here you need to have a switch condition to decide whether data has to proceed further with processing or rollback to JMS queue.

If end-systems are up proceed with data enrichment and send data to end-systems finally you can reply some dummy value to JMS queue.
otherwise, if end-system is down have a throw activity which will rollback the data to JMS queue.

example:- 

step1: check end system web service is up or not using java activity.

        String serviceURL=(String)getVariableData("EndPoint");    
        java.net.URL serverAddress=null;         
        java.net.HttpURLConnection connection = null;         
        int st=0;         
        try {         
            serverAddress = new java.net.URL(serviceURL);         
            connection = (java.net.HttpURLConnection)serverAddress.openConnection();         
            connection.setRequestMethod("POST");         
            connection.setDoOutput(true);         
            connection.setReadTimeout(10000000);           
            connection.connect();         
            st=connection.getResponseCode();      
            st=connection.getContentLength();      
            setVariableData("endPointStatus",st);         
        } catch (Exception e) {         
            e.printStackTrace();         
            setVariableData("endPointStatus",st);         
        }

step2: Take the output into a local bpel variable using assing activity

Step3: Switch condition to decide which flow to choose.
If endsystem returns "-1" use "throw activity" which will rollback the data to JMS queue.
otherwise, data process further to deliver to end-systems.

Note:- 
1) This is as part of my requirement I have chosen this approach, this still have some limitations which I am fine with.

2) Thanks to Srinivas Adusumalli for helping me on this.

Thursday, August 6, 2015

CSF Key Creation and Usage

Case: Creating CSF key in Oracle SOA 11g

Usage: credentials for HTTP basic authentication can be used, updated run time and managed easily

In the world of integration projects, it is very common to invoke the 3rd party web service into your web service
i.e. when your service is acting as a caller service and calling service will accept your request only upon authenticating your identity then we can pass the credentials in different ways.

CSF Key, also know as Credentials Store Factory - Key, One of the best way of sending credentials in the header along with your actual request  in Oracle SOA is using CSF Key.

Case:
Most of the web service providers expect authentication before addressing your request.
Example, in one of my projects we need to invoke Fusion Customer Hub web service which is https secured service expecting both certificate on your server and basic http authentication credentials.


Creating CSF key:
Creating CSF Key is quite easy.
Login to Oracle SOA EM console -- http://servername:port/EM

Expand the Weblogic Domain in left side panel.

Right click on SOA11TEST_domain (your SOA domain)

Select Security/Credentials as shown below.

Which will open a new window in the right side panel as shown below.

You can click on "Create Key" option to create a new CSF key and if you want to see existing CSF key's click on "oracle.wsm.security"

After click on "Create key" select "oracle.wsm.security" as shown below. 


You can give values as below.
key (key name) --  which we will use in our code to refer this key values while invoking the web service.
User Name -- Give required username which is provided by service provider.
Password -- Give required password which is provided by service provider.
confirm password and give description about the key and purpose.

And click on "Ok".

Ex:- 



Now you are ready with CSF Key.

How to Use:
During development of caller web service in Jdeveloper.
On the SCA Composite window
After creating partner link for the web service you are planing to invoke (calling web service partner link)
You can right click on the partner link where you have to pass the credentials, which will open the window as shown below and select the Security policy as shown below by clicking "+" sign at the Security section level.


Upon completion of adding the owsm security policy click on edit option (pencil icon) which is just next to the '+' sign you used above. Shown below.



Click on "ok" and "ok" on both the windows which will enable the WSM policy and also adds the CSF key credentials as shown below.

How to check if it is properly added or not.
Go to SCA Composite as shown below and go to respective reference XML tags to show if the policy and key added properly or not.





Which will completes the steps to create CSF key in Oracle SOA server and how to use it in your code.

And once after the CSF key is created in future though the credentials changed you can go to EM console and you can edit the corresponding CSF key with new credentials which will be ready available run time.