Search code examples
javasecurityxpageslotus-dominoagent

Domino Agent issues when running in Notes Client - works fine on server


I have a java agent that makes http requests using jsoup, This agent works fine when I trigger it manually from the server console. but will give an error when I run it on the client, (right click on agent and run)

  • The agent is set to option 2. Allow restricted operations, and is set to "Action menu selection" and Target "All documents in database"
  • I have set the same security settings in my java.policy file on both the server and the client. I also tried to run my agent on a server with a "standard" java.policy file and that worked also so the problem do not seem to be related to the java.policy file.

This is the error I get in the Java debug console when I run the agent in notes client (v9.0.1)

java.lang.NullPointerException
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:727)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:654)
at COM.ibm.JEmpower.applet.http.HttpURLConnection.getInputStream(HttpURLConnection.java:411)
at COM.ibm.JEmpower.applet.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:703)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:399)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:453)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)

this is the java.policy settings I use in my Notes client (and on some servers)

grant { permission java.util.PropertyPermission "http.keepAlive", "read, write"; };

grant { permission java.security.AllPermission; }

Here is the agent code

public class JavaAgent extends AgentBase {

public void NotesMain() {

  try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      Database db = session.getCurrentDatabase();
      lotus.domino.Document d = db.getView("inbox").getFirstDocument();

      String url = d.getItemValueString("Subject"); 
      Document x = Jsoup.connect(url).userAgent("Mozilla").get();
      Elements p = x.select("p");
      RichTextItem rt = (RichTextItem) d.getFirstItem("Body");
      rt.appendText(p.text());
      d.replaceItemValue("Processed", "1");
      d.save();

  } catch(Exception e) {
      e.printStackTrace();
   }

} }

How can I get the agent to run on my local Notes client?


Solution

  • Read this: Java Agent HTTP Connection Errors
    This solved the problem for me.

    After many restarts and toggled settings, and much pulling of hair, I was able to find a set of steps that would either cause the problem or prevent it. To make the code work:

    1. Open the Notes client
    2. Run the Java agent
    3. HTTP connection works

    To get the error:

    1. Open the Notes client
    2. Open the Java Debug Console
    3. Run the Java agent
    4. HTTP connection fails

    There's something about opening the Java Debug Console before running the agent that causes Notes to use a COM.ibm.JEmpower.applet.http.HttpURLConnection to make the connection instead of a sun.net.www.protocol.http.HttpURLConnection, and the JEmpower version of the class is the one that's broken (per experimentation and the APAR mentioned previously).

    Oddly, if I run the agent and then open the debug console and then run the agent again, everything is fine. It's opening the debug console before I do anything that causes problems.