如何从Domino Java代理安排Xagent?

时间:2016-03-31 17:54:39

标签: java xpages

尝试通过从计划的Java代理触发来使Xagent按计划运行。

以下是我的xagentmail.xsp的代码,它只是给我发了一封电子邮件:

test_bar_1(path.to.test.Foo) this is a docstring 1 ... ok
test_bar_2(path.to.test.Foo) this is a docstring 2 ... Fail

使用Devin Olson博客Scheduled Xagents中描述的SSL-ENCRYPTED连接方法,我创建了以下计划的Domino Java代理:

<?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>

当我在浏览器中输入我的xagentmail.xsp的URL时,我按预期收到邮件。

但是我的预定Java代理没有触发Xagent发送邮件。

我确实使用代理和xagent为应用程序设置了对Reader的匿名访问。我在服务器上也有限制和非限制权限。

有什么想法吗?

1 个答案:

答案 0 :(得分:7)

我使用以下方法效果很好:我使用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运行。