diff options
author | Leif Åstrand <leif@vaadin.com> | 2014-07-14 17:17:18 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-07-16 13:36:02 +0000 |
commit | 4252c4b40fc1a766815f3b762f4ef81a9a456093 (patch) | |
tree | 089d4055b8e6a4631a7044a627fc8a5eca316e0c | |
parent | 8f1d6d965be7adff75373d4406bddcbc2b22f27c (diff) | |
download | vaadin-framework-4252c4b40fc1a766815f3b762f4ef81a9a456093.tar.gz vaadin-framework-4252c4b40fc1a766815f3b762f4ef81a9a456093.zip |
Make it possible to disable the sync id checking (#14193)
Change-Id: I35c2a767d7726abbbe7bae56387952343ac21157
7 files changed, 57 insertions, 9 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index d968ea5306..510657561f 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -66,6 +66,7 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; +import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; @@ -1422,10 +1423,16 @@ public class ApplicationConnection implements HasHandlers { if (json.containsKey(ApplicationConstants.SERVER_SYNC_ID)) { int syncId = json.getInt(ApplicationConstants.SERVER_SYNC_ID); - assert (lastSeenServerSyncId == UNDEFINED_SYNC_ID || syncId == lastSeenServerSyncId + 1) : "Newly retrieved server sync id was not exactly one larger than the previous one (new: " - + syncId + ", last seen: " + lastSeenServerSyncId + ")"; + /* + * Use sync id unless explicitly set as undefined, as is done by + * e.g. critical server-side notifications + */ + if (syncId != -1) { + assert (lastSeenServerSyncId == UNDEFINED_SYNC_ID || syncId == lastSeenServerSyncId + 1) : "Newly retrieved server sync id was not exactly one larger than the previous one (new: " + + syncId + ", last seen: " + lastSeenServerSyncId + ")"; - lastSeenServerSyncId = syncId; + lastSeenServerSyncId = syncId; + } } else { VConsole.error("Server response didn't contain a sync id. " + "Please verify that the server is up-to-date and that the response data has not been modified in transmission."); diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java index 39329c32ce..34c9b5b767 100644 --- a/server/src/com/vaadin/server/Constants.java +++ b/server/src/com/vaadin/server/Constants.java @@ -126,6 +126,7 @@ public interface Constants { static final String SERVLET_PARAMETER_PUSH_MODE = "pushMode"; static final String SERVLET_PARAMETER_UI_PROVIDER = "UIProvider"; static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString"; + static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck"; // Configurable parameter names static final String PARAMETER_VAADIN_RESOURCES = "Resources"; diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index 6aeac684c2..7588e4fd79 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -59,6 +59,7 @@ import com.vaadin.server.communication.HeartbeatHandler; import com.vaadin.server.communication.PublishedFileHandler; import com.vaadin.server.communication.SessionRequestHandler; import com.vaadin.server.communication.UidlRequestHandler; +import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.JsonConstants; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.ui.UI; @@ -1590,6 +1591,7 @@ public abstract class VaadinService implements Serializable { json.put("resources", new JSONObject()); json.put("locales", new JSONObject()); json.put("meta", meta); + json.put(ApplicationConstants.SERVER_SYNC_ID, -1); returnString = json.toString(); } catch (JSONException e) { getLogger().log(Level.WARNING, diff --git a/server/src/com/vaadin/server/communication/ServerRpcHandler.java b/server/src/com/vaadin/server/communication/ServerRpcHandler.java index 89d87567d7..2619c272b4 100644 --- a/server/src/com/vaadin/server/communication/ServerRpcHandler.java +++ b/server/src/com/vaadin/server/communication/ServerRpcHandler.java @@ -33,6 +33,7 @@ import org.json.JSONException; import org.json.JSONObject; import com.vaadin.server.ClientConnector; +import com.vaadin.server.Constants; import com.vaadin.server.JsonCodec; import com.vaadin.server.LegacyCommunicationManager; import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException; @@ -78,7 +79,19 @@ public class ServerRpcHandler implements Serializable { public RpcRequest(String jsonString) throws JSONException { json = new JSONObject(jsonString); csrfToken = json.getString(ApplicationConstants.CSRF_TOKEN); - syncId = json.getInt(ApplicationConstants.SERVER_SYNC_ID); + + VaadinRequest request = VaadinService.getCurrentRequest(); + if (request == null + || request + .getService() + .getDeploymentConfiguration() + .getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_SYNC_ID_CHECK, + Boolean.toString(true)).equals("true")) { + syncId = json.getInt(ApplicationConstants.SERVER_SYNC_ID); + } else { + syncId = -1; + } invocations = new JSONArray( json.getString(ApplicationConstants.RPC_INVOCATIONS)); } diff --git a/server/src/com/vaadin/server/communication/UidlWriter.java b/server/src/com/vaadin/server/communication/UidlWriter.java index 00522e2aa5..d27b2ba5b5 100644 --- a/server/src/com/vaadin/server/communication/UidlWriter.java +++ b/server/src/com/vaadin/server/communication/UidlWriter.java @@ -33,10 +33,12 @@ import org.json.JSONException; import com.vaadin.annotations.JavaScript; import com.vaadin.annotations.StyleSheet; import com.vaadin.server.ClientConnector; +import com.vaadin.server.Constants; import com.vaadin.server.JsonPaintTarget; import com.vaadin.server.LegacyCommunicationManager; import com.vaadin.server.LegacyCommunicationManager.ClientCache; import com.vaadin.server.SystemMessages; +import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; import com.vaadin.shared.ApplicationConstants; import com.vaadin.ui.ConnectorTracker; @@ -75,10 +77,11 @@ public class UidlWriter implements Serializable { public void write(UI ui, Writer writer, boolean repaintAll, boolean async) throws IOException, JSONException { VaadinSession session = ui.getSession(); + VaadinService service = session.getService(); // Purge pending access calls as they might produce additional changes // to write out - session.getService().runPendingAccessTasks(session); + service.runPendingAccessTasks(session); ArrayList<ClientConnector> dirtyVisibleConnectors = ui .getConnectorTracker().getDirtyVisibleConnectors(); @@ -99,8 +102,15 @@ public class UidlWriter implements Serializable { uiConnectorTracker.setWritingResponse(true); try { + + int syncId = service + .getDeploymentConfiguration() + .getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_SYNC_ID_CHECK, + Boolean.toString(true)).equals("true") ? uiConnectorTracker + .getCurrentSyncId() : -1; writer.write("\"" + ApplicationConstants.SERVER_SYNC_ID + "\": " - + uiConnectorTracker.getCurrentSyncId() + ", "); + + syncId + ", "); writer.write("\"changes\" : "); diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index f7eae0013a..c0f973106b 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -774,7 +774,7 @@ public class ConnectorTracker implements Serializable { * concurrently or not. * @param lastSyncIdSeenByClient * the most recent sync id the client has seen at the time the - * request was sent + * request was sent, or -1 to ignore potential problems * @return <code>true</code> if the connector was removed before the client * had a chance to react to it. */ @@ -784,7 +784,8 @@ public class ConnectorTracker implements Serializable { assert getConnector(connectorId) == null : "Connector " + connectorId + " is still attached"; - boolean clientRequestIsTooOld = lastSyncIdSeenByClient < currentSyncId; + boolean clientRequestIsTooOld = lastSyncIdSeenByClient < currentSyncId + && lastSyncIdSeenByClient != -1; if (clientRequestIsTooOld) { /* * The headMap call is present here because we're only interested in @@ -823,6 +824,9 @@ public class ConnectorTracker implements Serializable { * packet is sent. If the state has changed on the server side since that, * the server can try to adjust the way it handles the actions from the * client side. + * <p> + * The sync id value <code>-1</code> is ignored to facilitate testing with + * pre-recorded requests. * * @see #setWritingResponse(boolean) * @see #connectorWasPresentAsRequestWasSent(String, long) @@ -846,6 +850,9 @@ public class ConnectorTracker implements Serializable { * Entries that both client and server agree upon are removed. Since * argument is the last sync id that the client has seen from the server, we * know that entries earlier than that cannot cause any problems anymore. + * <p> + * The sync id value <code>-1</code> is ignored to facilitate testing with + * pre-recorded requests. * * @see #connectorWasPresentAsRequestWasSent(String, long) * @since 7.2 @@ -854,6 +861,12 @@ public class ConnectorTracker implements Serializable { * server. */ public void cleanConcurrentlyRemovedConnectorIds(int lastSyncIdSeenByClient) { + if (lastSyncIdSeenByClient == -1) { + // Sync id checking is not in use, so we should just clear the + // entire map to avoid leaking memory + syncIdToUnregisteredConnectorIds.clear(); + return; + } /* * We remove all entries _older_ than the one reported right now, * because the remaining still contain components that might cause diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index 9f723763f8..da4ac7450d 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -111,7 +111,9 @@ public class ApplicationConstants implements Serializable { public static final String CSRF_TOKEN = "csrfToken"; /** - * The name of the parameter used to transmit the sync id + * The name of the parameter used to transmit the sync id. The value can be + * set to -1 e.g. when testing with pre-recorded requests to make the + * framework ignore the sync id. * * @see com.vaadin.ui.ConnectorTracker#getCurrentSyncId() * @since 7.2 |