Imported Java agent
I saw a post on Lotus developerWorks asking for help on creating an imported Java agent. Since I have seen this question so many times I finally decided to create an example.
I case you didn't know you can create Java agents in two ways in Domino Designer:
- Write the agent in Domino Designer (this is the most common way to write a Java agent).
- Import compiled code into Domino Designer.
When creating an agent with imported code you must make sure that one of the classes extend the lotus.domino.AgentBase class. When the agent is run in Notes an instance of this class is created and the NotesMain() method is called. As you can see in the first screenshot I have written a simple agent in Eclipse. The class (dk.heisterberg.lekkim.blog.TestAgent) extend lotus.domino.AgentBase and have some simple Java code in he NotesMain() method. Apart from being a requirement, one of the advantages of extending AgentBase is that you do not have to worry about threads and how to get a Session object (you can simply call getSession() as shown in the example).
Once you have compiled the agent (automatically done if using Eclipse) you create a zip-/jar-file with the compiled classes. Make sure to include the entire package hierarchy if you are using packages. Then create an agent in Domino Designer, set the type to "Imported Java" and click the "Import Class Files..." as shown below.
In the dialog box you select the zip-/jar-file you created and add it to the right pane. Then, and this is the important point here, specify the class that extend the lotus.domino.AgentBase class in the "Base class" field. Remember to include the package name if you are using packages.
Click OK and verify the choices you made in the dialog box has been set correctly.
Give the agent a name, set the desired agent trigger and save the agent. That's it!
The example database is available for download.
Re: Imported Java agent
Re: Imported Java agent
Re: Imported Java agent
You have to understand that Domino agent runs under a specialized Java SecurityManager (COM.ibm.JEmpower.applet.AppletSecurity) that enforces the agent security model. The SecurityManager for example enforce that you cannot read or write a file on disk from an agent not allowed access to restricted operations (see the second tab of the agent properties). It also enforce that you do not use operations that are illegal from a Domino point of view such as System.exit().
My recommendation is to set the agent to run with full priviledges for starters to see if that solves the problem. That is normally the easiest way to see if the problems are SecurityManager related. In your case I guess they are due to the reference to COM.ibm.JEmpower.applet.AppletSecurity in the stacktrace.
You cannot install your own SecurityManager so don't even try to go down that path... :-)
/lekkim
Re: Imported Java agent
Re: Imported Java agent
Well there is nothing special about reading property or xml-files from a Java agent as long as the file is packaged with the agent. You simply load the resource as a stream (see text in bold):
import lotus.domino.*;
import java.util.*;
import java.io.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Properties p = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("lekkim.properties");
p.load(in);
System.out.println(p.getProperty("firstname") + " " + p.getProperty("lastname"));
} catch(Exception e) {
e.printStackTrace();
}
}
}
This is code from a standard Java agent not allowed to use restricted operations and it runs without any issues. I have simply added a properties file (lekkim.properties) to the agent using the "Edit Project" button. I'm using a normal Java agent to test this.
My guess is that the stacktrace you are seeing is not from trying to read the files but from another source. If you look at the stacktrace the problem is your call to java.lang.System.exit() which is illegal in Notes.
If it was me I would break down the agent into some smaller parts and make sure that you can read the properties file correctly. Then try using your bean to get and parse the xml-file. Take small steps to get acquinted with the environment.
Re: Imported Java agent
Re: Imported Java agent
Your agent is probably is creating some additional threads to the one (NotesThread) created as part of extending lotus.domino.AgentBase. If you have multiple threads in your agent make sure that the one creating the lotus.domino.Session class is the last one to be terminted. One solution is to use a separate ThreadGroup.
The error normally occurs because a thread is still running when the Domino Amgr is terminating the agent thread.
/lekkim
Re: Imported Java agent
Re: Imported Java agent
Re: Imported Java agent
Re: Imported Java agent
Re: Imported Java agent
Well I wrote a piece on managing external dependencies which is basically what you're asking about.
You cannot share script libraries among different databases, that is databases with different replica id. There are of causes ways around this but using the normal approach it isn't possible. If using the same database the list of script libraries should be the same on the server as on the local machine unless you did something with your replication.





