I've developed an OSGi bundle on Domino which should execute code in context of a user. There exists a lot of code in LotusScript also which is too much work to rewrite (Web agents). So I'm looking for a solution to run these web agents as user and grab the output (the prints). I've tried a lot but now I'm stuck that I can either run the agent as Agent Signer (result of session.effectiveUserName) and be able to grab the output or run the agent as the user but don't be able to grab the output. But because it's essential that the LotusScript code has to respect the reader fields, it must run as user. And because I need the output from the agent to do the rest in Java, I need a way to grab the StdOut also.
What I have tried so far:
OpenNTF Domino API: I can run agents as user but I can't grab the output (Or I don't know how)
String user = "Effective User/Acme"; TrustedSessionFactory factory = new TrustedSessionFactory(null); Sessions s = factory.createSession(user); Database db = .getDatabase(null, "path/db.nsf"); Agent ag = db.getAgent("LotusScript-Web-Agent") ag.run(); /* How can I grap the prints?? */
Darwino NAPI: I can't run agents as user but I can grab the output (Or I don't know how)
String user = "CN=Effective User Name/O=Acme"; String prints = null; NSFSession nsfSession = null; NSFDatabase nsfDb = null; NSFAgent nsfAg = null; RunContext runContext = null; try { DominoAPI napi = DominoAPI.get(); nsfSession = new NSFSession(napi, user, true, false); nsfDb = nsfSession.getDatabase(null, "path/db.nsf"); nsfAg = nsfDb.getDesign().getAgent("LotusScript-Web-Agent"); runContext = nsfAg.createRunContext(true); runContext.redirectOutput(AGENT_REDIR.MEMORY); runContext.documentContext(nsfNote); runContext.run(false); /* How can I run the agent as "Effective User/Acme" and not as agent signer ?? */ prints = runContext.getStdoutBuffer(); } finally { if (runContext != null) runContext.free(); if (nsfAg != null) nsfAg.free(); if (nsfDb != null) nsfDb.free(); if (nsfSession != null) nsfSession.free(); }
Domino-JNA: I can't run agents as user but I can grab the output (Or I don't know how)
String prints = NotesGC.runWithAutoGC(() -> { String user = "Effective User/Acme"; NotesDatabase ndb = new NotesDatabase(null, "path/db.nsf", user); NotesAgent ag = ndb.getAgent("LotusScript-Web-Agent"); Writer printWriter = new StringWriter(); NotesAgentRunContext narc = new NotesAgentRunContext(); narc.setUsername(user); narc.setCheckSecurity(true); narc.setOutputWriter(printWriter); ag.run(narc); /* How can I run the agent as "Effective User/Acme" and not as agent signer ?? */ return printWriter.toString(); });
Does anybody know a solution or can give me a hint to solve this situation?