I have a button on an XPage where I want to connect to a remote OpenOffice instance. OpenOffice is started and is listening for a socket connection.
The onclick event of the button runs following SSJS:
oo = new com.test.OpenOffice(); oo.init("host=127.0.0.1,port=8107"); oo.openFile("C:\\TEMP\\Test.odt");
The code raises an excepction jva.lang.IlleagalStateException: NotesContext not initialized for the thread
The exception is raised within the method init
of the class OpenOffice
.
The relevant parts of the class OpenOffice is the following code:
public class DHOpenOffice implements Serializable { private static final long serialVersionUID = -7443191805456329135L; private XComponentContext xRemoteContext; private XMultiComponentFactory xMCF; private XTextDocument oTextDocument; public DHOpenOffice() { xRemoteContext = null; xMCF = null; oTextDocument = null; } public void init(String hostAdr) throws java.lang.Exception { xRemoteContext = null; XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null); XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext); String sConnect = "uno:socket," + hostAdr + ",tcpNoDelay=0;urp;StarOffice.ServiceManager"; Object context = xUrlResolver.resolve(sConnect); xRemoteContext = UnoRuntime.queryInterface(XComponentContext.class, context); xMCF = xRemoteContext.getServiceManager(); }
The code line Object context = xUrlResolver.resolve(sConnect);
is the one that raises the exception.
Why is this happing? What is the reason for this exception and how can I resolve the situation?
N.B.: The class code runs smoothly in a standalone application. The error occurs only when the code is started by a SSJS code.