Looking up a datasource from an IBM Connections event handler

For a customer project I’m working on these days I’m writing an event handler for IBM Connections Profiles to integrate two profile systems in real-time using the IBM Connections 4.0 Event SPI. Pretty powerful stuff in case you’ve never looked into it.

In IBM Connections an event handler is basically just a Java bean which you register in events-config.xml to be called when certain events occur such as a profile being updated, the photo set, the photo removed etc. In this event handler I needed to contact the Profiles database which should be easy as it’s registered in JNDI in Websphere Application Server. I couldn’t however use the usual java:comp/env/jdbc/profiles resource reference as there’s no J2EE deployment description for the event handler and hence the naming context hasn’t been mapped for me.

But with Websphere Application Server being the all-purpose application server that it is, I was able to find a way to make it work anyway. It turns out that all resources are mapped into a JNDI namespace using their cell and cluster prefix as well (I was able to deduce it from the “Example: Looking up an EJB home or business interface with JNDI” page).

So to look up the jdbc/profiles data source from the Cluster1-cluster scope I simply use the following. Sweet.

try {
   InitialContext ctx = new InitialContext();
   DataSource ds = (DataSource)ctx.lookup("cell/clusters/Cluster1/jdbc/profiles");
} catch (NamingException e) {
   // unable to lookup data source
}

LS2J rules!

I know it has limitations and that it has issues but today it worked like a charm. I was asked to write a library in LotusScript to resolve groups and nested groups from Active Directory into an array of users. It had to be cross platform which ruled out COM and ActiveX controls even if I had been able to find any.

The solution was of cause to write the code in Java using JNDI (Java Naming and Directory Interface) and then write a thin wrapper class in LotusScript using LS2J (LotusScript to Java bridge supplied with Notes out-of-the-box). Now I have a cross-platform solution that has no external dependencies. Beautiful!

So learn Java already! 🙂