]> source.dussan.org Git - vaadin-framework.git/commitdiff
Handle unknown connectors consistently and quietly as described in #8111 (#8741)
authorArtur <artur@vaadin.com>
Tue, 7 Mar 2017 07:46:33 +0000 (09:46 +0200)
committerAleksi Hietanen <aleksi@vaadin.com>
Tue, 7 Mar 2017 07:46:33 +0000 (09:46 +0200)
Fixes #8629

server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java
server/src/test/java/com/vaadin/server/communication/ServerRpcHandlerTest.java [new file with mode: 0644]

index d0be98332c58da1c8a2451d59fc06ff3af1e6541..39b26212079f16172d8da1800e7c6296f5a128e8 100644 (file)
@@ -351,11 +351,9 @@ public class ServerRpcHandler implements Serializable {
                 final ClientConnector connector = connectorTracker
                         .getConnector(invocation.getConnectorId());
                 if (connector == null) {
-                    getLogger().log(Level.WARNING,
-                            "Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})",
-                            new Object[] { invocation.getConnectorId(),
-                                    invocation.getInterfaceName(),
-                                    invocation.getMethodName() });
+                    logUnknownConnector(invocation.getConnectorId(),
+                            invocation.getInterfaceName(),
+                            invocation.getMethodName());
                     continue;
                 }
 
@@ -415,6 +413,13 @@ public class ServerRpcHandler implements Serializable {
         }
     }
 
+    private void logUnknownConnector(String connectorId, String interfaceName,
+            String methodName) {
+        getLogger().log(Level.FINE,
+                "Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})",
+                new Object[] { connectorId, interfaceName, methodName });
+    }
+
     /**
      * Handles the given RPC method invocation for the given connector
      *
@@ -567,7 +572,10 @@ public class ServerRpcHandler implements Serializable {
             JsonArray parametersJson, ConnectorTracker connectorTracker)
             throws JsonException {
         ClientConnector connector = connectorTracker.getConnector(connectorId);
-
+        if (connector == null) {
+            logUnknownConnector(connectorId, interfaceName, methodName);
+            return null;
+        }
         ServerRpcManager<?> rpcManager = connector.getRpcManager(interfaceName);
         if (rpcManager == null) {
             /*
diff --git a/server/src/test/java/com/vaadin/server/communication/ServerRpcHandlerTest.java b/server/src/test/java/com/vaadin/server/communication/ServerRpcHandlerTest.java
new file mode 100644 (file)
index 0000000..70ef0f4
--- /dev/null
@@ -0,0 +1,49 @@
+package com.vaadin.server.communication;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinService;
+import com.vaadin.tests.util.AlwaysLockedVaadinSession;
+import com.vaadin.ui.UI;
+
+import elemental.json.Json;
+import elemental.json.JsonArray;
+
+public class ServerRpcHandlerTest {
+
+    public static class TestUI extends UI {
+
+        @Override
+        protected void init(VaadinRequest request) {
+
+        }
+
+    }
+
+    @Test
+    public void handleUnknownConnector() {
+        ServerRpcHandler rpcHandler = new ServerRpcHandler();
+        JsonArray invocation = Json.createArray();
+        invocation.set(0, "12");
+        invocation.set(1, "someInterface");
+        invocation.set(2, "someMethod");
+        JsonArray params = Json.createArray();
+        invocation.set(3, params);
+
+        JsonArray invocationData = Json.createArray();
+        invocationData.set(0, invocation);
+
+        AlwaysLockedVaadinSession s = new AlwaysLockedVaadinSession(
+                Mockito.mock(VaadinService.class));
+        TestUI ui = new TestUI();
+        ui.doInit(Mockito.mock(VaadinRequest.class), 1, null);
+        ui.setSession(s);
+        s.addUI(ui);
+        rpcHandler.handleInvocations(ui, 1, invocationData);
+
+        // This only tests that an invocation for a non-existant connector does
+        // not cause any exceptions
+    }
+}