Throwable t = e.getTargetException();
if (t instanceof RemoteAccessException) {
t = ((RemoteAccessException)t).getCause();
}
if (t instanceof RemoteException) {
throw RmiInvoker.setRpcExceptionCode(t, new RpcException("Failed to invoke remote service: " + serviceType + ", method: "
+ invocation.getMethodName() + ", url: " + url + ", cause: " + t.getMessage(), t));
} else {
return new RpcResult(t);
}
} catch (Throwable e) {
if (e instanceof RemoteAccessException) {
e = ((RemoteAccessException)e).getCause();
}
throw RmiInvoker.setRpcExceptionCode(e, new RpcException("Failed to invoke remote service: " + serviceType + ", method: "
+ invocation.getMethodName() + ", url: " + url + ", cause: " + e.getMessage(), e));
}
}
public void destroy() {
}
};
} else {
Invoker<T> invoker;
try {
if ("dubbo".equals(url.getParameter("codec"))) {
RmiProtocol.getRemoteClass(serviceType);
}
Registry registry = LocateRegistry.getRegistry(url.getHost(), url.getPort());
String path = url.getPath();
if (path == null || path.length() == 0) {
path = serviceType.getName();
}
invoker = new RmiInvoker<T>(registry, rmiProxyFactory, rmiProxyFactory.getInvoker(registry.lookup(path), serviceType, url));
} catch (RemoteException e) {
Throwable cause = e.getCause();
boolean isExportedBySpringButNoSpringClass = ClassNotFoundException.class
.isInstance(cause)
&& cause.getMessage().contains(
"org.springframework.remoting.rmi.RmiInvocationHandler");
String msg = String
.format("Can not create remote object%s. url = %s",
isExportedBySpringButNoSpringClass ? "(Rmi object is exported by spring rmi but NO spring class org.springframework.remoting.rmi.RmiInvocationHandler at consumer side)"
: "", url);
throw new RpcException(msg, e);
} catch (NotBoundException e) {
throw new RpcException("Rmi service not found. url = " + url, e);
}
invokers.add(invoker);
return invoker;
}
}