One of the things I really miss in Domino is a UserSession object. Any ‘mature’ web development environment supports them, but Domino’s Session object is a locked object. There is nothing you can add to it.

Now, when you really need something like that you have a problem with Domino. There are several ways around it (don’t you also have the feeling that developing for Domino is a lot of ‘working your way around things’?):

Store the user data in a profile document and retrieve that every time an agent runs

Store the data in a ‘normal’ document and retrieve that every time an agent runs

Use a servlet instead and use the methods you get with servlets for session handling

Or do it way I implemented it in the end using java agents:

I created what I call a ‘ControllerFramework’. The way you execute code in that framework differs a bit from the ‘normal’ way code is handled in Domino.

Take a look at this url:

http://server/database.nsf/controller?openagent&do=Test

This will execute the ‘Test’ method in the controller framework. The controller agent itself consist of ridiculous less code:

Session session = getSession();

Executer executer = new Executer();

executer.execute(session,getAgentOutput());

That’s all there is to it.

All the magic happens in the execute class. In there I parse the URL, the Context Document, and several more things, and initialize the userSession. The usersessions are serialized to disk and checked for expiration etc. etc. Everytime the class is run it will retrieve the userSession and initialize all the objects in there for you to use. I set a specific cookie in the browser to keep track of the usersession.

The Test class looks like this:


public class Test extends ActionClass
{
public void execute()
{    
String address = request.getParameterValue(“address”);    
userSession.addObject(“address”,address);    
response.setContent(“Address has been stored in session object!”);
}
}

Notice that Test extends ActionClass. The executer creates a new instance of Test, initializes all the necessary objects in there (like request, response, userSession) and runs the execute method in the Test class. When done executing it will parse response, and outputs any text if there is anything to output.

Goodies you can find in the ‘ActionClass’ are:

  • userSession
  • request
  • response

In ‘userSession’ you can find things like:

  • getObject(String);
  • addObject(String, Object);

In ‘request’ there are things like:

  • getCookie(String);
  • getAuthenticatedUser();
  • getCurrentDatabase();
  • getDocumentContext();
  • getParameterValue();

In ‘response’ there are things like:

  • setCookie(String);
  • setContent(String);
  • setContentType(String);
  • redirect(String);

All in all I think a nice set of methods and classes that make your life as developer much easier. What I do is that I create a java script library (not javascript script library), add those to the controller agent, and of you go. Simple as that.

It’s not ideal, but given the situation, I think it’s still a very nice solution. I wish I could share all the libraries with you, but as I’m developing this for a client, I’m restricted in doing that.

Now let’s hope that Domino 8 will have this all on board out of the box.