wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

Running vert.x with the OpenNTF Domino API


In the first part I got vert.x 3.0 running with my local Notes client. The mastered challenges there were 32 Bit Java for the Notes client and the usual adjustment for the path variables. The adoption of the OpenNTF Domino API required a few steps more:
  1. Set 2 evironment variables:
    DYLD_LIBRARY_PATH=/opt/ibm/notes
    LD_LIBRARY_PATH=/opt/ibm/notes
  2. Add the following parameter to your Java command line:
    -Dnotes.binary=/opt/ibm/notes -Duser.dir=/home/stw/lotus/notes/data -Djava.library.path=/opt/ibm/notes
    Make sure that it is one line only. (Of course you will adjust the path to your environment, will you?)
  3. Add 4 JAR files to the classpath of your project runtime:
    • /opt/ibm/notes/jvm/lib/ext/Notes.jar
    • /opt/ibm/notes/framework/rcp/eclipse/plugins/
      com.ibm.icu.base_3.8.1.v20080530.jar
    • org.openntf.domino.jar
    • org.openntf.formula.jar
    I used the latest build of the later two jars from Nathan's branch, so make sure you have the latest. The ICU plug-in is based on the International Components for Unicode project and might get compiled into a future version of the Domino API.
Now the real fun begins. The classic Java API is conceptually single threaded with all Domino actions wrapped into NotesThread.sinitThread(); and NotesThread.stermThread(); to gain access to the Notes C API. For external applications (the ones running neither as XPage/OSGi nor as agent, the OpenNTF API provides the Domino Executor.To make things easier, besides the standard Java Runnable interface, the class AbstractDominoRunnable is provided, that allow an easy extension and access to the Domino session without the need to create/tear down the native C threads manually. The sample application that does send out the same result as in the previous chapter looks like this:

package com.notessensei.vertx.notes;

import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import java.io.IOException;
import org.openntf.domino.thread.DominoExecutor;
import org.openntf.domino.thread.AbstractDominoRunnable;

public class OpenNTFDemo {

public static void main(String[] args) throws IOException {
DominoExecutor de = new DominoExecutor(10);
new OpenNTFDemo(de);
int quit = 0;
while (quit != 113) { // Wait for a keypress
System.out.println("Press q<Enter> to stop the verticle");
quit = System.in.read();
}
de.shutdown();
System.out.println("Verticle terminated");
System.exit(0);
}

private static final int listenport = 8112;
private final DominoExecutor de;

public OpenNTFDemo(DominoExecutor dex) {
this.de = dex;
Vertx vertx = Vertx.factory.createVertx();
HttpServerOptions options = new HttpServerOptions();
options.setPort(listenport);
HttpServer hs = vertx.createHttpServer(options);

hs.requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
final HttpServerResponse resp = req.response();
de.execute(new AbstractDominoRunnable() {
private static final long serialVersionUID = 1L;

     @Override
     public void run() {
      StringBuilder txt = new StringBuilder();
      resp.headers().set("Content-Type",
        "text/html; charset=UTF-8");
      txt.append("<html><body><h1>Hello from vert.x!</h1>");
      txt.append(this.getSession().getUserName());
      txt.append("</body></html>");
      resp.writeStringAndEnd(txt.toString());
     }

     @Override
     public boolean shouldStop() {
      return false;
     }
    });

}
}).listen();
}
}

The sample uses 2 inner anonymous classes: Handler and AbstractDominoRunnable. With this working we have the foundation to run a local web application that makes use of data accessible through our Notes client. The next step in this article series: API considerations and functionality planning. Thereafter code, code, code.

Posted by on 06 August 2014 | Comments (1) | categories: IBM Notes vert.x

Comments

  1. posted by Fredrik Stöckel on Friday 08 August 2014 AD:
    Nice research, very interesting stuff. I believe some of the success behind node.js (except the event/programming model) lies in how easy it is to build and deploy powerful applications/API:s.