Wednesday, December 7, 2011

Spring RMI over firewall

Problem: RMI service is not reachable even if the registry port is open in the firewall

Reason: RMI uses a random service port for communication with client and hence firewall will block this port. Even if you open RMI registry port on firewall the service can not be used since the service port is not open.

Solution: Configure a specific service port instead of the default random port for your RMI service. RMI will use this port instead of using a random port. You can open this port in your firewall and hence make the communication happen. If you are using spring Remoting then its as simple as configuring servicePort property for your RMIServiceExporter.
Eg
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">

    <property name="serviceName" value="MyService"></property>
    <property name="service" ref="MyService"></property>
    <property name="serviceInterface" value="in.example.MyService"></property>
    <property name="registryPort" value="1099"></property>
    <property name="servicePort" value="1100"></property>
</bean>

And the good news is that both registryPort and service port can be the same. That means your firewall requires to open only a single port for your rmi service.

Common Misconception: RMI uses the registry port for communication and opening registry port in firewall is sufficient to support RMI service over firewall