Announcement Announcement Module
Collapse
No announcement yet.
RemoteAccessException problem accessing SLSB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RemoteAccessException problem accessing SLSB

    Hi,
    I'm using two configurations to access my POJO from SWT client:
    1. for testing and development I use direct reference to POJO without J2EE container
    2. for production I use SLSB facade on JBoss implementing the same business interface and passing all invocations to POJO

    Works fine so I can switch between these two configurations without changing client application code ...
    ... except handling unchecked runtime exceptions.

    In 1 config client could catch and handle directly all unchecked exceptions e.g OptimisticLockingFailureException and do stuff

    In 2 config client always gets RemoteAccessException that wraps Runtime Exception so catching OptimisticLockingFailureException doesn't work at all.

    I would like to have client app that has the same exception handling in both configurations (and I don't want another Business Delegate layer)
    I debugged SimpleRemoteStatelessSessionProxyFactoryBean.java which I use for accesing SLSB. This class always wraps RemoteException with RemoteAccessException even if it has some meaningfull DataAccessException inside.
    I think it could check what's inside and sometimes throw that instead of RemoteAccessException, so client app could be really portable between local and remote configuration.

    I made a quick change to RmiClientInterceptorUtils
    so I could get MyDataAccessExceptions from POJO and SLSB (instead of RemoteAccessExceptions):

    Code:
    public static Exception convertRmiAccessException(Method method, RemoteException ex, String serviceName) {
    		if (logger.isDebugEnabled()) {
    			logger.debug("Remote service [" + serviceName + "] threw exception", ex);
    		}
    		if (!Arrays.asList(method.getExceptionTypes()).contains(RemoteException.class)) {
    			if (ex instanceof ConnectException) {
    				return new RemoteConnectFailureException("Cannot connect to remote service [" + serviceName + "]", ex);
    			}
    			else {
    // CHANGE STARTS HERE 
    			    logger.debug("Trying to extract included runtime server exception");
    			    Throwable e = ex;
    			    while (e.getCause() != null){
    			        e = e.getCause();
    			        if (e instanceof MyDataAccessException)
    			            return (Exception)e;
    			    }
    // CHANGE ENDS HERE 
    			    
    				return new RemoteAccessException("Cannot access remote service [" + serviceName + "]", ex);
    			}
    		}
    		else {
    			return ex;
    		}
    	}

    I wonder if there's another solution (without changing Spring code)
Working...
X