Remote RMI Registry

I am encoding an application that requires remote binding, i.e. binds the remote object to the remote registry. By default, the Java RMI registry is only linked locally, only remote objects bound to the same JVM / host.

I saw some solutions that circumvented this by making a remote interface that would take the remote object and then bind locally ( SO link of this disucssion ). Is there no more elegant way to solve this problem? Maybe I should try to use JNDI with another provider?

+4
source share
4 answers

I did some more research on this ... First, if you have the same code base on both servers, it should be so simple:

... Registry registry = LocateRegistry.getRegistry("192.168.1.1", 1100); registry.rebind("Hello, World!", myObj); 

But you can run into problems quickly if you need to upload classes to a remote registry ... you need a security manager: http://www.devx.com/getHelpOn/10MinuteSolution/20444

I was still hoping you could post a sample code or give us more information about your situation.

0
source

This is a hack, but you can try to configure port forwarding on the server, so the port of the registry server is displayed in such a way that all requests coming through it look like local.

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

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

This will not execute the ( -N ) command, but will open a listening socket on port 1199 on the local computer, which will be redirected to port 1099 on localhost ( -L 1199:localhost:1099 ) and available for connections from any source ( -g ). Connections made through this tunnel will be displayed on the server on port 1099 to go from the local host. Note that you can also add -f so that SSH goes into the background after configuring the tunnel, in which case I would suggest adding "-o ExitOnForwardFailure" to improve error handling.

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

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

Now I do not know that any of these options will be sufficient. This will allow access to the network layer, but it is possible that the rmiregistry server will still refuse to register deleted objects. I doubt it.

+2
source

Use an LDAP server instead of the RMI registry.

+2
source

I did this, but I used a completely different approach. I wrote simple POJOs and Plain Java Interfaces without getting confused with weird abstract classes, remote stub compilers, or a lot of proven exceptions related to the Java RMI APIs. Then I used Spring Remoting to connect everything and Spring took care of the RMI transport:

Take a look at the manual here: http://static.springsource.org/spring/docs/2.0.x/reference/remoting.html

Here is an example bean that proxies access to a remote registry:

 <bean id="accountService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://HOST:1199/AccountService"/> <property name="serviceInterface" value="example.AccountService"/> </bean> 

This solves your problem, but probably doesn't exactly answer your question ... the old Java RMI API is pretty outdated, but Spring allows you to work with "plain Java."

-1
source

Source: https://habr.com/ru/post/1391562/


All Articles