Saturday 9 March 2013

How to use Node.js with WebLogic OSB

I recently came across a situation where there was a requirement to use WebLogic OSB configuration in a Node.js application. The information in question was the Endpoint URIs for all Business Services found in the OSB.
Since WebLogic removed "ServiceConfigurationMBean" from WLST in 11g, writing a Python script as you normally do was out of the question. Using Java was the only possibility at this stage, but it felt a bit much writing a new app just for a simple task like this.

This is when a college pointed me to https://github.com/nearinfinity/node-java which is a module to write native Java which is then executed inside your javascript using Node.js.

It turned out to be very straight forward and I added a sample JavaScript here: https://gist.github.com/dunse/5122258

In order to run the script, you will need Node.js, Java and some WebLogic libraries.
The WebLogic libraries been specified in the getbs.js file as:
java.classpath.push('configfwk-1.1.0.0.jar');
java.classpath.push('sb-kernel-impl-1.1.3.0.jar');
java.classpath.push('sb-kernel-api-3.0.jar');
java.classpath.push('sb-kernel-common-1.1.3.0.jar');
java.classpath.push('wlfullclient-10.3.0.jar');
java.classpath.push('standalone_client-11.1.1.jar');
Copy those files to the current working directory and update any version numbers as necessary.


Next, define your connection options:
var config = {
        admin_server: {
            "hostname": "z2esbadmin01.zst.optusnet.com.au",
            "port": 9001,
            "username": "weblogic",
            "password": "w3blogic"
        }
    };


And then run it:
node getbs.js

If all goes well, it will output something similar to this:
qwerty/business_services/qwerty_bs       =>       http://my.backend.server.com:8080/EndPoint/
...