Trying to get an Xagent to run on schedule by triggering from a scheduled Java agent.
The following is the code for my xagentmail.xsp which simply sends me an email:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
<xp:this.beforePageLoad><![CDATA[#{javascript:
// test send mail
doc = database.createDocument() ;
doc.replaceItemValue("Form", "memo");
doc.replaceItemValue("Subject", " from xagentmail.xsp");
doc.replaceItemValue("SendTo", "PDella-Nebbia@testdomain.com");
doc.send();
}]]></xp:this.beforePageLoad>
</xp:view>
Using the SSL-ENCRYPTED connection approach described in Devin Olson's blog, Scheduled Xagents, I created the following scheduled Domino Java agent:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import javax.net.ssl.SSLSocketFactory;
import lotus.domino.AgentBase;
public class JavaAgent extends AgentBase {
// Change these settings below to your setup as required.
static final String hostName = "server1.testdomain.com";
static final String urlFilepath = "/test/poidemo.nsf/xagentmail.xsp";
static final int sslPort = 443;
public void NotesMain() {
try {
final SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final Socket socket = factory.createSocket(JavaAgent.hostName, JavaAgent.sslPort);
final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
final StringBuilder sb = new StringBuilder();
sb.append("GET ");
sb.append(JavaAgent.urlFilepath);
sb.append(" HTTP/1.1\n");
final String command = sb.toString();
sb.setLength(0);
sb.append("Host: ");
sb.append(JavaAgent.hostName);
sb.append("\n\n");
final String hostinfo = sb.toString();
out.write(command);
out.write(hostinfo);
out.flush();
in.close();
out.close();
socket.close();
} catch (final Exception e) {
// YOUR_EXCEPTION_HANDLING_CODE
}
}
}
When I enter the URL in a browser to my xagentmail.xsp I get mail as expected.
But my scheduled Java agent is not triggering the Xagent to send the mail.
I did set the Anonymous access to Reader for the application with both the agent and xagent. I also have restricted and non-restricted privileges on the server.
Any ideas?
I use the following approach which works great: I use HttpURLConnection instead of a BufferedWriter and I use localhost on port 80 to talk directly with the server locally.
Here's my agent code:
And here's the XAgent class that the agent uses:
The agent needs to run with runtime security level 2.