如何使用 Lotus Notes API 从 Java 创建和运行代理
我正在尝试创建一个代理并运行它。我创建了两个类,一个扩展了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您说无法访问代理时,是否收到错误消息?您不需要循环遍历代理集合来查找第一个代理 - 您可以使用 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
这两个链接是您浏览的一个很好的指南。它应该可以帮助您使用 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
您已在 Notes 代理中定义了两个主要入口点,但是在 Notes 代理的上下文中,只有 NotesMain 会执行。静态 main 方法只会在 Notes 代理的上下文之外触发,例如在 Netbeans 或 Eclipse 等第 3 方 IDE 中运行该方法时。
为了让您的代码从 Notes Agent 的上下文中运行,只需修改 NotesMain 入口点即可完成您需要的所有工作。
另外..对 sun.management.Agent 的引用是什么?
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??