Return-Path: X-Original-To: apmail-tuscany-commits-archive@www.apache.org Delivered-To: apmail-tuscany-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0CFB2938D for ; Wed, 14 Dec 2011 12:09:34 +0000 (UTC) Received: (qmail 58075 invoked by uid 500); 14 Dec 2011 12:09:34 -0000 Delivered-To: apmail-tuscany-commits-archive@tuscany.apache.org Received: (qmail 58026 invoked by uid 500); 14 Dec 2011 12:09:33 -0000 Mailing-List: contact commits-help@tuscany.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tuscany.apache.org Delivered-To: mailing list commits@tuscany.apache.org Received: (qmail 58019 invoked by uid 99); 14 Dec 2011 12:09:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2011 12:09:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2011 12:09:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C462D23888E7 for ; Wed, 14 Dec 2011 12:09:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1214198 - /tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java Date: Wed, 14 Dec 2011 12:09:11 -0000 To: commits@tuscany.apache.org From: antelder@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111214120911.C462D23888E7@eris.apache.org> Author: antelder Date: Wed Dec 14 12:09:11 2011 New Revision: 1214198 URL: http://svn.apache.org/viewvc?rev=1214198&view=rev Log: TUSCANY-3850: Apply patch from Sebastian Millies to fix RMI bug: ConnectException after component restart Modified: tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java Modified: tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java?rev=1214198&r1=1214197&r2=1214198&view=diff ============================================================================== --- tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java (original) +++ tuscany/sca-java-1.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIReferenceInvoker.java Wed Dec 14 12:09:11 2011 @@ -20,16 +20,19 @@ package org.apache.tuscany.sca.binding.r 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 impleme 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 impleme 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()) {