如何使用 Lotus Notes API 从 Java 创建和运行代理

发布于 2024-09-06 02:45:50 字数 1802 浏览 3 评论 0原文

我正在尝试创建一个代理并运行它。我创建了两个类,一个扩展了 AgentBase,另一个是普通的主类。 我已经在第一类中编写了代理代码,并尝试从第二类中运行它。但我无法访问它。 我是这里的新手,任何指导将不胜感激。

Agent 类:

import lotus.domino.*;

import java.util.Vector;
import sun.management.Agent;

public class anagent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = 
          session.getAgentContext();

      // (Your code goes here) 

      System.out.println("I am an agent");
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

Main 类:

 public static void main(String [] args) throws NotesException {
Session session = null;
Database db = null;
        try {
        session =  NotesFactory.createSession(hostname,UserName, password);
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    boolean x = session.isValid();
    System.out.println("success- "+x);

    try {
        db = session.getDatabase(null,"LotusDB2.nsf");
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if(db.isOpen())
    System.out.println("database open");



        //Agent agnt = (Agent) a.firstElement();
    //agnt.toString();}
     //AgentContext agentContext = session.getAgentContext();
      // db = agentContext.getCurrentDatabase();
       Vector agents = db.getAgents();
       //lotus.domino.Agent agent = new lotus.domino.Agent();
       System.out.println("Agents in database:");
       if(agents.size()>0) System.out.println("some agents found");
       for (int i=0; i<agents.size(); i++)

       {

         lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);

I am trying to create an agent and run it. I have created two classes, one extends AgentBase and the other one is a normal main class.
I have written the code for agent in the 1st class and trying to run it from the second class. But I am not able to access it.
I am a complete novice here, any guidance would be appreciated.

Agent Class:

import lotus.domino.*;

import java.util.Vector;
import sun.management.Agent;

public class anagent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = 
          session.getAgentContext();

      // (Your code goes here) 

      System.out.println("I am an agent");
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

Main Class:

 public static void main(String [] args) throws NotesException {
Session session = null;
Database db = null;
        try {
        session =  NotesFactory.createSession(hostname,UserName, password);
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    boolean x = session.isValid();
    System.out.println("success- "+x);

    try {
        db = session.getDatabase(null,"LotusDB2.nsf");
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if(db.isOpen())
    System.out.println("database open");



        //Agent agnt = (Agent) a.firstElement();
    //agnt.toString();}
     //AgentContext agentContext = session.getAgentContext();
      // db = agentContext.getCurrentDatabase();
       Vector agents = db.getAgents();
       //lotus.domino.Agent agent = new lotus.domino.Agent();
       System.out.println("Agents in database:");
       if(agents.size()>0) System.out.println("some agents found");
       for (int i=0; i<agents.size(); i++)

       {

         lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沙沙粒小 2024-09-13 02:45:50

当您说无法访问代理时,是否收到错误消息?您不需要循环遍历代理集合来查找第一个代理 - 您可以使用 GetAgent("agentname"),然后使用 Agent.run()。如果您的 Java 代码似乎找到了代理并运行它,但没有任何反应,请检查服务器上的 log.nsf 数据库是否存在可能的错误

When you say you cannot access the agent, are you getting an error? You do not need to loop through the agent collection looking for the first agent - you can use GetAgent("agentname") and then Agent.run(). If your Java code seems to be finding the agent and running it, but nothing happens, check the log.nsf database on your server for possible errors

人生戏 2024-09-13 02:45:50

这两个链接是您浏览的一个很好的指南。它应该可以帮助您使用 eclipse 设计 java 代理。

ibm

LekkimWorld

These 2 links are a good guide for you to go through. It should help you design java agents using eclipse.

ibm

LekkimWorld

风吹短裙飘 2024-09-13 02:45:50

您已在 Notes 代理中定义了两个主要入口点,但是在 Notes 代理的上下文中,只有 NotesMain 会执行。静态 main 方法只会在 Notes 代理的上下文之外触发,例如在 Netbeans 或 Eclipse 等第 3 方 IDE 中运行该方法时。

为了让您的代码从 Notes Agent 的上下文中运行,只需修改 NotesMain 入口点即可完成您需要的所有工作。

另外..对 sun.management.Agent 的引用是什么?

import lotus.domino.*;
import java.util.Vector;

public class AnAgent extends AgentBase {

  public void NotesMain() {
     private Session m_session;
     private AgentContext m_agentContext;
     private Database m_db;

    try {

      m_session = getSession();
      m_agentContext =  m_session.getAgentContext();

      // (Your code goes here) 
      System.out.println("I am an agent");
      m_db = m_session.getDatabase("","LotusDB2.nsf");

       if(m_db.isOpen())
            System.out.println("database open");
            Vector agents = m_db.getAgents();

            if(agents != null && agents.size()>0) {
                System.out.println("some agents found");

                for (int i=0; i<agents.size(); i++) {
                    lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);
                    // whatever it is you are trying to do here...
                }
            }

    } catch(Exception e) {

      e.printStackTrace();

    }

  }

You have defined two main entry points in your notes agent, however in the context of a notes agent, only NotesMain will execute. The static main method would only fire outside of the context of a notes agent, such as when running this in a 3rd party IDE such as Netbeans or Eclipse.

For your code to run from the context of a Notes Agent, simply modify your NotesMain entry point to do all the work you need.

also.. what is that reference to sun.management.Agent for??

import lotus.domino.*;
import java.util.Vector;

public class AnAgent extends AgentBase {

  public void NotesMain() {
     private Session m_session;
     private AgentContext m_agentContext;
     private Database m_db;

    try {

      m_session = getSession();
      m_agentContext =  m_session.getAgentContext();

      // (Your code goes here) 
      System.out.println("I am an agent");
      m_db = m_session.getDatabase("","LotusDB2.nsf");

       if(m_db.isOpen())
            System.out.println("database open");
            Vector agents = m_db.getAgents();

            if(agents != null && agents.size()>0) {
                System.out.println("some agents found");

                for (int i=0; i<agents.size(); i++) {
                    lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);
                    // whatever it is you are trying to do here...
                }
            }

    } catch(Exception e) {

      e.printStackTrace();

    }

  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文