Mike, the most likely reason you're triggering an ECL exception is because the code you posted appears to be trying to create a session from within a session:
Session nsCurrent = NotesFactory.createSession();
Just like a Domino Java agent already has a session, so you'd just grab onto it and go from there, any Java code executed from within an XPage is already running inside a session, although the approach for getting a handle on it is comparatively obtuse. I recommend creating something like a DominoUtils class for convenient access to variables that are implicit globals in SSJS but have to be more manually retrieved in Java. For example:
import javax.faces.context.FacesContext;
import javax.faces.el.VariableResolver;
import lotus.domino.Database;
import lotus.domino.Session;
import com.ibm.xsp.application.ApplicationEx;
public class DominoUtils {
public static Database getCurrentDatabase() {
return (Database) resolveVariable("database");
}
public static Session getCurrentSession() {
return (Session) resolveVariable("session");
}
public static VariableResolver getVariableResolver() {
return ApplicationEx.getInstance().getVariableResolver();
}
public static Object resolveVariable(String variable) {
return getVariableResolver().resolveVariable(
FacesContext.getCurrentInstance(), variable);
}
}
Then you can just refer to getCurrentDatabase() / getCurrentSession() from anywhere...
System.out.println(DominoUtils.getCurrentDatabase().getTitle());
Additionally, then, the resolveVariable method will allow you to get a handle on any object that has a corresponding value in SSJS (context, requestScope, sessionAsSigner, etc.), including any that your own code has already defined in the current execution context by the time the Java code is invoked.
FWIW, if you're using the Extension Library, there's already a class called ExtLibUtil that provides convenient static access to all manner of useful stuff.