Using IBM MDM Standard Edition SDK Client API in OSGI

Using IBM MDM Standard Edition SDK Client API in OSGI

Those who are familiar with IBM MDM Standard edition knows the importance of SDK client libraries and OSGI. With Client SDK we can create custom application interacting with MDM and OSGI is becoming popular with each day passing for modular application development. IBM MDM version 11 onwards we have MDM application being developed as an OSGI EBA. I assume that you are familiar with these terms, as I intend to tell something which was probably done first time. Using MDM Java SDK Clients inside an OSGI Bundle.

I was recently working on an project where the requirement is to use MDM SDK APIs outside the MDM Application which is going to be an OSGI EBA, deployed outside MDM EBA on WebSphere.

We had successfully used MDM SDK in our stand alone java clients and from J2EE applications and we were pretty sure that we can use it in the same way in an OSGI bundle as well.

So we created a sample bundle as POC and tried using MDM Client SDK in the manner we were using them in other custom clients. For example;

In our Context Creation section, we had following code;

UsrHead usrHead = new UsrHead("username", "password");

Context context = new Context("host","port",usrHead,options);

if(context.isConnected()){

log("Connection Successful);

}else {

log("Connection Failed with error" + context.getErrMsg());

}

And we created a sample EBA and deployed the bundle on WAS inside the sample EBA.

We had above code working in all our client but here comes the show stopper,

Context creation failed with a weird error saying it could not find following;

could not find file: /wsdl/VirtualBridge.wsdl

What went wrong, we did not even change our client libraries and file went missing ???

We ran J2EE application and same code worked. So where was the problem??

I did some debugging and it looked like some issue with class loader as class loading in OSGI is quite different then in Java EE. Each Bundle has its own class loader in OSGI and when using MDM Client Libraries which are non OSGI, you may encounter such problem. MDM client libraries internally invoke axis classes which are part of org.apache.axis2 plugin in Websphere. When control goes to these classes, the class loader of axis bundle has no idea where the client MDM client libraries are !!!

Tried doing some changes but nothing worked.

We raised a PMR with IBM but the initial response from them was not so encouraging as they sent us the steps to create OSGI bundle saying that it should work in the same as it works in any other client so we kept working on finding a workaround of the issue. Otherwise I had to change my entire design if we could not use MDM SDK libraries in OSGI bundle. I kept doing debugging and finally found a solution, playing around the class loader finally worked.

Its a workaround and I believe IBM should fix this issue.

So we need to change the ContextClassLoader of current thread to the ClassLoader of your bundle which is aware of MDM Client API. Here we go with same code but change in class loader;

ClassLoader currentClsLoader = getClass().getClassLoader();

ClassLoader originalContextClsLoader = Thread.currentThread().getContextClassLoader()

try {

//This line is the crux of all. Change the Context Class Loader to current class loader

Thread.currentThread().setContextClassLoader(currentClsLoader );

UsrHead usrHead = new UsrHead("username", "password");

Context context = new Context("host","port",usrHead,options);

if(context.isConnected()){

log("Connection Successful);

}else {

log("Connection Failed with error" + context.getErrMsg());

}

}finally{

//Finally revert the class loader to original one to avoid any runtime issues.

Thread.currentThread().setContextClassLoader(originalContextClsLoader);

}

Hurrayyyyyy!!! It worked.

Later IBM came with same workaround of problem and first time accepting that there is an issue using IBM SDK client libraries inside OSGI bundle.

Hope you enjoyed reading it. Please let me know your comments.

Sachin

Good one Sachin....this will really help us dealing with the problem in osgi....

To view or add a comment, sign in

More articles by Sachin Kumar

Others also viewed

Explore content categories