LinkedIn

Wednesday, September 8, 2010

Custom XPath in OSB 11g

There is already a documentation available for this cool new feature in OSB 11g to create custom XPath functions that can be used from the OEPE IDE or even from the Service bus console.

For the ones who have a touch time to understand the Oracle documentation, here is a brief tutorial.

Please refer to the Oracle Document here for the detailed steps:

http://download.oracle.com/docs/cd/E14571_01/doc.1111/e15866/custom_xpath.htm#CBADFJEG

I would start of by creating my own xml for my own custom function. I would name it custom-osb-xpath.xml with a corresponding .properties file associated with it. Here are the contents:

custom-osb-xpath.xml

<?xml version="1.0" encoding="UTF-8"?>
<xpf:xpathFunctions xmlns:xpf="http://www.bea.com/wli/sb/xpath/config">
<xpf:category id="%CUSTOM_FUNCTIONS%">
<xpf:function>
<xpf:name>concatStrings</xpf:name>
<xpf:comment>%FUNC_CONC_COMMENT%</xpf:comment>
<xpf:namespaceURI>http://www.dell.com/alsb/custom/xpath/xpath-functions</xpf:namespaceURI>
<xpf:className>com.caterpillar.alsb.custom.xpath.StringConcat</xpf:className>
<xpf:method>java.lang.String concatString(java.lang.String, java.lang.String)</xpf:method>
<xpf:isDeterministic>false</xpf:isDeterministic>
<xpf:scope>Pipeline</xpf:scope>
<xpf:scope>SplitJoin</xpf:scope>
</xpf:function>
</xpf:category>
</xpf:xpathFunctions>

custom-osb-xpath.properties

%CUSTOM_FUNCTIONS%=Custom Service Bus Functions
%FUNC_CONC_COMMENT%=Returns a concatenated string based on the input strings. E.g. fn-bea:concatStrings($string1 as xs:string, $string2 as xs:string )


Place these files in OSB_ORACLE_HOME/config/xpath-functions directory of the OSB installation.

Now we would create a sample java class to concatenate two strings

package com.caterpillar.alsb.custom.xpath;

import java.lang.String;

public class StringConcat {

public static java.lang.String concatString(String stringa, String stringb)
{
String concatedStr= new String(stringa);
return concatedStr.concat(stringb);
}
}

Thats all we need. We are good to go now. Restart the OSB server or the Eclipse IDE. On booting them up we would start to see these custom functions added.

Here is a sample Xquery i created to use this custom XPath funtion

declare namespace xf = "http://tempuri.org/CommonServices/Common/Monitoring/XQ/ConcatStrings/";

declare function xf:ConcatStrings($string1 as xs:string,
$string2 as xs:string)
as xs:string {
xpat8i:concatStrings($string1,$string2)
};

declare variable $string1 as xs:string external;
declare variable $string2 as xs:string external;

xf:ConcatStrings($string1,
$string2)


Simple but so useful!

Tuesday, September 7, 2010

Xquery Enhancements using XQSE

Well, I dont need to reiterate the usefulness of Xquery when it comes to OSB development. This is one of the few good XML technologies which i find amazing for XML processing and transformations but it is equally neglected as well. It needs to evolve as a programming language. As a matter of fact, I have found it lacking of so many things that are so critical sometimes.

During one of my transformation exercises I was supposed to handle date conversions in Xquery. The problem with using Xquery was that if any of the date formats comes wrong this would lead to an error in my Xquery and it will be aborted. However in my case what i needed to do was simply send a null/empty value in date field if the conversion failed for any reason. Miserable situation if we have only Xquery.

BEA came up with an extension for XQuery called XQSE (Read XQuery Scripting Extension) to use more programmatic blocks in Xquery. Here is an example

declare xqse function xf:CreateDateTimeFromString($DateTime as xs:string?)
as xs:dateTime? {

try{
if(fn:string-length($DateTime)>8) then
return value  ( xs:dateTime(fn:concat (fn:substring($DateTime,1,4),'-',fn:substring($DateTime,5,2),'-', fn:substring($DateTime,7,2),'T',
fn:substring($DateTime,9,2),':',fn:substring($DateTime,11,2),':',fn:substring($DateTime,13,2)))) ;

return value  (xs:dateTime(fn:concat(fn:substring($DateTime,1,4),'-',fn:substring($DateTime,5,2),'-', fn:substring($DateTime,7,2),'T','00:00:00')));

}catch (* into $err, $msg) {
return value  () ;
};
};

The above xqse function allows us to surround our xquery with a try catch block. This is extremely useful for the case i explained above.

Tuesday, December 29, 2009

ALDSP to ODSI Migration Tips and Tricks

I have been working on this aspect for a few time now. Here i am sharing some of my experiences related to migrating from data services projects in ALDSP 2.5 to data space projects in ODSI 10gR3

ALDSP to ODSI Migration Steps

Wednesday, October 28, 2009

Aqualogic Service Bus Tutorial

Weblogic - Aqualogic Service Bus - EAI - Part 1

This blog is to gather my learnings and understandings about Weblogic(WL)'s Aqualogic Service Bus (ALSB). Initially, i could not appreciate this awesome product from BEA. ALSB is meant mostly for Webservices and SOAP requests. I was trying to use these functionalities for normal GET and POST requests in RESTful services. Before we proceed further, lets look at some basic SOA jargons.

Service Bus:

Service Bus is considered as Enterprise Application Integration (EAI) tool, that would facilitate easy integration of various services (that are building blocks of any software system). This integration tool is created with various technologies that are opted for software middleware infrastructure. So, please note that ESB is not a programing language itself.

Also, ESB is NOT an app or web server. This is an application (could be web application) that runs in an web container. So, if you want to play with ALSB, you would need both WL server and ALSB. You could download trial version which you can use for 60days.

Basic Features of an ESB:
  1. Loose coupling of services in a software system. This would provide great flexibility of modifying / enhancing any part of the system without affecting much on the other dependents.
  2. ESB should be standard based and flexible, and should support many transport mediums like Messaging Service, SOAP, XML and text etc.
  3. It should allow integration with very less coding. In other words, should be configurable.
  4. ESB should be more scalable and highly revolvable.

All other features are added as vendors think it is necessary for an ESB. So, an Architect can select appropriate product based on their needs.

Ok! Lets get our hands dirty.

Installation:

ALSB setup can be (of course, trail version) downloaded from BEA site. I downloaded ALSB 3.0 which comes bundled with WL server 10.0.

There is nothing special about this installation. I just followed the installation setup wizard and it went perfect on my XP machine.

Basic Setup:

As basic setup, I created a user domain for my test project. You don't need to create a new domain, if you prefer to work on example domain, which is created with installation.

So, I created a domain using Start --> All Programs --> Bea Products --> Tools --> Config Wizard. Please follow this link if you have any questions on specific setting.

Once domain is created, start weblogic server from Start --> All Programs --> Bea Products --> User_projects --> --> "Start Server for AquaLogic Service Bus Domain"

Look for server state as running. When server is up and running, it would open Weblogic Admin console automatically. Since we are interested in ALSB and its console, I am not going to discuss about Weblogic Admin Console here.

Weblogic products are considered as one of the best and user friendly because of their Admin Console. All settings and cluster, server maintenance and deployments everything could be done through Admin console.As we expected, ALSB has a Web Admin console, where most of the configuration can be done by just few clicks of mouse.

Ok. I like to wind up this blog at here. So, we have completed the installation of ALSB and before I start next topic, you could play around with various options in admin console to get used to it.

Weblogic - Aqualogic Service Bus - EAI - Part 2

I hope you are familiar with ALSB Admin console. If you don't have Weblogic ALSB please visit my previous blog for seeting up ALSB on your window machine.

I assume that you have WL server running and you can open Admin console of ALSB (http://localhost:7001/sbconsole/) in a web browser. Please note, if you are installing WL10.0 bundle, the port number for ALSB may be 7021.

How ALSB works:

In a nutshell, ALSB acts as a proxy between client and service (any service lives in server). The proxying is done by creating a Proxy Service and Business Service in ALSB. I hope the below diagram could help you understand the "request" and "respose" flow.

As diagram illustrates, ALSB stands between client and service / server to route the requests and responses. Here, I have shown 2 proxy service and 2 business service. However, a project could have 'n' number of proxy services and business services. If you happen to have more proxy and business services, you may want to touch base with customer support folks regaring performs impact. I would suggest to have more than one ALSB instances to avoid any performance bottle necks. Few jargons definitions are below.

Project in ALSB.

A project is nothing but a group of proxy and business services. You may like to group proxy and business services of billing services in one project and a separate group for order management services.

Proxy Service:

You have guessed it! Proxy service is contacted by the client to eventually get response from target service. ALSB allows developer or ALSB administrator to modify any request data and metadata through Admin console configuration. For example, consider a case, where you have web service, is contacted by two different vendors (clients) with two different XML requests. You don't need to write code to understand both request formats. Instead, ALSB Proxy service could be configured using XQuery to convert the request XML to desirable / server understandable format. This means easy addition of new clients with any changes to Target service, which evetually facilitate easy integration of systems.

Using XQuery programming, literally, all request data or parameters could be modified. If also allows to write logics to decide which business services to contact in runtime. This is one of the key feature of an ESB.

Business Service:

Business service represents target service's URL. Business services are contacted by proxy service to route the requests to target service. If there are more than one target service (multiple instances of same service for scalability), all the URL can be added to single business service. ALSB also provides features for load-balancing of services. Business service also helps to fail-over services. Meaning, if one target service is down, Business service routes the requests to another service when there is an outage encountered by ALSB. It means high availability of your services.

Setting up ALSB:

  • As mentioned earlier, business services (BS) and proxy services(PS) are grouped under ALSB projects. So, before we create PS, BS, lets create a new project.
  • Open Admin console of ALSB. http://localhost:7001 or http://localhost:7021
  • Go to "Project Explorer" on left panel.
  • Once the Enter project name in text box in "Enter New Project Name:" and click on "Add Project". If the text box is not enabled, please click on "Edit" on top left panel.
  • Project entry is added to the projects table just below that. Click on your project.
  • Select a "Resource" type from drop down options. First we create PS, So, select Proxy service from the option. On selecting PS option, next page should be automatically loaded.
  • Provide, proxy name and make sure you select "Any XML service option. Click on Next>>. As you can see, here, ALSB can support other services like Messaging, WSDL and SOAP services.
  • Select protocol as "http" and leave rest of the options with default values. Click on Next>> to save the settings for proxy service.
  • Now, you can new proxy serive is added to "Resources" table.
  • Next, create a business service by selecting "Business Service" in the drop down options.
  • Follow the setting wizard. Provide BS name and type. Please make sure you select same type as PS. Click on Next>>.
  • On next page, we have to some important configuration for BS. Select protocol as http and Load balancing Algorithm as round-robin. Provide End point URL of Target service. In our case any webseite url. Since other options are not much important at this level, please go with default values and click on Next>>.
  • Since, we are dealing with website, select HTTP request as "GET" and leave rest of the options with default values. Go to next page to save the settings.

Now that we have created both proxy service and business service, you might be wondering! "Wait a second, are we not supposed to hook up proxy service with business service???" Yes!! We should!. That's next.

I would recommend to save the configurations so far that we have done by hitting "Activate" button on left top panel. Please note, in ASLB console each time as you modify setting, they are created as sessions. Later, if you find that one of the setting needs to be reverted back to original setting. You can go to "View All Sessions" and clicking on appropriate icon under Options.

If you clicked on Activate button, Click on "Create" again to create a new session.

Configure Proxy Service:

  • Click on your project under project explorer section. In Resources section, click on "Edit Message Flow" icon ( the one is activated) under "Actions" column.
  • On the next page right click on proxy service cover and select "Add Route". Here, as you can see, you can "Add pipeline pair" to add request and response pipelines. Under request and response pipelines, you could "Add Stage" to perform logic operations.
  • So, we have added new Route, Right click on RouteNode1 to select "Edit Route" to modify setting. You can also modify the name of this node to a meaning ful name by selecting "Edit name and Comments".
  • On Edit Route page, click on "Add an Action" --> Communication --> Routing
  • Now, you get new node added to this page. Click on "*" to select which business service should be contacted by this PS.
  • You can also add other Request and Response Actions like modifying header or to perform some logic operations or Log the event to server log file for reporting purposes.
  • "Save All" this settings and Activate the session to be effective.

Here, PS is hooked up with BS. You can contact PS through your browser by typing http://localhost:7001/proxyServiceName

The response should be eventually from the target website URL. Hope you are getting a proper response. You can further explorer to add stage (as mentioned in step 2) and modify request data and headers.

You can also refer reference documents from BEA site for more information.