Search code examples
javalotus-domino

Returning 200 OK while agent is not done


I built an Java agent in IBM Domino which can receive a xml through HTTP POST. Now in the agent when I succesfully created a document with the data which I received as an extra I also execute code which puts data in to a third party software. The last part is taking some time like 10-30 seconds. The sender of the HTTP POST is waiting for a 200 OK response code, when it is waiting to long it will get a timeout error. Is there a way to send the 200 OK back before I will execute the code which will put data in to the third pary software. For example is this possible:

enter image description here

I was thinking of maybe running another agent (which puts data in the third party software) on a the server:

     String noteIdtemp = RequestDoc.getNoteID();        
     Agent ag2 = db.getAgent("test");       
     ag2.runOnServer(noteIdtemp); 

But this not seem to work and I am also getting an error:

09-02-2018 14:52:27   HTTP JVM: NotesException: Could not execute macro:
09-02-2018 14:52:27   HTTP JVM: Unsupported trigger and search in the background or embedded agent
09-02-2018 14:52:27   HTTP JVM:     at lotus.domino.local.Agent.runOnServer(Unknown Source)
09-02-2018 14:52:27   HTTP JVM:     at JavaAgent.NotesMain(Unknown Source)
09-02-2018 14:52:27   HTTP JVM:     at lotus.domino.AgentBase.runNotes(Unknown Source)
09-02-2018 14:52:27   HTTP JVM:     at lotus.domino.NotesThread.run(Unknown Source)

Any sugesstions would be welcome.


Solution

  • The error you are getting is because you don't have the properties of the second agent set properly for it to be used with RunOnServer. But RunOnServer won't solve your problem. Your first agent will wait for the second one.

    The way I would do this is, though, by having the first agent create and save a document in some database. I'm going to call that a "trigger document" (because that's exactly what I called it when I designed a system that used this trick almost 20 years ago).

    You can write the trigger doc to any database. It doesn't have to be the main database you're working in for your application. It can be if you want to set it up that way, but I'm going to assume it's a separate database because it's probably easier that way. I'll call it the AgentQueue db.

    You put your second agent into the AgentQueue database, and you set it up to run When documents are create or modified. The trigger document that you write into the AgentQueue needs to contain the information the second agent will need in order to feed your third-party proces - i.e., data fields submitted in your HTTP POST, unids of documents in your main application that are needed, etc. Y

    Your first agent saves the trigger document and exits - sending a 200 to the browser. The second agent will run soon - not necessarily immediately, as it will be subject to limits in the agent manager. Because only one copy of your second agent can run at a time, the best way to write is to have it look for multiple unprocessed trigger documents in its database and deal with them all instead of just processing one document and terminating. Once it's done processing a trigger doc, it either marks it as "Done" and saves it, or just deletes it. It can be useful to save it because your second agent can write progress and debug info to that doc if you want.