Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote RMI Registry

I'm coding an application that requires remote binding, i.e., bind a remote object to a remote registry. By default, Java RMI Registry only binds locally, only remote objects that are binded in the same JVM/host.

I've seen some solutions that bypass this making a remote interface that will take a remote object and then bind locally (SO link of this disucssion). Isn't there a more elegant way to solve this? Maybe I should try to use JNDI with other provider??

like image 506
Marcos Roriz Junior Avatar asked Jan 18 '12 00:01

Marcos Roriz Junior


People also ask

What is RMI registry?

A Java RMI registry is a simplified name service that allows clients to get a reference (a stub) to a remote object. In general, a registry is used (if at all) only to locate the first remote object a client needs to use.

Which method is used for RMI registry for object?

The class java. rmi. registry. LocateRegistry is used to obtain a reference (construct a stub) to a bootstrap remote object registry on a particular host (including the local host), or to create a remote object registry that accepts calls on a specific port.


2 Answers

This is a hack, but you could try setting up a port forwarding on the server, so the registry's server port is exposed in such a way that all requests coming through it look like they're local.

This is fairly easy to do with SSH. On the server, run:

ssh localhost -N -L 1199:localhost:1099 -g

That won't run a command (-N), but will open a listening socket on port 1199 on the local machine which is forwarded to port 1099 on localhost (-L 1199:localhost:1099) and which is accessible to connections from any source (-g). Connections made through this tunnel will appear to the server on port 1099 to have come from localhost. Note that you can also add -f to have SSH go into the background after setting up the tunnel, in which case i would suggest also adding '-o ExitOnForwardFailure' to improve the error handling.

It should also be possible to do this using netcat rather than SSH, which will be simpler and more efficient, but i don't have a suitable version of netcat installed. It is also possible to do it with socat, if you have that installed:

socat TCP-LISTEN:1199,fork TCP:localhost:1099

Now, i don't know that any of these options will be sufficient. That will open up network-level access, but it's possible that the rmiregistry server will still refuse to register remote objects. I doubt that, though.

like image 94
Tom Anderson Avatar answered Sep 24 '22 07:09

Tom Anderson


Use an LDAP server instead of the RMI Registry.

like image 33
user207421 Avatar answered Sep 26 '22 07:09

user207421