Domino Code Fragment

Code Name*
Debugging Notes Java Code
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.13.58.137.218
Description*
Debugs your Notes Java Agents
Type*
Java
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

The idea behind the following is that a context document is created in AgentRunner.Nsf that will allow you to run your notes agent as a stand-alone Java code (as if it were your agent) from the windows command line. Because you can now run it as a stand-alone code you can use your debugger in Visual Age or Java Cafe or Java Workshop to run the code and step through the variables.

Lets get started.

1.) Copy AgentRunner.Nsf to your Notes data directory.

2.) Compile the following Java files (DebugAgentContext.java, DebugDocumentCollection.java,
DebugSession.java) and copy to your Java classes directory.

3.) Edit MyAgent.java and save-as some other Java file (here I use TestAgent.java).

4.) Edit TestAgent.java you will see the following statements:
private static String keyServer = "Local";
private static String keyDatabase = "c:\\lotus\\notes\\data\\JavaTest.nsf";
private static String keyAgent = "MyAgent";


5.) You can edit the above statements to point to one of your databases I used the following database
private static String keyServer = "Local";
private static String keyDatabase = "c:\\notes\\data\\Foreign.nsf";
private static String keyAgent = "TestAgent";


6.) Write your agent code inside of the following statements in TestAgent.java where the your agent code
goes here comment is.

public void NotesMain()
{
try
{
Session s = this.getSession();


if (s != null)
{
// your agent code goes here...
}
}


7.) I created the following code:

public void NotesMain()
{
try
{
Session s = this.getSession();


if (s != null)
{
AgentContext ac = s.getAgentContext();
Database db = ac.getCurrentDatabase();
DocumentCollection dc = ac.getUnprocessedDocuments();
System.out.println("We found " + dc.getCount() + " documents.");
Document doc = dc.getFirstDocument();
while(doc!=null)
{
System.out.println("Form = " + doc.getItemValueString("Form"));
doc = dc.getNextDocument(doc);
}
}
}


8.) Compile TestAgent.java.

9.) Open your database you defined in step 5. and create an agent called TestAgent set to
manual and to act on all documents in the database.

10.) Set the agent to run Java and import the following classes: DebugAgentContext,
DebugDocumentCollection, DebugSession and TestAgent.

11.) Set the base class to TestAgent.

12.) Run TestAgent in your database.

13.) Open the database AgentRunner.nsf, you should see a document for the agent that you ran.

14.) Now open a command line window and run the TestAgent.class (Java TestAgent).
Note: Ensure that the notes directory is in your path or you will get a link error

15.) You should see your output.

16.) Now load your Java debugger (Visual Age, Java Cafe..ect) and run TestJava.class and you should
see all the variables.

17.) When you are satisfied that your code is correct you go back into your TestAgent.java and change
the following line change true to false (this allows you to run your agent in notes without creating a
context document in the AgentRunner.nsf database.
private static boolean dumpAgentContext = true;

Oh almost forgot here is your file :-)

dtjava.zip