Skip to content

Commit

Permalink
Handle unknown connectors consistently and quietly as described in #8111
Browse files Browse the repository at this point in the history
 (#8741)

Fixes #8629
  • Loading branch information
Artur- authored and tsuoanttila committed Mar 16, 2017
1 parent 637afe2 commit 4ecf4f9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ protected void handleInvocations(UI ui, int lastSyncIdSeenByClient,
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;
}

Expand Down Expand Up @@ -423,6 +421,13 @@ protected void handleInvocations(UI ui, int lastSyncIdSeenByClient,
}
}

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
*
Expand Down Expand Up @@ -575,7 +580,10 @@ private ServerRpcMethodInvocation parseServerRpcInvocation(
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) {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 4ecf4f9

Please sign in to comment.