无法从XPage-版本10.0.1

时间:2019-05-10 23:14:41

标签: java xpages lotus-domino

我正在尝试从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)

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

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”命令加载了它们。我最初遇到无法解决Factory的问题,因此我将四个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会话,但它仍然无法正常工作。

谢谢, 斯科特

多米诺骨牌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();            
        }
    } 

2 个答案:

答案 0 :(得分:0)

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

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

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

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

答案 1 :(得分:0)

Jesse提出的建议是最简单的方法。使用变量解析器。我的应用程序正在获得像这样的ODA会话。这是更新的代码以获取可用的ODA会话或多米诺骨牌会话:

public static Session getSessionAsSigner() {
    Session s = (Session) ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "openSessionAsSigner");
    if (null == s) {
        s = (Session) Factory.getWrapperFactory().fromLotus((lotus.domino.Session)ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "sessionAsSigner"), Session.SCHEMA, null);
    }
    return s;
}

public static Session getSession() {
    Session s = (Session) ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "openSession");
    if (null == s) {
        s = (Session) Factory.getWrapperFactory().fromLotus((lotus.domino.Session)ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "session"), Session.SCHEMA, null);
    }
    return s;
}

我为此创建了一个带有静态函数的Utils类。