gpt4 book ai didi

java - 无法在从 XPage 调用的 java 中获取 openNTF session - 版本 10.0.1

转载 作者:太空宇宙 更新时间:2023-11-04 09:40:07 24 4
gpt4 key购买 nike

我正在尝试从 XPage 调用 java session 。 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 session ,但仍然不起作用。

谢谢,斯科特

多米诺骨牌 10.0.1 FP1openNTF 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() 是一种尝试查找当前上下文的 session 的方法,检查 XPages 环境(如果可用),然后检查 ContextInfo.getUserSession(),如果找不到任何内容,最后调用 NotesFactory.createSession()

设置后,Factory.getSession() 将使用提供的覆盖而不是其正常行为。

关于java - 无法在从 XPage 调用的 java 中获取 openNTF session - 版本 10.0.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56085867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com