简体   繁体   中英

Calling Java agent from LotusScript in XPages upload

I'm uploading a file using an XPage with the standard file upload control. On the datasource I have a WebQuerySave agent.

WQS-agent is in LotusScript.

The user is uploading an XML file and we've got an existing helper library to help parse the XML being uploaded - that's why the WQS is in LotusScript.

Since I cant detach the uploaded file to the server, I'm calling a Java agent to just read the XML to a string and store that in the document.

I'm calling the Java agent using a param document, all basic stuff.

In the param doc I include the UniversalID of the document that contains the attachment and here's my problem!

The Java agent claims that the UniversalID is invalid:

"HTTP JVM: 4091 Invalid universal id"

But if I try to locate the document in the LotusScript agent, before calling the Java agent the document is found using the same UNID: Set tempDoc = db.Getdocumentbyunid(unid)

The Java code:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import lotus.domino.Agent;
import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.Session;

public class JavaAgent extends AgentBase {
    public void NotesMain() {
        try {
            Session session = getSession();
            AgentContext agentContext = session.getAgentContext();
            Database db = agentContext.getCurrentDatabase();
            Agent agent = agentContext.getCurrentAgent();

            // Get document used for passing data
            System.out.println(agent.getParameterDocID());

            Document paramDoc = db.getDocumentByID(agent.getParameterDocID());
            String UniversalID = paramDoc.getItemValueString("unid");

            System.out.println(UniversalID);
            Document doc = db.getDocumentByUNID(UniversalID);

When I run the Java agent I won't get anything from the print commands, but maybe that's expected...(?)

If I run everything manually on an existing document it works. But not on a document submitted thru the browsers.

To me it feels like the document containing the attachment isn't ready yet to Java.

Domino 8.5.3

Any help very much appreciated!

/J

PS I'm a Java newbie, so U know.. ;-)

Are you able to use the Extension Library with the extlibx packages? If so, there's an XML parser already inbuilt, sbt.XmlNavigator. See chapter 13 of XPages Extension Library book. It may be worth looking at to avoid calling a LotusScript agent that calls a Java agent. You can use those packages from Java, but you can also use SSJS. It may be easier to rip the bandaid off and use that (or another Java-based XML parser, I'm sure there are a few). It may be a bit of work now, but will be more useful for the future.

I seem to remember that the context document has a temporary UNID that is changed to its permanent value when you call the save() method. So my best guess is that your LotusScript code is reading the universalId property of the context document before you save it.

So if I'm right, just move your call to get universalId property in the LotusScript agent until after you save the context document, and pass that value into your Java agent.

请记住在将paramDoc传递给Java代理之前将其保存在LotusScript代理中。

The only way I could solve it was to copy all items from the documentContext into a new document I created in the database.

  • Save that
  • Retrieve the UNID for this new document
  • Pass that to agent.run - java and it worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM