我使用下面的方法效果很好:我使用HttpURLConnection而不是BufferedWriter,并且在端口80上使用localhost直接与本地服务器通信。
这是我的代理代码:
import lotus.domino.Agentbase;import lotus.domino.Session;public class JavaAgent extends Agentbase { @Override public void NotesMain() { try { final String xpageName = "demo"; Session session = getSession(); dk.fmcgsolutions.XAgent.run(session.getAgentContext(), xpageName); } catch (Exception e) { e.printStackTrace(); } }}这是代理使用的XAgent类:
package dk.fmcgsolutions;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import lotus.domino.AgentContext;public class XAgent { public static void run(AgentContext agentContext, String xpageName) { try { String dbPath = agentContext.getCurrentDatabase().getFilePath(); String url = "http://localhost/" + dbPath + "/" + xpageName + ".xsp"; System.out.println("Starting " + xpageName + " in database " + dbPath); URL xPageURL = new URL(url); HttpURLConnection conn = (HttpURLConnection) xPageURL.openConnection(); conn.connect(); switch (conn.getResponseCode()) { case HttpURLConnection.HTTP_OK: // read from the urlconnection via the bufferedreader BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { System.out.println("Response: " + line); } bufferedReader.close(); break; case HttpURLConnection.HTTP_INTERNAL_ERROR: System.out.println("Interal server error while running"); break; default: System.out.println("An error occurred: " + conn.getResponseCode()); System.out.println("Error message: " + conn.getResponseMessage()); break; } conn.disconnect(); System.out.println("Finished " + xpageName + " in database " + dbPath); } catch (Exception e) { e.printStackTrace(); } }}代理需要以运行时安全级别2运行。



