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

  • Handling RMI ConnectException

    The RmiProxyFactoryBean works great. But I'm puzzled as on how to handle java.net.ConnectException 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: http://research.sun.com/techrep/1994/abstract-29.html). 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:

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

    Comment

    Working...
    X