Programming WebLogic RMI
The basic building block for all remote objects is the interface
java.rmi.Remote, which contains no methods. You extend this "tagging" interface—that is, it functions as a tag to identify remote classes—to create your own remote interface, with method stubs that create a structure for your remote object. Then you implement your own remote interface with a remote class. This implementation is bound to a name in the registry, where a client or server can look up the object and use it remotely.
If you have written RMI classes, you can drop them in WebLogic RMI by changing the import statement on a remote interface and the classes that extend it. To add remote invocation to your client applications, look up the object by name in the registry. WebLogic RMI exceptions are identical to and extend java.rmi exceptions so that existing interfaces and implementations do not have to change exception handling.
RuntimeException. WebLogic RMI subclasses
java.rmi.RemoteException,so if you already have existing RMI classes, you will not have to change your exception handling.
With JavaSoft's RMI, every class that implements a remote interface must have accompanying, precompiled proxies. WebLogic RMI supports more flexible runtime code generation; WebLogic RMI supports dynamic proxies and dynamically created bytecode that are type-correct but are otherwise independent of the class that implements the interface. If a class implements a single remote interface, the proxy and bytecode that is generated by the compiler will have the same name as the remote interface. If a class implements more than one remote interface, the name of the proxy and bytecode that result from the compilation depend on the name mangling used by the compiler.
Still using a Java code text editor, write the class be invoked remotely. The class should implement the remote interface that you wrote in Step 1, which means that you implement the method signatures that are contained in the interface. Currently, all the code generation that takes place in WebLogic RMI is dependent on this class file.
With WebLogic RMI, your class does not need to extend UnicastRemoteObject, which is required by JavaSoft RMI. (You can extend UnicastRemoteObject, but it isn't necessary.) This allows you to retain a class hierarchy that makes sense for your application.
Note: With Weblogic server, you can use both Weblogic RMI and standard JDK RMI. If you use Weblogic RMI, then you must use "java weblogic.rmic ..." as the rmic compiler and you must not create your RMI implementation as a subclass of "java.rmi.server.UnicastRemoteObject". If you use standard JDK RMI, then you must use "%JAVA_HOME%\bin\rmic" as the rmic compiler and you must create your RMI implementation class as a subclass of "java.rmi.server.UnicastRemoteObject".
This example implements a class that creates multiple HelloImpls and binds each to a unique name in the registry. The method sayHello() greets the user and identifies the object which was remotely invoked.
Next, write a main() method that creates an instance of the remote object and registers it in the WebLogic RMI registry, by binding it to a name (a URL that points to the implementation of the object). A client that needs to obtain a proxy to use the object remotely will be able to look up the object by name.
WebLogic RMI does not require that you set a Security Manager in order to integrate security into your application. Security is handled by WebLogic Server support for SSL and ACLs. If you must, you may use your own security manager, but do not install it in WebLogic Server.
Run the WebLogic RMI compiler (
weblogic.rmic) against the remote class to generate the dynamic proxy and bytecode, on the fly. A proxy is the client-side proxy for a remote object that forwards each WebLogic RMI call to its matching server-side bytecode, which in turn forwards the call to the actual remote object implementation. To run the
weblogic.rmic, use the command pattern:
Set the flag -keepgenerated when you run
weblogic.rmic if you want to keep the generated source when creating stub or skeleton classes. For a listing of the available command-line options, see WebLogic RMI Compiler Options.
Using a Java code text editor, once you compile and install the remote class, the interface it implements, and its proxy and the bytecode on the WebLogic Server, you can add code to a WebLogic client application to invoke methods in the remote class.
In general, it takes just a single line of code: get a reference to the remote object. Do this with the Naming.lookup() method. Here is a short WebLogic client application that uses an object created in a previous example.