Problem getting a session in java

I’m calling a java method from server side javascript similar to this tutorial (http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-26), but am having trouble getting a handle to a Notes session.

When I try to create the session from a NotesFactory I get: “NotesException: Cannot create a session from an agent”

If I go Session s = getSession(), s is null.

How do you get a handle to a session?

Thanks,

Scott.