The magic that makes it all possible is provided by CORBA and DIIOP. While CORBA didn’t catch on across the industry and was plagued by horrible implementations, the Domino version makes good on the location transparency promise of CORBA. After a couple of lines of setup code, you can run Java code on your local machine and access Domino exactly as if you were running it on the Domino server.
First of all, I define a
Domino convenience object to encapsulate the CORBA setup. It uses the
Packages object in Nashorn to load the
NotesFactory class from Domino’s Java libraries, storing it in a local variable so it can be used without typing the entire qualified class name each time.
The Nashorn introductory material suggests using a Mozilla Rhino compatibility feature to load Java classes:
I was unable to get this to work. I couldn’t get the
JavaImporter class to import
use structure which
JavaImporter is designed around. If you have any luck with
importClass and Domino, I’d be interested to see code.
Anyhow, with the Domino
NotesFactory class loaded, the
openSession method is defined. When called, it uses
NotesFactory.getIOR() to connect via HTTP to the Domino server, and fetch the IOR — which is actually just a text file called
http://server.example.com/diiop_ior.txt, where server.example.com is the Domino server hostname. The IOR itself is just a string of ASCII characters that tell CORBA how to interface with the Domino server.
Note that your Domino server needs to have IIOP enabled, and there can be a catch if you have the server locked down to require HTTPS connections: The standard
NotesFactory is used to obtain a
lotus.domino.Session object, which is returned.
Finally, the rest of the
Domino object’s code (the initialization code) calls the
openSession method just defined, and returns the result.
// Get a lotus.domino.Session sess = Domino.openSession(serverURL, username, password); // Get a database db = sess.getDatabase("servername/MYORG", "some/db.nsf");
and so on. It’s exactly like XPages SSJS, except there you’d use
DominoUtils.getCurrentSession() to get the existing session object instead of opening a new one via CORBA.
The only other thing to note is that you need both
NCSO.jar from your server to be added to the
CLASSPATH for your Java environment when the script is run. I did this using the
-cp argument to the
jrunscript command, which works just like it does when using the
java command to run a Java program.
So, what is this good for? I can think of a few possibilities.