I use RMI to access my Java application through MATLAB, which works in another JVM. MATLAB has a good interface for printing Java object methods. But it does not work with RMI, because the object that it receives is a proxy server.
Therefore, I would like to add my own method for extracting / printing the capabilities of the remote interface (RMI, obviously, cannot directly access methods not available in the exported remote interfaces).
How could I do this with reflection, either on the client end of the RMI connection or on the server? I do not have much experience using reflection. Use the example below.
edit: the fact that I am getting the most stuck is given by an arbitrary X object (including where X is the RMI proxy), how can I use reflection to get the interfaces implemented through this object?
java classes:
class RemoteDescriber { RemoteDescription describe(Remote remote) { ... } } class RemoteDescription implements Serializable { @Override public String toString() { ... } } interface FooRemote extends Remote { public int getValue() throws RemoteException; public void setValue(int x) throws RemoteException; public void doSomethingSpecial() throws RemoteException; public RemoteDescription describe() throws RemoteException; }
and example client session in MATLAB
x = ...; % get something that implements FooRemote describer = com.example.RemoteDescriber; % describer is a client-side Java object description1 = describer.describe(x) %%% prints a description of the FooRemote interface %%% obtained by the client-side RemoteDescriber description2 = x.describe() %%% prints a description of the FooRemote interface %%% obtained on the server-side by x itself, and marshalled %%% to the client
source share