莲花笔记中agent.runonserver异常

Exception in agent.runonserver in lotus notes

我有从 lotusscript 代理调用 java 代理的代码

Sub insertDealDetails() 
    On Error GoTo errhandler
    MsgBox "inside deal details"
    Dim agent As NotesAgent
    On Error GoTo errhandler
    Set agent = db.GetAgent("Procs")
    If agent.RunOnServer(doc.Noteid) = 0 Then
        MessageBox "Agent ran",, "Success"
    Else
        MessageBox "Agent did not run",, "Failure"
    End If
    Exit Sub

errhandler:
    MsgBox  "Error in function insertDealDetails in agtSubmit Agent" & Erl & Error

End Sub

现在,如果 Procs 代理发生任何异常,如何向调用 insertDealDetails() 的主代理提供异常,以便它停止主代理。

使用 In-Memory Document,
在 Java 代理和
中将您的错误消息写入此文档 阅读 LotusScript 代码中的错误消息。

LotusScript

Call agent.RunWithDocumentContext(doc)
If doc.ErrorMessage(0) <> "" Then
    print doc.ErrorMessage(0)
    ' handle the error
End If

Java代理

Document doc = agentContext.getDocumentContext();
...
doc.replaceItemValue("ErrorMessage", "Your Error Message from Java Agent");

您不需要随时保存 In-Memory 文档。

这是更新的代码

`Sub insertDealDetails() 
    On Error GoTo errhandler
    MsgBox "inside deal details"
    Dim agent As NotesAgent
    Dim in_doc As Notesdocument
    On Error GoTo errhandler
    Set agent = db.GetAgent("Procs")
    Set in_doc = db.createDocument()
    If agent.Runwithdocumentcontext(in_doc,doc.Noteid) Then`
        MsgBox "doc.ErrorMessage(0):::::::::"&in_doc.ErrorMessage(0)
        If in_doc.ErrorMessage(0)<>"" Then
            Call prompt("2")
        End If
    End If

Exit Sub
errhandler:
    MsgBox  "Error in function insertDealDetails in agtSubmit Agent" & Erl & Error

End Sub

现在的问题是它没有从 Procs 中调用的 java 代码返回 agent.What 我在这里做错了。

public class JavaAgent extends AgentBase {


    public void NotesMain() {
        Connection con = null;
        CallableStatement stmt = null;
        Database db;
        lotus.domino.Document doc = null;
        try {
            Session session = getSession();
            AgentContext agentContext = session.getAgentContext();
            doc = agentContext.getDocumentContext();
            con = JavaAgent.getConnection(); //making connectiion here
            //executing code here and exception occurs
            System.out.println("success");

        } catch(Exception e) {
            try {
                doc.replaceItemValue("ErrorMessage", e.getMessage());
            } catch (NotesException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        }finally{
            try {
                stmt.close();
                con.close();
            } catch (SQLException e) {
                try {
                    doc.replaceItemValue("ErrorMessage", e.getMessage());
                } catch (NotesException e1) {
                    e1.printStackTrace();
                }
                e.printStackTrace();
            }
        }
    }
}

同样的日志如下:

**[0DCC:01AD-053C] 01/27/2016 01:24:56 PM  HTTP JVM: class load: JavaAgent from: <unknown>
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM  HTTP JVM: before connection:::::
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM  HTTP JVM: inside dobi
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM  HTTP JVM: inside dobi 2
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM: inside dobi 3
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM: after connection:::::Oracle Database 11g Release 11.1.0.0.0 - Production
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM: message is Invalid column index
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM: java.sql.SQLException: Invalid column index
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4596)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at oracle.jdbc.driver.OracleCallableStatement.setString(OracleCallableStatement.java:4249)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at JavaAgent.NotesMain(Unknown Source)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at lotus.domino.AgentBase.runNotes(Unknown Source)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM  HTTP JVM:  at lotus.domino.NotesThread.run(Unknown Source)
[0DF8:000A-0F84] Router: DNS server returned an error searching for MX records. The destination domain may not exist: 11.17.108.223, Error: Not implemented(NOTIMP)**

相同步骤的工作代码如下:

%REM
    Sub insertDetailsOracle
    Description: To insert details in Oracle Table
    Date: 28/03/2014

    '******************* Logic ***************************
    'Validation In submit agent
    '1)Create in-memory document
    '2)Run java agent with Runwithdocumentcontext passing newly created  in-memory document 
    '  as well as note-id of original request document context

    'If pass i.e. no exceptions in Java agent
    '1) submit the Case

     'Else
     '1) Log Error message and exit the agent

    '***************************************************

%END REM

Function  insertDetailsOracle() As String 
    On Error GoTo errhandler
    Dim agent As NotesAgent
    Dim agentValue As Boolean

    Set agent = db.GetAgent("Procs")

    'Create in-memory document
    Set in_doc = db.createDocument()

    'Running java agent with Runwithdocumentcontext
    agentValue = agent.Runwithdocumentcontext(in_doc,doc.Noteid)

    'Return error message as per message passed by java agent in in-memory document's field
    If in_doc.ErrorMessage(0)<>"" Then
        insertDealDetails = in_doc.ErrorMessage(0)
    Else
        insertDealDetails = "1"
    End If

    Exit Function
errhandler:
    MsgBox  "Error in function insertDealDetailsOracle in agtSubmit Agent" & Erl & Error
End Function

java方法与下面相同。