Server settings required for accessing Domino using Java

Source: Internet
Author: User
I. Overview

Java accesses Domino Objects through the lotus. domino advanced package. According to the runtime environment, the interfaces in this package are implemented in one of the other two packages:

Lotus. domino. local provides the ability to call Notes/Domino Software on the same computer.
Lotus. domino. cso provides calling from the Domino server accessed through a remote connection.

For local access, the Java program runs on a computer where the Notes client or Domino server is installed. The local class is built by JNI (Java Native Interface) to access the Notes/Domino binary files in the same process as JVM (Java Virtual Machine.

For remote access, Java uses the Common Object Request Broker Architecture to Request services provided by the Domino server. The remote class accesses the server through the TCP/IP network using CORBA. Remote Access consists of the following two parts:

1. The client obtains the initial Object of the server through the HTTP protocol as the IOR (Interoperable Object Reference ).
2. The client uses the IIOP connection to further obtain other objects.

 

 

Java remote access through HTTP and IIOP

To compile a Java program using the lotus. domino package, the class path must contain Notes. jar (local) or NCSO. jar (remote ). For example:
Set classpath = % classpath %; c: \ lotus \ domino \ Notes. jar
Or
Set classpath = % classpath %; c: \ lotus \ domino \ data \ domino \ java \ NCSO. jar
The Notes. jar file can be found in any program directory installed in Notes/Domino. NCSO. jar can be found in the Domino \ java directory under the Domino Designer or domino server data directory.

This section only describes remote calls.

Ii. Remote Call

1. Domino server settings:

First, set the domino server. This is the key step to success.
First, make the following configuration on the Server document configuration page of the Server Domino Directory (names. nsf ).
(1) Open the Http tab of the Internet protocol tab and set "allow HTTP client to browse Database: yes"
(2) Open the Security tab and set Java/Com restrictions.
Run restricted java/javascript/com :*
Run unrestricted java/javascript/com :*
(3) Open the IIOP tab of the Internet tab of the Port tab, set the HTTP port number to 63148, And the status is enable and set verification.
Name and password of the selected certificate: No, anonymous: Yes
(4) Open the Internet tab of the Port tab, set the HTTP port number to 80, the status to enable, and set verification
Option name and password: No, anonymous: Yes
(5) To start HTTP and DIIOP tasks on the server, make sure these tasks are in the Notes. ini file.
If the file Server is correctly configured in the task list of the ServerTasks variable
Included in the task list. The Notes. ini file should contain rows similar to the following:
ServerTasks = Update, Replica, Router, AMgr, AdminP, CalConn, Sched, DIIOP, HTTP, LDAP
From the running server, you can enter the following command in the console to load the task:
> Load http> load diiop
You can run the tell Command on the console to stop the task:
> Tell http quit> tell diiop quit
You can refresh the DIIOP task:
> Tell diiop refresh
You can restart an HTTP task:
> Tell http restart
(6) obtain the IOR. If createSessionWithIOR is used to create a connection. Export the diiop_ior.txt file from the service
Computer to the client computer. The file is in \ Domino \ Data \ domino \ html under the installation directory of the server.

2. Connect to the domino server
During remote calling, the first parameter of the createSession signature is a non-null string. The first parameter is usually used to identify the computer on which the Domino server is located. For example:

Session s = NotesFactory. createSession ("192.168.128.2 ")
Or
Session s = NotesFactory. createSession ("192.168.128.2: 63148 ")
The second example specifies the port number, so that you do not need to run the Domino Web Server on 192.168.128.2.

To remotely call an application or servlet, the class path of the client computer must contain NCSO. jar. NCSO. jar contains the lotus. domino package, lotus. domino. cso package, lotus. domino. corba package, and ORB class. ORB class contains the implementation code for remote classes. For installed Domino Designer and Domino server software, NCSO. jar is located in the Domino \ java subdirectory under the domino data directory. For computers that do not have Domino software installed, you must copy the jar file from the computer where the software is installed and put it in classpath.

The encoding is relatively simple. NotesThread is not used for remote calls. You only need to use the host name and (optional) port number to call createSession.

Import lotus. domino .*;
Public class myClass
{
Public static void main (String argv [])
{
Try
{
String host = "192.168.128.2"; // Note: Sometimes the port number is required.
Session s = NotesFactory. createSession (host );
// Operational code goes here
}
Catch (Exception e)
{
E. printStackTrace ();
}
}
}

 

The following describes how to access domino through iiop.
On the Domino server, IOR is a file named diiop_ior.txt located in the Domino \ html subdirectory under the domino data directory. IOR is the string encoding of the object and contains the identification information for the server's CORBA access. The customer can decode the IOR string and use it to establish a remote session.

By default, the remote client requests the server IOR through the Web server port (which usually supports HTTP requests), and then requests the session through the DIIOP port. The two requests can be executed separately. For example:

String ior = NotesFactory. getIOR ("192.168.128.2 ");
// Get IOR using Web server port
Session s = NotesFactory. createSessionWithIOR (ior );
// Create session using DIIOP port
It is equivalent:
Session s = NotesFactory. createSession ("192.168.128.2 ");
In the NotesFactory call, you can add a colon and a port number after the host name or IP address to specify the host port used to obtain the IOR. If the Web server is not running, you can use this mechanism to support ior http requests through the DIIOP port. For example:
String ior = NotesFactory. getIOR ("192.168.128.2: 63148 ");
// Get IOR using DIIOP port
Session s = NotesFactory. createSessionWithIOR (ior );
// Create session using DIIOP port
However, the two-step encoding sequence is not required. You can simplify it:
Session s = NotesFactory. createSession ("192.168.128.2: 63148 ");

Note: specifying the DIIOP port to obtain the IOR is a new feature of Notes/Domino 6. Now you can use remote calls without allowing anonymous access to the Web server, or even starting the Web server.

You can also use other methods to obtain the IOR and then use createSessionWithIOR. For example, you can copy the diiop_ior.txt file from the server computer to the client computer. If the client contains the diiop_ior.txt file that is valid for the server to be used.

The following program demonstrates how to access the domino database, how to find documents, how to obtain data, how to download attachments, how to insert data, and how to upload attachments.
Bytes -----------------------------------------------------------------------------------
Test environment: domino5.0.7
Domino Database Name: javatest. nsf
Form: form1
Domain:
Text Field: name1
Time Domain: name2
Integer field: name3
Rtf domain: name4
List domain: name5
Multi-Value Domain: name6
-----------------------------------------------------------------------------
Package demo;
Import lotus. domino .*;
Import java. io .*;
Import java. util .*;

Public class JavaAccessDomino {
Public static void main (String argv []) {
Try {
FileInputStream fin = new FileInputStream (
"E:/JBWork/DominoApp/lib/diiop_ior.txt ");
InputStreamReader fisr = new InputStreamReader (fin );
BufferedReader br = new BufferedReader (fisr );
String ior = br. readLine ();
Fin. close ();
// Get sessionthrough diiop_ior, and put diiop_ior.txt locally
Session s = NotesFactory. createSessionWithIOR (ior );
// You can also use the sessionobtained in the following example to place diiop_ior.txt locally, but you must enable the domino Web server.
// Ior = NotesFactory. getIOR ("192.168.9.32"); // Get IOR using Web server port
// S = NotesFactory. createSessionWithIOR (ior); // Create session using DIIOP port
// Obtain the database object
Database db = s. getDatabase (s. getServerName (), "javatest. nsf ");
JavaAccessDomino obj = new JavaAccessDomino ();
Obj. selectDoc (db );
Obj. insertDoc (db );
Db. recycle ();
} Catch (Exception e ){
E. printStackTrace ();
}
}
/**
* Document Traversal
* @ Param db Database
*/
Public void selectDoc (Database db ){
DocumentCollection docList = null;
Try {
DocList = db. getAllDocuments ();
If (docList! = Null ){
System. out. println ("database:" + db. getTitle () + "is" +
(Int) (db. getSize ()/1024) +
"KB long and has" + docList. getCount () +
"Documents ");
Document doc = docList. getFirstDocument ();
While (doc! = Null ){
// System. out. println ("================= name1 =" + doc. getItemValueString ("name1 "));
Vector items = doc. getItems ();
For (int j = 0; j <items. size (); j ++ ){
Item item = (Item) items. elementAt (j );

If (item! = Null & item. getType () = 1280) {// indicates text
System. out. println ("\ t" + item. getName () +
"= \" "+
Item. getValueString () + "\"");
} Else if (item! = Null & item. getType () = 1024) {// indicates the time
System. out. println ("\ t" + item. getName () +
"= \" "+
Item. getDateTimeValue () + "\"");
} Else if (item! = Null & item. getType () = 768) {// indicates that it is an integer.
System. out. println ("\ t" + item. getName () +
"= \" "+
Item. getValueInteger () + "\"");
} Else if (item! = Null & item. getType () = 1) {// indicates the rtf domain
Item itmWjbt = doc. getFirstItem ("$ FILE ");
If (itmWjbt! = Null ){
EmbeddedObject eo = doc. getAttachment (itmWjbt.
GetValueString ());
FileOutputStream out = new FileOutputStream (
"C:/" +
ItmWjbt.
GetValueString ());

InputStream in = eo. getInputStream ();
BufferedInputStream bufferedInputStream = new
BufferedInputStream (in );
BufferedOutputStream bufferedOutputStream = new
BufferedOutputStream (out );

Byte [] data = new byte [1];
While (bufferedInputStream. read (data )! =-1 ){
BufferedOutputStream. write (data );
}
// Write all the data in the buffer.
BufferedOutputStream. flush ();
// Close the stream
BufferedInputStream. close ();
BufferedOutputStream. close ();
}
}
}
System. out. println ("---------------------");
Doc. recycle ();
Doc = docList. getNextDocument ();
}
}

} Catch (NotesException ex ){
Ex. printStackTrace ();
} Catch (Exception ex1) {ex1.printStackTrace ();}
}

/**
* Insert a document
* @ Param db Database
*/
Public void insertDoc (Database db ){
// Insert a Document //////////////////
Document newDoc = null;
Try {
NewDoc = db. createDocument ();
NewDoc. appendItemValue ("Form", "form1"); // specify the Form
NewDoc. appendItemValue ("name1", "hello ");
NewDoc. appendItemValue ("name2", "2008-04-11 ");
NewDoc. appendItemValue ("name3", "100 ");
RichTextItem RRTI = (RichTextItem) newDoc. createRichTextItem (
"Name4 ");
String attachFilePath = "D:/test .doc ";
Ti. embedObject (EmbeddedObject. EMBED_ATTACHMENT, null,
AttachFilePath, attachFilePath); // Add an attachment
If (newDoc. save ()){
System. out. println ("document created and saved successfully ");
} Else {
System. out. println ("document creation and saving failed ");
}
} Catch (NotesException ex ){
Ex. printStackTrace ();
}
///////////////////////////////////////
}
}

The above programs passed the test in domino5.0.7. If the domino version is different, there may be a small problem. The key is to check whether the session can be obtained. If the operation fails, check the settings of the domino server carefully.

Iii. Glossary:

1. DIIOP:
IIOP is an Internet Inter-ORB Protocol, a transport layer Protocol. It is used on the Java 2.0 and compatible platform. The IIOP protocol is used to establish the following parts: an IIOP-to-HTTP gateway that allows the client to access WWW resources; an HTTP-to-IIOP gateway, through this gateway, you can access CORBA resources. A server that provides resources for IIOP and HTTP, and a browser that can use IIOP as a recognizable protocol.
Among them, ORB, Object Request Broker (Request Object proxy), a middleware. It can establish the client/server relationship between objects. Through ORB, a client can transparently reference a server object on the same machine or on the network. ORB explains the call and is responsible for finding an object that implements the request. After finding the object, it passes the parameter to the object, calls its method, and returns the result.
So what does DIIOP mean by Domino IIOP? It is a Server-side task. Through Domino ORB, the Domino Server interacts with Java applets, and both parties use IIOP to interact and exchange object data.

2. IOR:
IOR, Interoperable Object Reference.

Upload a file diiop_ior.txt on the dominoserver, which is in the c: \ lotus \ domino \ data \ domino \ html folder.

The client java program sends a CORBA Request to the domino server. The server returns the IOR string to the client through the HTTP protocol, and then the client communicates with the server through the IIOP protocol.

From this point of view, IOR is actually a string encoding of an object, containing the identification information for the Domino server's CORBA access. The client java program decodes the IOR string and can use it to find the corresponding host and establish a remote session.

3. Domino objects
The structure of Domino Object classes is based on the Inclusion model, which defines the object range. A container object is usually used to access its sub-objects.
Disabling a container object means that all its sub-objects will also be disabled. For example, you have created a Database object and used it to create a Document object. If the Database object is closed, the Document Object is also closed. If the container object times out, it will be automatically closed and its contained objects will also be automatically closed. Therefore, you should save any changes before the container object times out or closes.
4. Domino Database:
Databases in Domino are stored under a name. A collection contains documents and corresponding forms, views, and folder. Lotus. domino. Database is available in Java.

We can usually obtain the Database object instance through the getDatabase method of the session object or the getFirstDatabase/getNextDatabase method of the DbDirectory object.

5. Domino View:
The Database collection has various views. Lotus. domino. View is available in Java. You can use the getView method of the Database object to obtain the instance of the View object.

6. Domino Document:
Document in Domino refers to an entry in a Database, including fileds, text, numbers, graphics, and so on. Lotus. domino. Document is available in Java.

You can use the getView method of the Database object to obtain the instance of the View object.

Reference: http://www.ibm.com/developerworks/cn/lotus/ls-java_access_pt1/
Http://www.ibm.com/developerworks/cn/lotus/ls-java_access_2/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.