Architecture
COMConnect comes as four discreet components, a COM/.NET client (for use by .NET/COM applications wanting to talk to Java applications), a COM/.NET server (for use by any client wanting to talk to exposed COM/.NET applications), a Java client and a Java server (to expose Java applications). All four components speak the same protocol and any client can connect to any server. There is also a fifth component, a proxy, which imitates a server and routes requests from clients to a pool of servers.
Installation
A complete windows installer is supplied, allowing you to select the components you wish to install. For the purposes of our demo, you will need to install at least the COM server and Java clients.
A source bz2 file is included for other platforms, look in the build directory for pre-built JAR files for your Java applications.
Demonstration: Use Microsoft Word 2000 remotely from Java
This section describes how the TestClientMSWord application connects to the MS Word COM object and makes requests of it. The source code will be found at $install\test\TestClientMSWord.java.
Step 1 involves getting a connection to an UPCOnnect server, and then starting it listening for incoming traffic:-
String host = "localhost"; int port = 2001; uk.co.upco.iop.IOPServer iops = new IOPServer(host, port); iops.start();
To create a connection to the UPCOnnect server it is necessary to pass in the hostname and port that the UPCOnnect server is running on. In the example above the server running on the local machine and listening on port 2001 has been called.
Once a connection to a server is established we need to get a reference to a COM object of the type we are interested in. For this example we want a reference to a new Word Application object, this is known as "Word.Application". The following code demonstrates how to do this:-
IOPObject wordAppn = iops.createIOPObject("Word.Application");
Once a reference to an object has been obtained it is possible to call COM methods on it. For example, to create a document and add some text we need to do the following (there are multiple object calls because of the Word COM object model hierarchy):-
1. wordAppn.letProperty("Visible", new IOPVariable(true)); 2. IOPObject wordAppDocs = wordAppn.getObjectProperty("Documents"); 3. IOPObject worddoc = wordAppDocs.callMethodReturnObject("Add"); 4. IOPObject wordContent = worddoc.getObjectProperty("Content"); 5. IOPVariable[] upv = { new IOPVariable("Testing Java to COM")}; 6. wordContent.callMethod("InsertAfter", upv);
Line 1 displays the word application in an MS office window. Lines 2 and 3 create the word document and get an IOPObject reference to it (worddoc). Line 4 to 6 sets the content by first getting the value of the COM "Content" property from the COM word document (worddoc) via the getObjectProperty method. An IOPVariable is then created with the text to be added, and finally the COM method "InsertAfter" is called.
Finally, we should clean up by disposing of the references, and closing the connection to the server:-
// Clear up all references on the server wordContent.dispose(); worddoc.dispose(); wordAppDocs.dispose(); wordAppn.dispose(); // Close connection to UPCOnnect server. iops.close();
This code is shown fully in the $install/test/TestClientMSWord.java application. To run the application use:-
java -classpath .;$filepath/UPCOnnectClient.jar test.TestClientMSWord
Alternatively use the runMSWord.bat file. An MS Word application should open with the text "Testing Java to COM".
If you want to specify a different host and port pass in the values as application arguments:
java -classpath .;$filepath/UPCOnnectClient.jar test.TestClientMSWord $host $port