Bugzilla – Attachment 131385 Details for
Bug 106128
Closing last document will close all frames in uno listening mode
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Test class
Test.java (text/x-java), 3.26 KB, created by
Sven
on 2017-02-21 13:39:58 UTC
(
hide
)
Description:
Test class
Filename:
MIME Type:
Creator:
Sven
Created:
2017-02-21 13:39:58 UTC
Size:
3.26 KB
patch
obsolete
>package uno.bug.test; > >import java.io.IOException; >import java.net.InetSocketAddress; >import java.net.Socket; > >import com.sun.star.bridge.XBridge; >import com.sun.star.bridge.XBridgeFactory; >import com.sun.star.comp.helper.Bootstrap; >import com.sun.star.connection.NoConnectException; >import com.sun.star.connection.XConnection; >import com.sun.star.connection.XConnector; >import com.sun.star.lang.EventObject; >import com.sun.star.lang.XComponent; >import com.sun.star.lang.XEventListener; >import com.sun.star.lang.XMultiComponentFactory; >import com.sun.star.uno.UnoRuntime; >import com.sun.star.uno.XComponentContext; > >public class Test { > > // the only variable to change by the user for testing > private static final String SOFFICE_CMD = System.getProperty("soffice.cmd", > "D:/Programme/LibreOfficePortable530/App/libreoffice/program/soffice.exe"); > > private static final String HOST = "localhost"; > private static final int PORT = 9100; > private static final String CONNECTION_STRING = "socket,host=" + HOST + ",port=" + PORT; > private static final int UNO_TIMEOUT_IN_SECONDS = 120; > > public static void main(String[] args) throws Exception { > Test t = new Test(); > t.test(); > } > > private void test() throws Exception { > XComponentContext localContext = Bootstrap.createInitialComponentContext(null); > XMultiComponentFactory localServiceManager = localContext.getServiceManager(); > XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, > localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext)); > XConnection xConnection; > try { > xConnection = xConnector.connect(CONNECTION_STRING); > } catch (NoConnectException e) { > if (!isConnected()) { > ProcessBuilder pb = new ProcessBuilder(SOFFICE_CMD, > "--accept=" + CONNECTION_STRING + ";urp;StarOffice.ServiceManager"); > pb.start(); > // only waiting for uno server socket connection > waitForUno(); > } > xConnection = xConnector.connect(CONNECTION_STRING); > } > XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, > localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext)); > XBridge xBridge = xBridgeFactory.createBridge("", "urp", xConnection, null); > XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xBridge); > xComponent.addEventListener(new XEventListener() { > @Override > public void disposing(EventObject arg0) { > System.out.println("XBridge is disposing"); > } > }); > } > > private void waitForUno() { > long start = System.currentTimeMillis(); > long timeout = System.currentTimeMillis() + (UNO_TIMEOUT_IN_SECONDS * 1000); > while (!isConnected() && System.currentTimeMillis() < timeout) { > try { > Thread.sleep(100); > } catch (InterruptedException e) { > } > } > System.out.println( > "wait for uno " + (System.currentTimeMillis() - start) + " ms; uno is running: " + isConnected()); > } > > private boolean isConnected() { > boolean connected = false; > try { > Socket s = new Socket(); > s.connect(new InetSocketAddress(HOST, PORT), 10); > connected = true; > s.setSoLinger(true, 0); > s.close(); > } catch (IOException ioe) { > } > return connected; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 106128
: 131385 |
131386