ACUCOBOL-GT's "CVM.jar" package contains a class for connecting to an RMI server and returning an object through which remote methods can then be called on the RMI server. The class is called RemoteConnect. For more information, see the topic CVM Class.
The RemoteConnect class has a public static method called "CreateRemoteObject" that takes two strings and an int as parameters and returns a java.rmi.Remote object handle. The strings it requires are the host name of the server, the name of the RMI server object, and the int is the port number on which the server is listening. Once the remote object handle has been returned, remote methods on that object can be called in the same way as methods as any other Java object handle. Here is an example of using the RemoteConnect class in COBOL:
CALL "C$JAVA" USING CJAVA-NEW, "java/lang/Object", "()V" GIVING REMOTE-OBJ. CALL "C$JAVA" USING "com/acucorp/acucobolgt/RemoteConnect", "CreateRemoteObject", "(XXI)Ljava/rmi/Remote;", "localhost", "TestRemoteInterface", PORT-NUMBER, REMOTE-OBJ GIVING STATUS-VAL. CALL "C$JAVA" USING CJAVA-CALL, REMOTE-OBJ, "acuUtilities/TestRemoteInterface", "TestRemoteMethod", "()X", FIELD-STRINGRET GIVING STATUS-VAL. CALL "C$JAVA" USING CJAVA-DELETE, REMOTE-OBJ GIVING STATUS-VAL.
In this example, an instance of the object is created, and then the method "CreateRemoteObject" in RemoteConnect is called. In this case, the host is localhost, and the name of the remote interface is "TestRemoteInterface". "TestRemoteInterface" extends Remote and has one remote method called "TestRemoteMethod". The port number is "0" here. Passing in "0" causes the method to look for the object on the default RMI port, 1099. Note that for this to work, the RMI registry needs to have been previously started using the command "start rmiregistry" from the command line, and then the server object must be registered with the RMI registry.