我正在尝试从XPage调用java中的会话。从3.0版开始的老派方式非常有效:

(Session) Factory.fromLotus(NotesFactory.createSession(), Session.class, null);


但是,这不再可用。我尝试了下面找到的代码,但始终收到以下错误:

***NO STACK TRACE*** - A session of type CURRENT was requested but no Factory has been defined for that type in this thread.

***NO STACK TRACE*** - Unable to get the session of type CURRENT from the session factory of type null. This probably means that you are running in an unsupported configuration or you forgot to set up your context at the start
of the operation. If you're running in XPages, check the xsp.properties of your database. If you are running in an Agent, make sure you start with a call to Factory.setSession() and pass in your lotus.domino.Session
java.lang.RuntimeException
at org.openntf.domino.utils.Factory.getSession(Factory.java:1012)
at org.openntf.domino.utils.Factory.getSession(Factory.java:859)


由于“ setSession()也不再可用”,因此“确保从对Factory.setSession()的调用开始并传入Lotus.domino.Session”具有误导性。

if(!Factory.isStarted()) {
        Factory.startup();
    }
    if (!Factory.isInitialized()) {
        System.out.println("Factory.initThread");
        Factory.initThread(new Factory.ThreadConfig(new Fixes[0], AutoMime.WRAP_32K, true));
    }

    Session session = Factory.getSession();


我已经使用更新站点安装了OpenNTF API,并确认已使用“ tell http osgi ss openntf”命令加载了它们。我有一个最初的问题,它无法解决工厂问题,因此我将四个jar文件复制到ext目录,它解决了这个问题:

org.openntf.domino.rest_10.0.1.201905061230.jar

org.openntf.domino.xsp_10.0.1.201905061230.jar

org.openntf.domino_10.0.1.201905061230.jar

org.openntf.formula_10.0.1.201905061230.jar

我还尝试在Factory.startup()调用中提交Domino会话,但它仍然无法正常工作。

谢谢,
史考特

Domino 10.0.1 FP1
openNTF API: OpenNTF-Domino-API-10.0.1.zip

问题所在的代码。这是从XPage调用的。电话是:

<xp:label value="#{javascript:sessionBean.getCoreUser().getUserId();}"/>


这将触发SessionBean构造函数,该构造函数将调用startLogging方法。该方法检查是否打开了“ DebugMode”。如果是,则将所有调试语句写入OpenLog。

private void startLogging() {
        System.out.println("Start OpenLog Logging");

        Session session = (Session) ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "openSession");
        System.out.println("Session: " + session);

        try {
            ViewEntry valueEntry = session.getCurrentDatabase().getView("SystemConfig").getFirstEntryByKey("DebugMode");
            if (valueEntry != null)
                SessionBean.debugMode = ("true".equalsIgnoreCase((String) valueEntry.getColumnValue("SetupValue")) ? Boolean.TRUE : Boolean.FALSE);

            System.out.println("Debug Mode set to: " + debugMode);
        } catch(Exception e) {
            System.out.println("Exception in Start OpenLog Logging");
            e.printStackTrace();
        }
    }

最佳答案

现在,我在servlet插件中执行此操作的方法是在service(HttpServletRequest, HttpServletResponse)方法中进行以下操作:

Factory.setSessionFactory(() -> AppUtil.getSession(), SessionType.CURRENT);


其中AppUtil.getSession()是一种尝试为当前上下文找到会话的方法,先检查XPages环境(如果可用),然后检查ContextInfo.getUserSession(),如果找不到任何内容,则最终调用NotesFactory.createSession()

设置完之后,Factory.getSession()将使用提供的替代代替其正常行为。

08-07 19:13