Announcement Announcement Module
No announcement yet.
Handling RMI ConnectException Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Handling RMI ConnectException

    The RmiProxyFactoryBean works great. But I'm puzzled as on how to handle when a client tries to connect to a server that is not running.

    I noticed that the RmiProxyFactoryBean inherits methods from org.springframework.remoting.rmi.RmiClientIntercep tor, such as <code>isConnectFailure</code>. But how can I take advantage of this?

    The idea is to try to connect to another RMI server; i.e. create a minimal kind of failover.

    Help appreciated.

  • #2
    RmiProxyFactoryBean ConnectException

    I don't know if this will help.

    I was having a problem that was the same or similar. I love RmiProxyFactoryBean, but it annoyed me that it would throw RemoteAccessExceptions on connection problems, which would bypass my catch RemoteException blocks and screw up the works. I know the Spring guys think that most exceptions are unrecoverable; perhaps theyíve been working the in presentation layer too much.

    In my case, I actually could recover from a remoting exception. I didnít want to add catch RemoteAccessException blocks everywhere my remote methods were called. Indeed, why should I; RemoteAccessException isnít in the throws clauses or javadocs of my remote methods. This whole unchecked exceptions thing is silly. Why is Spring going against the longstanding best practices for Java exceptions anyway?

    I get it that, in this particular case, RmiProxyFactoryBean can hide the fact that an object is remote (which, BTW, goes against distributed computing best practices: But when the proxied interface extends java.rmi.Remote, it should just throw RemoteException on connection problems. Or at least make it configurable.

    Long story short (too late), I subclassed RmiProxyFactoryBean to get the desired behaviour:

     * Throws {@link RemoteException} instead of the silly {@link RemoteAccessException}s
    public class MyRmiProxyFactoryBean extends RmiProxyFactoryBean {
        public Object invoke(MethodInvocation invocation) throws Throwable {
    	try {
    	    return super.invoke(invocation);
    	} catch (RemoteAccessException e) {
    	    throw new RemoteException("", e);