【问题标题】:How to schedule an Xagent from a Domino Java agent?如何从 Domino Java 代理调度 Xagent?
【发布时间】:2016-03-31 17:54:38
【问题描述】:

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

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

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

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

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

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

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

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

有什么想法吗?

【问题讨论】:

  • 通过服务器控制台运行代理时收到什么消息?
  • 您使用 (1, 2, 3) 运行代理的安全级别是多少?
  • 实际上现在在客户开发服务器上盲目运行。控制台访问不是那里的选项。需要移动到测试服务器。
  • @Eric 我的 id 在服务器上具有受限和非受限权限。不知道是什么级别
  • 我只是让代理调用本地主机上的 xagent(具有适当的 Internet 站点)。那么代理不需要ssl。请改用这种方法。

标签: java xpages


【解决方案1】:

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

【讨论】:

  • 此站点当前通过 Web 配置设置。使用 Web 配置时还可以设置本地 Internet 站点吗?你是怎么做到的?
  • 当然。只需使用“localhost”作为域名。
  • 谢谢 Per,我会试试...现在需要和管理员谈谈!
  • 会不会是网络服务器上的 SSL 密码对于 java 代理来说太强大了?
  • @umeli 你的问题是针对问题而不是我的答案,我想。
猜你喜欢
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多