Browse Source

Send widgetset version with the first UIDL request

This enables the server to verify that the widgetset version match the
servlet version
tags/7.0.0.alpha3
Artur Signell 12 years ago
parent
commit
9fd13d260c

+ 71
- 0
src/com/vaadin/Version.java View File

@@ -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;
}

}

+ 20
- 0
src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java View File

@@ -212,6 +212,7 @@ public class ApplicationConfiguration implements EntryPoint {
private Class<? extends ComponentConnector>[] classes = new Class[1024];

private boolean browserDetailsSent = false;
private boolean widgetsetVersionSent = false;

static// TODO consider to make this hashmap per application
LinkedList<Command> callbacks = new LinkedList<Command>();
@@ -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 <code>true</code> 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;
}

}

+ 9
- 4
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java View File

@@ -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);
}


+ 0
- 19
src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java View File

@@ -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;

+ 0
- 63
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java View File

@@ -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;

+ 23
- 0
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java View File

@@ -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

+ 4
- 3
src/com/vaadin/terminal/gwt/server/BootstrapHandler.java View File

@@ -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("<title>"
+ AbstractApplicationServlet.safeEscapeForHtml(title)

Loading…
Cancel
Save