Results 1 to 2 of 2

Thread: Handling RMI ConnectException

  1. #1
    Join Date
    Feb 2006
    Location
    Tokyo, JP
    Posts
    5

    Default 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. #2

    Default 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);
    	}
        }
    
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •