From: Artur Signell Date: Thu, 21 Jun 2012 14:59:55 +0000 (+0300) Subject: Pass RPC exceptions to Application.terminalError (#9018) X-Git-Tag: 7.0.0.alpha3~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bd85f96658b15159af3f7e8159047a6057290502;p=vaadin-framework.git Pass RPC exceptions to Application.terminalError (#9018) --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 797f8f756c..1ea713b4f6 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -71,6 +71,7 @@ import com.vaadin.terminal.gwt.client.communication.SharedState; import com.vaadin.terminal.gwt.client.communication.UidlValue; import com.vaadin.terminal.gwt.server.BootstrapHandler.BootstrapContext; import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout; +import com.vaadin.terminal.gwt.server.RpcManager.RpcInvocationException; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Component; @@ -1530,8 +1531,18 @@ public abstract class AbstractCommunicationManager implements Serializable { } if (invocation instanceof ServerRpcMethodInvocation) { - ServerRpcManager.applyInvocation(connector, - (ServerRpcMethodInvocation) invocation); + try { + ServerRpcManager.applyInvocation(connector, + (ServerRpcMethodInvocation) invocation); + } catch (RpcInvocationException e) { + Throwable realException = e.getCause(); + Component errorComponent = null; + if (connector instanceof Component) { + errorComponent = (Component) connector; + } + handleChangeVariablesError(root.getApplication(), + errorComponent, realException, null); + } } else { // All code below is for legacy variable changes @@ -1775,10 +1786,10 @@ public abstract class AbstractCommunicationManager implements Serializable { * map from variable names to values */ private void handleChangeVariablesError(Application application, - Component owner, Exception e, Map m) { + Component owner, Throwable t, Map m) { boolean handled = false; ChangeVariablesErrorEvent errorEvent = new ChangeVariablesErrorEvent( - owner, e, m); + owner, t, m); if (owner instanceof AbstractField) { try { diff --git a/src/com/vaadin/terminal/gwt/server/RpcManager.java b/src/com/vaadin/terminal/gwt/server/RpcManager.java index d240ab8467..026c847e2b 100644 --- a/src/com/vaadin/terminal/gwt/server/RpcManager.java +++ b/src/com/vaadin/terminal/gwt/server/RpcManager.java @@ -13,5 +13,36 @@ import java.io.Serializable; * @since 7.0 */ public interface RpcManager extends Serializable { - public void applyInvocation(ServerRpcMethodInvocation invocation); + public void applyInvocation(ServerRpcMethodInvocation invocation) + throws RpcInvocationException; + + /** + * Wrapper exception for exceptions which occur during invocation of an RPC + * call + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0 + * + */ + public static class RpcInvocationException extends Exception { + + public RpcInvocationException() { + super(); + } + + public RpcInvocationException(String message, Throwable cause) { + super(message, cause); + } + + public RpcInvocationException(String message) { + super(message); + } + + public RpcInvocationException(Throwable cause) { + super(cause); + } + + } + } diff --git a/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java b/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java index 07f83864c2..d9931a9610 100644 --- a/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java +++ b/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.server; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -66,9 +67,10 @@ public class ServerRpcManager implements RpcManager { * non-null target of the RPC call * @param invocation * method invocation to perform + * @throws RpcInvocationException */ public static void applyInvocation(RpcTarget target, - ServerRpcMethodInvocation invocation) { + ServerRpcMethodInvocation invocation) throws RpcInvocationException { RpcManager manager = target.getRpcManager(invocation .getInterfaceClass()); if (manager != null) { @@ -109,7 +111,8 @@ public class ServerRpcManager implements RpcManager { * @param invocation * method invocation to perform */ - public void applyInvocation(ServerRpcMethodInvocation invocation) { + public void applyInvocation(ServerRpcMethodInvocation invocation) + throws RpcInvocationException { Method method = invocation.getMethod(); Class[] parameterTypes = method.getParameterTypes(); Object[] args = new Object[parameterTypes.length]; @@ -125,7 +128,7 @@ public class ServerRpcManager implements RpcManager { try { method.invoke(implementation, args); } catch (Exception e) { - throw new RuntimeException("Unable to invoke method " + throw new RpcInvocationException("Unable to invoke method " + invocation.getMethodName() + " in " + invocation.getInterfaceName(), e); }