]> source.dussan.org Git - vaadin-framework.git/commitdiff
Pass RPC exceptions to Application.terminalError (#9018)
authorArtur Signell <artur@vaadin.com>
Thu, 21 Jun 2012 14:59:55 +0000 (17:59 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 21 Jun 2012 14:59:55 +0000 (17:59 +0300)
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/RpcManager.java
src/com/vaadin/terminal/gwt/server/ServerRpcManager.java

index 797f8f756c3e7a4aaf7e02f54870369ad327c8ea..1ea713b4f6a04b32df3951f461e0a2fb728aa268 100644 (file)
@@ -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<String, Object> m) {
+            Component owner, Throwable t, Map<String, Object> m) {
         boolean handled = false;
         ChangeVariablesErrorEvent errorEvent = new ChangeVariablesErrorEvent(
-                owner, e, m);
+                owner, t, m);
 
         if (owner instanceof AbstractField) {
             try {
index d240ab846712570e428ca2b5beb5ba12ba45d4ea..026c847e2b5dfd7e154c993ed9a63613e17e109f 100644 (file)
@@ -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);
+        }
+
+    }
+
 }
index 07f83864c24b8e0d9a44a4d398d10f8ee3495823..d9931a961092db5e0bd7c5a328ef22e8c7f9b58c 100644 (file)
@@ -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<T> 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<T> 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<T> 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);
         }