次の例では、Domino クラスを使用する Java™ プログラムに最低限必要なコードを示します。この例は、Session オブジェクトをインスタンス化して、getPlatform メソッドで Platform プロパティを String 型で出力します。
import lotus.domino.*;
public class platform1 extends NotesThread
{
public static void main(String argv[])
{
platform1 t = new platform1();
t.start();
}
public void runNotes()
{
try
{
Session s = NotesFactory.createSession();
// To bypass Readers fields restrictions
// Session s = NotesFactory.createSessionWithFullAccess();
String p = s.getPlatform();
System.out.println("Platform = " + p);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import lotus.domino.*;
public class platform2 implements Runnable
{
public static void main(String argv[])
{
platform2 t = new platform2();
NotesThread nt = new NotesThread((Runnable)t);
nt.start();
}
public void run()
{
try
{
Session s = NotesFactory.createSession();
String p = s.getPlatform();
System.out.println("Platform = " + p);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import lotus.domino.*;
public class platform3
{
public static void main(String argv[])
{
try
{
NotesThread.sinitThread();
Session s = NotesFactory.createSession();
String p = s.getPlatform();
System.out.println("Platform = " + p);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
NotesThread.stermThread();
}
}
}
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext =
session.getAgentContext();
// (Your code goes here)
String p = session.getPlatform();
System.out.println("Platform = " + p);
} catch(Exception e) {
e.printStackTrace();
}
}
}
import lotus.domino.*;
public class platform4 extends AgentBase
{
public void NotesMain()
{
try
{
Session s = getSession();
String p = s.getPlatform();
System.out.println("Platform =" + p);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import lotus.domino.*;
import java.io.PrintWriter;
public class platform5 extends AgentBase
{
public void NotesMain()
{
try
{
Session s = getSession();
String p = s.getPlatform();
PrintWriter pw = getAgentOutput();
pw.println("Platform = " + p);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import lotus.domino.*;
public class platform6 implements Runnable
{
String host=null, user="", pwd="";
public static void main(String argv[])
{
if(argv.length<1)
{
System.out.println(
"Need to supply Domino server name");
return;
}
platform6 t = new platform6(argv);
Thread nt = new Thread((Runnable)t);
nt.start();
}
public platform6(String argv[])
{
host = argv[0];
if(argv.length >= 2) user = argv[1];
if(argv.length >= 3) pwd = argv[2];
}
public void run()
{
try
{
Session s = NotesFactory.createSession(
host, user, pwd);
String p = s.getPlatform();
System.out.println("Platform = " + p);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Session s = NotesFactory.createSession(
host, user, pwd);
以下に書き換え:
String args[] = new String[1];
args[0] = "-ORBEnableSSLSecurity";
Session s = NotesFactory.createSession(
host, args, user, pwd);
TrustedCerts.class (通常はサーバーのデータディレクトリの domino¥java にあります) は、classpath になければなりません。このファイルは、DIIOP タスクの起動時にこのタスクによって生成されます。
SSL をアプレット用に有効にするためには、[Java アプレットのプロパティ] ダイアログボックスの [CORBA SSL セキュリティを使用] も有効にする必要があります。
import lotus.domino.*;
public class foo extends AppletBase
{
java.awt.TextArea ta;
public void notesAppletInit()
{
setLayout(null);
setSize(100,100);
ta = new java.awt.TextArea();
ta.setBounds(0,0,98,98);
add(ta);
ta.setEditable(false);
setVisible(true);
}
public void notesAppletStart()
{
Session s = null;
try
{
// Can also do openSession(user, pwd)
s = this.openSession();
if (s == null) { //not able to make connection, warn user
ta.append("Unable to create a session with the server");
return;
}
String p = s.getPlatform();
ta.append("Platform = " + p);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {this.closeSession(s);}
catch(NotesException e) {e.printStackTrace();}
}
}
}
import lotus.domino.*;
import java.awt.*;
import java.awt.event.*;
public class awt extends AppletBase implements ActionListener
{
private Button b;
private String text = "";
Graphics g;
public java.awt.TextArea ta;
public Session s;
public void notesAppletInit()
{
g = getGraphics();
b = new Button("Get user common name");
add(b);
ta = new java.awt.TextArea(15, 30);
add(ta);
setVisible(true);
}
public void paint(Graphics g)
{
b.setLocation(0, 0);
ta.setLocation(200, 0);
}
public void notesAppletStart()
{
try
{
s = this.getSession();
b.addActionListener(this);
}
catch(NotesException e)
{
text = e.id + " " + e.text;
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
text = "";
getTheName();
ta.append(text + "¥n");
}
public void getTheName()
{
try
{
if (isNotesLocal())
{
NotesThread.sinitThread();
}
text = "User " + s.getCommonUserName();
}
catch(NotesException e)
{
text = e.id + " " + e.text;
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if (isNotesLocal())
{
NotesThread.stermThread();
}
}
}
}
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Session s2 = NotesFactory.createSession("test5.irish.com",
session.getSessionToken());
System.out.println("remote session name = " + s2.getUserName());
} catch(Exception e) {
e.printStackTrace();
}
}
}
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Session s2 = NotesFactory.createSession("test5.irish.com",
session.getSessionToken("test5.irish.com"));
System.out.println("remote session name = " + s2.getUserName());
} catch(Exception e) {
e.printStackTrace();
}
}
}
import java.lang.*;
import java.lang.reflect.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import lotus.domino.*;
public class Cookies extends HttpServlet
{
private void respond(HttpServletResponse response, String entity)
throws IOException
{
response.setContentType("text/plain");
if (entity == null)
{ response.setContentLength(0);}
else
{
response.setContentLength(entity.length() + 1);
ServletOutputStream out = response.getOutputStream();
out.println(entity);
}
}
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String s1 = "";
Cookie[] cookies = null;
String sessionToken = null;
try
{
cookies = request.getCookies();
}
catch (Exception e)
{
respond(response,"Exception from request.getCookies(): " +
e.toString());
return;
}
if (cookies == null)
{
s1 = "No cookies received";
}
else
{
for (int i = 0; i < cookies.length; i++)
{
if (cookies[i].getName().equals("LtpaToken"))
{
sessionToken = cookies[i].getValue();
}
}
}
if (sessionToken != null)
{
try
{
NotesThread.sinitThread();
Session session = NotesFactory.createSession(null, sessionToken);
s1 += "¥n" + "Server: " + session.getServerName();
s1 += "¥n" + "IsOnServer: " + session.isOnServer();
s1 += "¥n" + "CommonUserName: " + session.getCommonUserName();
s1 += "¥n" + "UserName: " + session.getUserName();
s1 += "¥n" + "NotesVersion: " + session.getNotesVersion();
s1 += "¥n" + "Platform: " + session.getPlatform();
NotesThread.stermThread();
}
catch (NotesException e)
{
s1 += "¥n" + e.id + e.text;
e.printStackTrace();
}
}
respond(response,s1);
}
}
org.omg.SecurityLevel2.Credentials credentials =
loginHelper.request_login("Jane Doe", "", "password",
new org.omg.SecurityLevel2.CredentialsHolder(),
new org.omg.Security.OpaqueHolder());
Session s = NotesFactory.createSession("test5.iris.com", credentials);
System.out.println("Got Session for " + s.getUserName());
import lotus.domino.*;
public class HelloBean extends Object implements SessionBean {
... /* See HelloBean.java from Websphere for the complete class code */
/**
Returns the greeting. But has been modified to create a remote session to the
Domino server.
@return The greeting.
@exception RemoteException Thrown if the remote method call fails.
*/
public String getMessage () throws RemoteException
{
String result = "hello bean ";
try {
Session s = NotesFactory.createSession("test5.iris.com", null);
result = result + " -- Got Session for " + s.getUserName();
}
catch (NotesException ne)
{
result = result + "-- " + ne.text;
result = result + "-- failed to get session for user";
}
return (String) result + " -- done";
}
}