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??
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.
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.
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.
Use an LDAP server instead of the RMI Registry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With