TUSCANY-3850: Apply patch from Sebastian Millies to fix RMI bug: ConnectException after component restart
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1214198 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8580fd78a
commit
6fb07f5e88
1 changed files with 44 additions and 4 deletions
|
@ -20,16 +20,19 @@ package org.apache.tuscany.sca.binding.rmi.provider;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.rmi.ConnectException;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.UnexpectedException;
|
||||
|
||||
import org.apache.tuscany.sca.host.rmi.RMIHost;
|
||||
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
|
||||
import org.apache.tuscany.sca.invocation.Invoker;
|
||||
import org.apache.tuscany.sca.invocation.Message;
|
||||
import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
|
||||
|
||||
/**
|
||||
* Invoker for RMI References.
|
||||
*
|
||||
*
|
||||
* @version $Rev$ $Date$
|
||||
*/
|
||||
public class RMIReferenceInvoker implements Invoker, DataExchangeSemantics {
|
||||
|
@ -55,7 +58,7 @@ public class RMIReferenceInvoker implements Invoker, DataExchangeSemantics {
|
|||
Object[] args = msg.getBody();
|
||||
Object resp = invokeTarget(args);
|
||||
msg.setBody(resp);
|
||||
|
||||
|
||||
} catch (InvocationTargetException e) {
|
||||
msg.setFaultBody(e.getCause());
|
||||
} catch (Throwable e) {
|
||||
|
@ -65,12 +68,49 @@ public class RMIReferenceInvoker implements Invoker, DataExchangeSemantics {
|
|||
return msg;
|
||||
}
|
||||
|
||||
public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
|
||||
public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException,
|
||||
NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
|
||||
// try cached proxy first
|
||||
if (proxy == null) {
|
||||
proxy = rmiHost.findService(host, port, svcName);
|
||||
// proxy = Naming.lookup(serviceURI);
|
||||
}
|
||||
|
||||
Object invocationResult = null;
|
||||
InvocationTargetException rethrow = null;
|
||||
try {
|
||||
invocationResult = doInvokeTarget(payload);
|
||||
} catch (InvocationTargetException e) {
|
||||
// rethrow this exception from finally block unless it can be
|
||||
// handled
|
||||
rethrow = e;
|
||||
// try to diagnose the error condition: proxy may be out-of-date
|
||||
// (cf. TUSCANY-3850)
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof UndeclaredThrowableException) {
|
||||
cause = cause.getCause();
|
||||
if (cause instanceof UnexpectedException) {
|
||||
cause = cause.getCause();
|
||||
if (cause instanceof ConnectException) {
|
||||
// retry invoke with a fresh proxy
|
||||
rethrow = null;
|
||||
proxy = rmiHost.findService(host, port, svcName);
|
||||
invocationResult = doInvokeTarget(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (rethrow != null) {
|
||||
throw rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
return invocationResult;
|
||||
}
|
||||
|
||||
private Object doInvokeTarget(final Object payload) throws InvocationTargetException, SecurityException,
|
||||
NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
remoteMethod = proxy.getClass().getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes());
|
||||
|
||||
if (payload != null && !payload.getClass().isArray()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue