[Solved] Bootstrapping on Ubuntu server

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Bootstrapping on Ubuntu server

Postby wmpartner » Sun Jan 29, 2017 4:32 pm

I operate a cloud server with Ubuntu 16.04 and OpenOffice 4.1.2. Several users use java application that bootstrap an instance of OpenOffice. For bootstrapping I use bootstrapconnector.jar. The first user can easily bootstrap OpenOffice with the following java-snippet:

Code: Select all   Expand viewCollapse view
List liste = ooo.connector.server.OOoServer.getDefaultOOoOptions();
            oooExeFolder = "/opt/openoffice4/program";
            ooo.connector.server.OOoServer server = new ooo.connector.server.OOoServer(oooExeFolder, liste);
            BootstrapSocketConnector oooConnector = new BootstrapSocketConnector(server);
            xContext = oooConnector.connect();
            xMultiComponentFactory = xContext.getServiceManager();
            xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
            PropertyValue[] argumente  = new PropertyValue[1];
            argumente[0] = new PropertyValue();
            objectDocumentToStore = (XComponent) xcomponentloader.loadComponentFromURL(loadUrl, "_default", 2, argumente);

OpenOffice starts and everything works just fine. But now a second user starts a different java application with nearly the same bootstrap-mechanism. Only loadUrl and the red line above are different. It reads now
Code: Select all   Expand viewCollapse view

The app of the second user crashes on the last line of the code snippet. In some cases with an error message, in other cases the OOo Document appears on the display of the first user!! But on the other hand, if user 1 types
Code: Select all   Expand viewCollapse view
/opt/openoffice4/program/soffice -accept="socket,host=localhost,port=8699;urp;StarOffice.ServiceManager"
on the terminal. OOo opens fine
Now user 2 types
Code: Select all   Expand viewCollapse view
/opt/openoffice4/program/soffice -accept="socket,host=localhost,port=8700;urp;StarOffice.ServiceManager"
on the terminal. OOo opens fine too.
sudo netstat -a gives me the information that ports 8699 and 8700 are in listening mode.

Some advice would be highly appreciated

Best regards and thanks in advance
Andeas from wmpartner
Last edited by Hagar Delest on Sat Feb 04, 2017 5:13 pm, edited 1 time in total.
Reason: tagged [Solved].
OOo Version 4.1.2 Ubuntu 16,04 on a cloud server
Posts: 2
Joined: Sun Jan 29, 2017 3:50 pm

Re: Bootstrapping on Ubuntu server

Postby wmpartner » Sat Feb 04, 2017 1:57 pm

I've found a solution that works very stable. I'm now using the jodconverter library to connect to a running instance of OpenOffice. It has a slightly different bootstrap mechanism. First of all it only connects to a running OO instance. It return an error if the office instance isn't listening on the desired port.
Before you connect you have to start OO from the command line or a script

Code: Select all   Expand viewCollapse view
/opt/openoffice4/program/soffice -accept="socket,host=,port=8699;urp;" &

Establishing the connection in Java is very simple:

Code: Select all   Expand viewCollapse view
// connect to an OpenOffice.org instance running on port 8699
connection = new SocketOpenOfficeConnection(8699);
xContext = connection.getComponentContext();

That's nearly all. To be on the save side some more scripting and Java-programming is necessary. Before you start a new instance of OO on a certain port you better make sure that no other user has already started a connection on that port. My solution isn't elegant but it works stable. I use the following shell script:

Code: Select all   Expand viewCollapse view
java -jar /pathTo/MyProgram.jar

if [ $returnvalue -eq 12 ]; then
    /opt/openoffice4/program/soffice -accept="socket,host=,port=8699;urp;" &
    while ! echo exit | nc 8699; do sleep 2; done
    java -jar /pathTo/MyProgram.jar

The Java program returns 12 if no other user has started OO on port 8699. This can be done with System.exec() and the command ss -tanp | grep 8699. If a process is listening on port 8699 the output should contain "" and "users:((\"soffice.bin\",pid=" and "LISTEN". If this is the case you can read the pid from the output and query the owner oft this process. I did it with

Code: Select all   Expand viewCollapse view
String user = System.getProperty("user.name");
Process p = r.exec("ps -p " + pid + " -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS");
output = org.apache.commons.io.IOUtils.toString(p.getInputStream());

If output contains user then the process is running and the user owns it. Now you can connect to this OO instance.

Without asking the ownership of the process you have more or less funny side effects.

I hope it helps others. If there is anybody with a better and/or more elegant solution, please reply to this post.

Best regards
Andreas from wmpartner
OOo Version 4.1.2 Ubuntu 16,04 on a cloud server
Posts: 2
Joined: Sun Jan 29, 2017 3:50 pm

Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests