diff options
author | Artur Signell <artur@vaadin.com> | 2015-04-21 11:00:13 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-07-13 17:19:08 +0300 |
commit | 64411225cea6bf255fa6079a4ddf525979b79890 (patch) | |
tree | 629ad1d315f71637e83ddac1bb9e3b6261d783b6 /server/src | |
parent | ba2efda9d3d8c923ac996f5371e0de43dc5b4e59 (diff) | |
download | vaadin-framework-64411225cea6bf255fa6079a4ddf525979b79890.tar.gz vaadin-framework-64411225cea6bf255fa6079a4ddf525979b79890.zip |
Send resynchronize and widgetset version in JSON (#11733)
Change-Id: I7c75801102e10595b923ceab3900a17e166b5c78
Diffstat (limited to 'server/src')
6 files changed, 56 insertions, 52 deletions
diff --git a/server/src/com/vaadin/server/LegacyCommunicationManager.java b/server/src/com/vaadin/server/LegacyCommunicationManager.java index e982cdf10a..87b484a65f 100644 --- a/server/src/com/vaadin/server/LegacyCommunicationManager.java +++ b/server/src/com/vaadin/server/LegacyCommunicationManager.java @@ -353,6 +353,10 @@ public class LegacyCommunicationManager implements Serializable { res.clear(); } + public boolean isEmpty() { + return res.isEmpty(); + } + } /** diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 357278f411..87ce9ba81a 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -163,7 +163,7 @@ public class AtmospherePushConnection implements PushConnection { } else { try { Writer writer = new StringWriter(); - new UidlWriter().write(getUI(), writer, false, async); + new UidlWriter().write(getUI(), writer, async); sendMessage("for(;;);[{" + writer.toString() + "}]"); } catch (Exception e) { throw new RuntimeException("Push failed", e); diff --git a/server/src/com/vaadin/server/communication/ServerRpcHandler.java b/server/src/com/vaadin/server/communication/ServerRpcHandler.java index 85a8b341d0..f3d4b163ff 100644 --- a/server/src/com/vaadin/server/communication/ServerRpcHandler.java +++ b/server/src/com/vaadin/server/communication/ServerRpcHandler.java @@ -29,6 +29,7 @@ import java.util.logging.Level; import java.util.logging.Logger; 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; @@ -40,6 +41,7 @@ import com.vaadin.server.VaadinService; import com.vaadin.server.VariableOwner; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Connector; +import com.vaadin.shared.Version; import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.ServerRpc; @@ -78,6 +80,7 @@ public class ServerRpcHandler implements Serializable { private final JsonObject json; private final boolean resynchronize; private final int clientToServerMessageId; + private String widgetsetVersion = null; public RpcRequest(String jsonString, VaadinRequest request) { json = JsonUtil.parse(jsonString); @@ -107,6 +110,11 @@ public class ServerRpcHandler implements Serializable { } else { resynchronize = false; } + if (json.hasKey(ApplicationConstants.WIDGETSET_VERSION_ID)) { + widgetsetVersion = json + .getString(ApplicationConstants.WIDGETSET_VERSION_ID); + } + if (json.hasKey(ApplicationConstants.CLIENT_TO_SERVER_ID)) { clientToServerMessageId = (int) json .getNumber(ApplicationConstants.CLIENT_TO_SERVER_ID); @@ -178,6 +186,17 @@ public class ServerRpcHandler implements Serializable { public JsonObject getRawJson() { return json; } + + /** + * Gets the widget set version reported by the client + * + * @since 7.6 + * @return The widget set version reported by the client or null if the + * message did not contain a widget set version + */ + public String getWidgetsetVersion() { + return widgetsetVersion; + } } private static final int MAX_BUFFER_SIZE = 64 * 1024; @@ -217,6 +236,8 @@ public class ServerRpcHandler implements Serializable { throw new InvalidUIDLSecurityKeyException(""); } + checkWidgetsetVersion(rpcRequest.getWidgetsetVersion()); + int expectedId = ui.getLastProcessedClientToServerId() + 1; if (rpcRequest.getClientToServerId() != -1 && rpcRequest.getClientToServerId() != expectedId) { @@ -258,6 +279,29 @@ public class ServerRpcHandler implements Serializable { if (rpcRequest.isResynchronize()) { ui.getSession().getCommunicationManager().repaintAll(ui); } + + } + + /** + * Checks that the version reported by the client (widgetset) matches that + * of the server. + * + * @param widgetsetVersion + * the widget set version reported by the client or null + */ + private void checkWidgetsetVersion(String widgetsetVersion) { + if (widgetsetVersion == null) { + // Only check when the widgetset version is reported. It is reported + // in the first UIDL request (not the initial request as it is a + // plain GET /) + return; + } + + if (!Version.getFullVersion().equals(widgetsetVersion)) { + getLogger().warning( + String.format(Constants.WIDGETSET_MISMATCH_INFO, + Version.getFullVersion(), widgetsetVersion)); + } } /** diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java index 3a6dc1e55f..f380a6df6e 100644 --- a/server/src/com/vaadin/server/communication/UIInitHandler.java +++ b/server/src/com/vaadin/server/communication/UIInitHandler.java @@ -282,7 +282,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler { if (session.getConfiguration().isXsrfProtectionEnabled()) { writer.write(getSecurityKeyUIDL(session)); } - new UidlWriter().write(uI, writer, true, false); + new UidlWriter().write(uI, writer, false); writer.write("}"); String initialUIDL = writer.toString(); diff --git a/server/src/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/com/vaadin/server/communication/UidlRequestHandler.java index 33a3669b7f..dda3d81453 100644 --- a/server/src/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/com/vaadin/server/communication/UidlRequestHandler.java @@ -22,7 +22,6 @@ import java.io.Writer; import java.util.logging.Level; import java.util.logging.Logger; -import com.vaadin.server.Constants; import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException; import com.vaadin.server.ServletPortletHelper; import com.vaadin.server.SessionExpiredHandler; @@ -32,9 +31,7 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinResponse; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; -import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.JsonConstants; -import com.vaadin.shared.Version; import com.vaadin.ui.UI; import elemental.json.JsonException; @@ -76,29 +73,12 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements return true; } - checkWidgetsetVersion(request); - // repaint requested or session has timed out and new one is created - boolean repaintAll; - - // TODO PUSH analyzeLayouts should be - // part of the message payload to make the functionality transport - // agnostic - - // Resynchronize is sent in the payload but will still support the - // parameter also for compatibility reasons - repaintAll = (request - .getParameter(ApplicationConstants.URL_PARAMETER_REPAINT_ALL) != null); - StringWriter stringWriter = new StringWriter(); try { rpcHandler.handleRpc(uI, request.getReader(), request); - if (repaintAll) { - session.getCommunicationManager().repaintAll(uI); - } - - writeUidl(request, response, uI, stringWriter, repaintAll); + writeUidl(request, response, uI, stringWriter); } catch (JsonException e) { getLogger().log(Level.SEVERE, "Error writing JSON to response", e); // Refresh on client side @@ -119,28 +99,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements stringWriter.toString()); } - /** - * Checks that the version reported by the client (widgetset) matches that - * of the server. - * - * @param request - */ - private void checkWidgetsetVersion(VaadinRequest request) { - String widgetsetVersion = request.getParameter("v-wsver"); - if (widgetsetVersion == null) { - // Only check when the widgetset version is reported. It is reported - // in the first UIDL request (not the initial request as it is a - // plain GET /) - return; - } - - if (!Version.getFullVersion().equals(widgetsetVersion)) { - getLogger().warning( - String.format(Constants.WIDGETSET_MISMATCH_INFO, - Version.getFullVersion(), widgetsetVersion)); - } - } - private void writeRefresh(VaadinRequest request, VaadinResponse response) throws IOException { String json = VaadinService.createCriticalNotificationJSON(null, null, @@ -149,10 +107,10 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements } private void writeUidl(VaadinRequest request, VaadinResponse response, - UI ui, Writer writer, boolean repaintAll) throws IOException { + UI ui, Writer writer) throws IOException { openJsonMessage(writer, response); - new UidlWriter().write(ui, writer, repaintAll, false); + new UidlWriter().write(ui, writer, false); closeJsonMessage(writer); } diff --git a/server/src/com/vaadin/server/communication/UidlWriter.java b/server/src/com/vaadin/server/communication/UidlWriter.java index 3d52230927..c2f3c507bb 100644 --- a/server/src/com/vaadin/server/communication/UidlWriter.java +++ b/server/src/com/vaadin/server/communication/UidlWriter.java @@ -63,8 +63,6 @@ public class UidlWriter implements Serializable { * The {@link UI} whose changes to write * @param writer * The writer to use - * @param repaintAll - * Whether the client should re-render the whole UI. * @param analyzeLayouts * Whether detected layout problems should be logged. * @param async @@ -74,8 +72,7 @@ public class UidlWriter implements Serializable { * @throws IOException * If the writing fails. */ - public void write(UI ui, Writer writer, boolean repaintAll, boolean async) - throws IOException { + public void write(UI ui, Writer writer, boolean async) throws IOException { VaadinSession session = ui.getSession(); VaadinService service = session.getService(); @@ -86,6 +83,8 @@ public class UidlWriter implements Serializable { Set<ClientConnector> processedConnectors = new HashSet<ClientConnector>(); LegacyCommunicationManager manager = session.getCommunicationManager(); + ClientCache clientCache = manager.getClientCache(ui); + boolean repaintAll = clientCache.isEmpty(); // Paints components ConnectorTracker uiConnectorTracker = ui.getConnectorTracker(); getLogger().log(Level.FINE, "* Creating response to client"); @@ -205,7 +204,6 @@ public class UidlWriter implements Serializable { Collection<Class<? extends ClientConnector>> usedClientConnectors = paintTarget .getUsedClientConnectors(); boolean typeMappingsOpen = false; - ClientCache clientCache = manager.getClientCache(ui); List<Class<? extends ClientConnector>> newConnectorTypes = new ArrayList<Class<? extends ClientConnector>>(); |