From: Artur Signell Date: Fri, 4 May 2012 11:19:12 +0000 (+0300) Subject: Send widgetset version with the first UIDL request X-Git-Tag: 7.0.0.alpha3~248 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9fd13d260c3b0510272abed2170decf709f1062d;p=vaadin-framework.git Send widgetset version with the first UIDL request This enables the server to verify that the widgetset version match the servlet version --- diff --git a/src/com/vaadin/Version.java b/src/com/vaadin/Version.java new file mode 100644 index 0000000000..b0db50da74 --- /dev/null +++ b/src/com/vaadin/Version.java @@ -0,0 +1,71 @@ +package com.vaadin; + +import java.io.Serializable; + +public class Version implements Serializable { + /** + * The version number of this release. For example "6.2.0". Always in the + * format "major.minor.revision[.build]". The build part is optional. All of + * major, minor, revision must be integers. + */ + private static final String VERSION; + /** + * Major version number. For example 6 in 6.2.0. + */ + private static final int VERSION_MAJOR; + + /** + * Minor version number. For example 2 in 6.2.0. + */ + private static final int VERSION_MINOR; + + /** + * Version revision number. For example 0 in 6.2.0. + */ + private static final int VERSION_REVISION; + + /** + * Build identifier. For example "nightly-20091123-c9963" in + * 6.2.0.nightly-20091123-c9963. + */ + private static final String VERSION_BUILD; + + /* Initialize version numbers from string replaced by build-script. */ + static { + if ("@VERSION@".equals("@" + "VERSION" + "@")) { + VERSION = "9.9.9.INTERNAL-DEBUG-BUILD"; + } else { + VERSION = "@VERSION@"; + } + final String[] digits = VERSION.split("\\.", 4); + VERSION_MAJOR = Integer.parseInt(digits[0]); + VERSION_MINOR = Integer.parseInt(digits[1]); + VERSION_REVISION = Integer.parseInt(digits[2]); + if (digits.length == 4) { + VERSION_BUILD = digits[3]; + } else { + VERSION_BUILD = ""; + } + } + + public static String getFullVersion() { + return VERSION; + } + + public static int getMajorVersion() { + return VERSION_MAJOR; + } + + public static int getMinorVersion() { + return VERSION_MINOR; + } + + public static int getRevision() { + return VERSION_REVISION; + } + + public static String getBuildIdentifier() { + return VERSION_BUILD; + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index ff77c5904a..8eeccb828d 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -212,6 +212,7 @@ public class ApplicationConfiguration implements EntryPoint { private Class[] classes = new Class[1024]; private boolean browserDetailsSent = false; + private boolean widgetsetVersionSent = false; static// TODO consider to make this hashmap per application LinkedList callbacks = new LinkedList(); @@ -645,4 +646,23 @@ public class ApplicationConfiguration implements EntryPoint { browserDetailsSent = true; } + /** + * Checks whether the widget set version has been sent to the server. It is + * sent in the first UIDL request. + * + * @return true if browser information has already been sent + * + * @see ApplicationConnection#getNativeBrowserDetailsParameters(String) + */ + public boolean isWidgetsetVersionSent() { + return widgetsetVersionSent; + } + + /** + * Registers that the widget set version has been sent to the server. + */ + public void setWidgetsetVersionSent() { + widgetsetVersionSent = true; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 18b1afd813..8285e956e6 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -416,13 +416,10 @@ public class ApplicationConnection { // initial uidl request String nativeBootstrapParameters = getNativeBrowserDetailsParameters(getConfiguration() .getRootPanelId()); - String widgetsetVersion = ApplicationConfiguration.VERSION; - // TODO figure out how client and view size could be used better on // server. screen size can be accessed via Browser object, but other // values currently only via transaction listener. - String parameters = "repaintAll=1&" + nativeBootstrapParameters - + "&wsver=" + widgetsetVersion; + String parameters = "repaintAll=1&" + nativeBootstrapParameters; return parameters; } @@ -1723,7 +1720,15 @@ public class ApplicationConnection { } else { extraParams = ""; } + if (!getConfiguration().isWidgetsetVersionSent()) { + if (!extraParams.isEmpty()) { + extraParams += "&"; + } + String widgetsetVersion = ApplicationConfiguration.VERSION; + extraParams += "wsver=" + widgetsetVersion; + getConfiguration().setWidgetsetVersionSent(); + } makeUidlRequest(req.toString(), extraParams, forceSync); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 77698805de..1acc9d128a 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -333,21 +333,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet } } - /** - * Checks that the version reported by the client (widgetset) matches that - * of the server. - * - * @param request - */ - private void checkWidgetsetVersion(WrappedRequest request) { - if (!AbstractApplicationServlet.VERSION.equals(request - .getParameter("wsver"))) { - logger.warning(String.format(WIDGETSET_MISMATCH_INFO, - AbstractApplicationServlet.VERSION, - request.getParameter("wsver"))); - } - } - private void checkProductionMode() { // TODO Identical code in AbstractApplicationServlet -> refactor // Check if the application is in production mode. @@ -674,10 +659,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet return; } else if (requestType == RequestType.UIDL) { // Handles AJAX UIDL requests - if (isRepaintAll(request)) { - // warn if versions do not match - checkWidgetsetVersion(wrappedRequest); - } applicationManager.handleUidlRequest(wrappedRequest, wrappedResponse, portletWrapper, root); return; diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 6ab2748332..905cfe7e3c 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -90,51 +90,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements private static final Logger logger = Logger .getLogger(AbstractApplicationServlet.class.getName()); - /** - * The version number of this release. For example "6.2.0". Always in the - * format "major.minor.revision[.build]". The build part is optional. All of - * major, minor, revision must be integers. - */ - public static final String VERSION; - /** - * Major version number. For example 6 in 6.2.0. - */ - public static final int VERSION_MAJOR; - - /** - * Minor version number. For example 2 in 6.2.0. - */ - public static final int VERSION_MINOR; - - /** - * Version revision number. For example 0 in 6.2.0. - */ - public static final int VERSION_REVISION; - - /** - * Build identifier. For example "nightly-20091123-c9963" in - * 6.2.0.nightly-20091123-c9963. - */ - public static final String VERSION_BUILD; - - /* Initialize version numbers from string replaced by build-script. */ - static { - if ("@VERSION@".equals("@" + "VERSION" + "@")) { - VERSION = "9.9.9.INTERNAL-DEBUG-BUILD"; - } else { - VERSION = "@VERSION@"; - } - final String[] digits = VERSION.split("\\.", 4); - VERSION_MAJOR = Integer.parseInt(digits[0]); - VERSION_MINOR = Integer.parseInt(digits[1]); - VERSION_REVISION = Integer.parseInt(digits[2]); - if (digits.length == 4) { - VERSION_BUILD = digits[3]; - } else { - VERSION_BUILD = ""; - } - } - private Properties applicationProperties; private boolean productionMode = false; @@ -235,19 +190,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } } - /** - * Checks that the version reported by the client (widgetset) matches that - * of the server. - * - * @param request - */ - private void checkWidgetsetVersion(HttpServletRequest request) { - if (!VERSION.equals(request.getParameter("wsver"))) { - logger.warning(String.format(WIDGETSET_MISMATCH_INFO, VERSION, - request.getParameter("wsver"))); - } - } - private void checkProductionMode() { // Check if the application is in production mode. // We are in production mode if productionMode=true @@ -416,11 +358,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements return; } - if (isRepaintAll(request)) { - // warn if versions do not match - checkWidgetsetVersion(request); - } - Application application = null; boolean transactionStarted = false; boolean requestStarted = false; diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 97cb3114b9..8f942d9aee 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -45,6 +45,7 @@ import java.util.logging.Logger; import com.vaadin.Application; import com.vaadin.Application.SystemMessages; import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.Version; import com.vaadin.external.json.JSONArray; import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; @@ -499,6 +500,7 @@ public abstract class AbstractCommunicationManager implements Serializable { WrappedResponse response, Callback callback, Root root) throws IOException, InvalidUIDLSecurityKeyException { + checkWidgetsetVersion(request); requestThemeName = request.getParameter("theme"); maxInactiveInterval = request.getSessionMaxInactiveInterval(); // repaint requested or session has timed out and new one is created @@ -585,6 +587,27 @@ public abstract class AbstractCommunicationManager implements Serializable { requestThemeName = null; } + /** + * Checks that the version reported by the client (widgetset) matches that + * of the server. + * + * @param request + */ + private void checkWidgetsetVersion(WrappedRequest request) { + String widgetsetVersion = request.getParameter("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)) { + logger.warning(String.format(Constants.WIDGETSET_MISMATCH_INFO, + Version.getFullVersion(), widgetsetVersion)); + } + } + /** * Method called after the paint phase while still being synchronized on the * application diff --git a/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java b/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java index 84f87124d3..8a0c700121 100644 --- a/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java +++ b/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java @@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.Version; import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.terminal.DeploymentConfiguration; @@ -370,7 +371,7 @@ public abstract class BootstrapHandler implements RequestHandler { } JSONObject versionInfo = new JSONObject(); - versionInfo.put("vaadinVersion", AbstractApplicationServlet.VERSION); + versionInfo.put("vaadinVersion", Version.getFullVersion()); versionInfo.put("applicationVersion", application.getVersion()); appConfig.put("versionInfo", versionInfo); @@ -478,8 +479,8 @@ public abstract class BootstrapHandler implements RequestHandler { } Root root = context.getRoot(); - String title = ((root == null || root.getCaption() == null) ? "Vaadin " - + AbstractApplicationServlet.VERSION_MAJOR : root.getCaption()); + String title = ((root == null || root.getCaption() == null) ? "" : root + .getCaption()); page.write("" + AbstractApplicationServlet.safeEscapeForHtml(title)