Search code examples
javaservletslotus-noteslotus-domino

A Lotus Domino Servlet gives me this error: "Cannot create a session from an agent"


I create a servlet in a Lotus Notes database on a Lotus Domino 9.0 IF5 server. The source code was taken from a tutorial page. Also, the servlet was developed in Domino Designer

This is the most important source code:

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lotus.domino.*;
[...]

public class TestServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse res) {
    try {
        res.setContentType("text/html");        
            PrintWriter toBrowser = res.getWriter();        
            [...]
            try {    
                NotesThread.sinitThread();        
                Session s = NotesFactory.createSession();    //<== ERROR
                Database db = s.getDatabase("","names.nsf");        
                toBrowser.println(db.getTitle());        
                [...]
            }    
            catch (NotesException n) {
                System.out.println("Exception ID:  " + n.id);        
                System.out.println("Exception description:  " + n.text);
                n.printStackTrace();
            }    
            [...]
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}

When I call the servlet, I get this message on the server console.

13/08/2014 04:31:43   HTTP JVM: Exception ID:  4493
13/08/2014 04:31:43   HTTP JVM: Exception description:  Cannot create a session from an agent
13/08/2014 04:31:43   HTTP JVM: NotesException: Cannot create a session from an agent
13/08/2014 04:31:43   HTTP JVM:        at lotus.domino.local.Session.checkSecurityManagerExtender(Unknown Source)
13/08/2014 04:31:43   HTTP JVM:        at lotus.domino.local.Session.createSession(Unknown Source)
13/08/2014 04:31:43   HTTP JVM:        at lotus.domino.NotesFactory.createSession(Unknown Source)
[...]

If I write the servlet without the Lotus Notes code (Session, Database, Document, etc.) it works fine. I can do everything I want always I do not use the Lotus Domino objects. But if I add that lines, the error occurs.

What would be the problem?

TIA,

EDIT:

This how it looks the servlet on Domino Designer. I wrote it in a Notes DB, no outside as an standalone file.

The servlet in Domino Designer


Solution

  • When you calling to NotesFactory.createSession() the user is prompted for a password as required. But it seems that there are some problem with prompting an user. So, you must manually provide the UserName and Password:

    Session s = NotesFactory.createSession(null, "UserName", "Password");
    

    Or use some another methods as mentioned in Documentation, for example:

    Session s = NotesFactory.createSessionWithFullAccess("Password");
    //or
    Session s = NotesFactory.createSession(null, "", "");
    //or
    Session s = NotesFactory.createSession(hostString, HttpServletRequest);
    //etc