Today I want to introduce a testing code for users who have not had an enough experience of DIIOP or Notes Java class and want to learn DIIOP feature.
Preparation
1. Start HTTP & DIIOP task
To use DIIOP feature, you need to start HTTP task and DIIOP task beforehand.
You can manually start these task like "load DIIOP" command or you can add these tasks to "ServerTasks" entry in your server Notes.ini file.
2. Install JDK
You also need to install JDK environment to compile DIIOP program.
You can get JDK environment from here.
IBM JDK Download
Sun JDK Download
On the sample in this article, you need to take so much care of Java version, but basically you need to use the same Java version as your Lotus Notes/Domino JRE environment.
To check your JRE version, use
\jvm\bin\java -fullversion command.
Example:
C:\lotus\notes\jvm\bin>java -fullversion
java full version "J2RE 1.5.0 IBM Windows 32 build pwi32devifx-20071025 (SR6b)"
3. Copy NCSO.jar
On using remote access application ( I mean the Java program which uses NCSO.jar, not Notes.jar) , you don't need to install Lotus Notes client on client environment.
You just copy NCSO.jar file to your client machine.
NCSO.jar file is located on
\domino\java
Sample Code
On this article, you don't need to prepare sample database to run the sample.
This sample code just accesses the specified server and opens names.nsf on the Domino server and get some database information.
NABTest.java (Change the variable in blue to fit your environment)
import lotus.domino.* ;
public class NABTest
{
static String host = "xxxx.xxx.com" ; // server address
static String cName = "notes admin" ; //username
static String dbname = "names.nsf"; // database (e.g. mail\\hnagashi.nsf)
static String password = "password" ; // internet password
public static void main(String args[]){
try{
Session s = NotesFactory.createSession(host,cName,password) ;
Database db = s.getDatabase("", dbname );
if(!db.isOpen()){
db.open();
}
String title = db.getTitle();
String uname = s.getUserName();
System.out.println("UserName: " + uname );
System.out.println("ServerName: " + db.getServer());
System.out.println("Title: " + title);
}catch(NotesException ne){
System.out.println(ne.id + ne.text);
ne.printStackTrace() ;
}catch (Exception e){e.printStackTrace() ;}
}
}
Compile and Execution
When you start to run DIIOP program, I think compiling DIIOP program would be the most difficult step for unfamiliar users. To compile program, you just add the path to NCSO.jar file to CLASSPATH but to avoid confusion, I usually create the batch file like this.
(I used "C:\MyJava" directory as working directory)
Compile.bat (Change the variable in blue)
set Java_HOME=C:\SUN\Java\jdk1.6.0_06\bin
set PATH=%Java_HOME%;%PATH%
set CLASSPATH=C:\lotus\notes\data\domino\java\NCSO.jar;C:\myjava
javac -target 1.5 NABTest.java
JAVA_HOME: Full path to your JDK bin folder
CLASSPATH: Add work directory(C:\MyJava in the above sample) and full path to NCSO.jar
Note: On the above sample. I used "-target 1.5" because Notes Domino 8.x uses Java 1.5.
so you need to specify "-target 1.4" when you uses Lotus Notes Domino 7.x
run.bat
java -cp c:\MyJava;c:\lotus\notes\data\domino\java\NCSO.jar NABTest
Result
You will get the result like this.
C:\MyJava>run
C:\MyJava>java -cp c:\MyJava;D:\lotus\notes\data\domino\java\NCSO.jar NABTest
UserName: CN=notes admin/O=LTS
ServerName: CN=xxxx/O=LTS
Title: LTS's Directory
This is very cheap and simple code like "Hello World" code and when I set up DIIOP test environment, I am using this kind of code to test my environment is working correctly.
Hope it helps!