Factored-out methods for performing invocations within an RMI client.
Can handle both RMI and non-RMI service interfaces working on an RMI stub.
Note: This is an SPI class, not intended to be used by applications.
| Method from org.springframework.remoting.rmi.RmiClientInterceptorUtils Detail: |
public static Exception convertRmiAccessException(Method method,
Throwable ex,
String message) {
if (logger.isDebugEnabled()) {
logger.debug(message, ex);
}
if (ReflectionUtils.declaresException(method, RemoteException.class)) {
return new RemoteException(message, ex);
}
else {
return new RemoteAccessException(message, ex);
}
}
Wrap the given arbitrary exception that happened during remote access
in either a RemoteException or a Spring RemoteAccessException (if the
method signature does not support RemoteException).
Only call this for remote access exceptions, not for exceptions
thrown by the target service itself! |
public static Exception convertRmiAccessException(Method method,
RemoteException ex,
String serviceName) {
return convertRmiAccessException(method, ex, isConnectFailure(ex), serviceName);
}
Convert the given RemoteException that happened during remote access
to Spring's RemoteAccessException if the method signature does not
support RemoteException. Else, return the original RemoteException. |
public static Exception convertRmiAccessException(Method method,
RemoteException ex,
boolean isConnectFailure,
String serviceName) {
if (logger.isDebugEnabled()) {
logger.debug("Remote service [" + serviceName + "] threw exception", ex);
}
if (ReflectionUtils.declaresException(method, ex.getClass())) {
return ex;
}
else {
if (isConnectFailure) {
return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
}
else {
return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
}
}
}
Convert the given RemoteException that happened during remote access
to Spring's RemoteAccessException if the method signature does not
support RemoteException. Else, return the original RemoteException. |
public static Object doInvoke(MethodInvocation invocation,
Remote stub) throws InvocationTargetException {
return invokeRemoteMethod(invocation, stub);
} Deprecated! as - of Spring 2.5, in favor of #invokeRemoteMethod
Perform a raw method invocation on the given RMI stub,
letting reflection exceptions through as-is. |
public static Object invoke(MethodInvocation invocation,
Remote stub,
String serviceName) throws Throwable {
try {
return invokeRemoteMethod(invocation, stub);
}
catch (InvocationTargetException ex) {
Throwable targetEx = ex.getTargetException();
if (targetEx instanceof RemoteException) {
RemoteException rex = (RemoteException) targetEx;
throw convertRmiAccessException(invocation.getMethod(), rex, serviceName);
}
else {
throw targetEx;
}
}
} Deprecated! as - of Spring 2.5, in favor of #invokeRemoteMethod
Apply the given method invocation to the given RMI stub.
Delegates to the corresponding method if the RMI stub does not directly
implement the invoked method. This typically happens when a non-RMI service
interface is used for an RMI service. The methods of such a service interface
have to match the RMI stub methods, but they typically don't declare
java.rmi.RemoteException: A RemoteException thrown by the RMI stub
will be automatically converted to Spring's RemoteAccessException. |
public static Object invokeRemoteMethod(MethodInvocation invocation,
Object stub) throws InvocationTargetException {
Method method = invocation.getMethod();
try {
if (method.getDeclaringClass().isInstance(stub)) {
// directly implemented
return method.invoke(stub, invocation.getArguments());
}
else {
// not directly implemented
Method stubMethod = stub.getClass().getMethod(method.getName(), method.getParameterTypes());
return stubMethod.invoke(stub, invocation.getArguments());
}
}
catch (InvocationTargetException ex) {
throw ex;
}
catch (NoSuchMethodException ex) {
throw new RemoteProxyFailureException("No matching RMI stub method found for: " + method, ex);
}
catch (Throwable ex) {
throw new RemoteProxyFailureException("Invocation of RMI stub method failed: " + method, ex);
}
}
Perform a raw method invocation on the given RMI stub,
letting reflection exceptions through as-is. |
public static boolean isConnectFailure(RemoteException ex) {
return (ex instanceof ConnectException || ex instanceof ConnectIOException ||
ex instanceof UnknownHostException || ex instanceof NoSuchObjectException ||
ex instanceof StubNotFoundException || isCorbaConnectFailure(ex.getCause()) ||
ORACLE_CONNECTION_EXCEPTION.equals(ex.getClass().getName()));
}
Determine whether the given RMI exception indicates a connect failure.
Treats RMI's ConnectException, ConnectIOException, UnknownHostException,
NoSuchObjectException and StubNotFoundException as connect failure,
as well as Oracle's OC4J com.evermind.server.rmi.RMIConnectionException
(which doesn't derive from from any well-known RMI connect exception). |