我想连接到远程 OpenOffice 实例的 XPage 上有一个按钮。OpenOffice 已启动并正在侦听套接字连接。
按钮的 onclick 事件在 SSJS 之后运行:
oo = new com.test.OpenOffice(); oo.init("主机=127.0.0.1,端口=8107"); oo.openFile("C:\\TEMP\\Test.odt");
代码引发异常jva.lang.IlleagalStateException: NotesContext not initialized for the thread
init
异常在类的方法中引发OpenOffice
。
OpenOffice 类的相关部分是以下代码:
公共类 DHOpenOffice 实现 Serializable { 私有静态最终长序列版本UID = -7443191805456329135L; 私有 XComponentContext xRemoteContext; 私有 XMultiComponentFactory xMCF; 私有 XTextDocument oTextDocument; 公共 DHOpenOffice() { xRemoteContext = null; xMCF = 空; oTextDocument = null; } public void init(String hostAdr) 抛出 java.lang.Exception { xRemoteContext = null; XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null); XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext); 字符串 sConnect = "uno:socket," + hostAdr + ",tcpNoDelay=0;urp;StarOffice.ServiceManager"; 对象上下文 = xUrlResolver.resolve(sConnect); xRemoteContext = UnoRuntime.queryInterface(XComponentContext.class, context); xMCF = xRemoteContext.getServiceManager(); }
代码行Object context = xUrlResolver.resolve(sConnect);
是引发异常的行。
为什么会这样?此异常的原因是什么,我该如何解决这种情况?
注意:类代码在独立应用程序中运行流畅。该错误仅在代码由 SSJS 代码启动时发生。