From 1384f1eb2c973252da27d6e379d8b863d912b22e Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 1 Nov 2012 15:10:40 +0200 Subject: When closeIdleUIs is true, close open UIs only after all UIs have been idle for longer than the session timeout * Rename closeIdleUIs to closeIdleSessions, isIdleUICleanupEnabled to isCloseIdleSessions (#10252) * Close the whole session at the same time as well * Move UI lastUidlRequestTime to VaadinSession lastRequestTimestamp (#10253) * Rename VaadinSession lastRequestTime to lastRequestDuration, totalSessionTime to cumulativeRequestDuration (#10253) * Rename UI lastHeartbeatTime to lastHeartbeatTimestamp * Show "Session Expired" notification when a heartbeat fails because of this Change-Id: If3d4bd9add9995f435c29812eec00b3a3a92a6e6 --- .../vaadin/client/ApplicationConfiguration.java | 6 ++ .../com/vaadin/client/ApplicationConnection.java | 78 +++++++++++----------- 2 files changed, 46 insertions(+), 38 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ApplicationConfiguration.java b/client/src/com/vaadin/client/ApplicationConfiguration.java index 4159b38211..1f35c408ae 100644 --- a/client/src/com/vaadin/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/client/ApplicationConfiguration.java @@ -199,6 +199,7 @@ public class ApplicationConfiguration implements EntryPoint { private boolean standalone; private ErrorMessage communicationError; private ErrorMessage authorizationError; + private ErrorMessage sessionExpiredError; private int heartbeatInterval; private HashMap unknownComponents; @@ -314,6 +315,10 @@ public class ApplicationConfiguration implements EntryPoint { return authorizationError; } + public ErrorMessage getSessionExpiredError() { + return sessionExpiredError; + } + /** * Reads the configuration values defined by the bootstrap javascript. */ @@ -353,6 +358,7 @@ public class ApplicationConfiguration implements EntryPoint { communicationError = jsoConfiguration.getConfigError("comErrMsg"); authorizationError = jsoConfiguration.getConfigError("authErrMsg"); + sessionExpiredError = jsoConfiguration.getConfigError("sessExpMsg"); // boostrap sets initPending to false if it has sent the browser details if (jsoConfiguration.getConfigBoolean("initPending") == Boolean.FALSE) { diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 23906f0e02..9133e3dfc5 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -960,9 +960,7 @@ public class ApplicationConnection { */ protected void showCommunicationError(String details, int statusCode) { VConsole.error("Communication error: " + details); - ErrorMessage communicationError = configuration.getCommunicationError(); - showError(details, communicationError.getCaption(), - communicationError.getMessage(), communicationError.getUrl()); + showError(details, configuration.getCommunicationError()); } /** @@ -973,9 +971,31 @@ public class ApplicationConnection { */ protected void showAuthenticationError(String details) { VConsole.error("Authentication error: " + details); - ErrorMessage authorizationError = configuration.getAuthorizationError(); - showError(details, authorizationError.getCaption(), - authorizationError.getMessage(), authorizationError.getUrl()); + showError(details, configuration.getAuthorizationError()); + } + + /** + * Shows the session expiration notification. + * + * @param details + * Optional details for debugging. + */ + protected void showSessionExpiredError(String details) { + VConsole.error("Session expired: " + details); + showError(details, configuration.getSessionExpiredError()); + } + + /** + * Shows an error notification. + * + * @param details + * Optional details for debugging. + * @param message + * An ErrorMessage describing the error. + */ + protected void showError(String details, ErrorMessage message) { + showError(details, message.getCaption(), message.getMessage(), + message.getUrl()); } /** @@ -1002,9 +1022,11 @@ public class ApplicationConnection { if (html.length() > 0) { // Add error description - html.append("

"); - html.append(details); - html.append("

"); + if (details != null) { + html.append("

"); + html.append(details); + html.append("

"); + } VNotification n = VNotification.createNotification(1000 * 60 * 45, uIConnector.getWidget()); @@ -1442,32 +1464,11 @@ public class ApplicationConnection { if (meta != null) { if (meta.containsKey("appError")) { ValueMap error = meta.getValueMap("appError"); - String html = ""; - if (error.containsKey("caption") - && error.getString("caption") != null) { - html += "

" + error.getAsString("caption") - + "

"; - } - if (error.containsKey("message") - && error.getString("message") != null) { - html += "

" + error.getAsString("message") - + "

"; - } - String url = null; - if (error.containsKey("url")) { - url = error.getString("url"); - } - if (html.length() != 0) { - /* 45 min */ - VNotification n = VNotification.createNotification( - 1000 * 60 * 45, uIConnector.getWidget()); - n.addEventListener(new NotificationRedirect(url)); - n.show(html, VNotification.CENTERED_TOP, - VNotification.STYLE_SYSTEM); - } else { - redirect(url); - } + showError(null, error.getString("caption"), + error.getString("message"), + error.getString("url")); + applicationRunning = false; } if (validatingLayouts) { @@ -3027,7 +3028,7 @@ public class ApplicationConnection { *

* Heartbeat requests are used to inform the server that the client-side is * still alive. If the client page is closed or the connection lost, the - * server will eventually close the inactive Root. + * server will eventually close the inactive UI. *

* TODO: Improved error handling, like in doUidlRequest(). * @@ -3051,16 +3052,17 @@ public class ApplicationConnection { // TODO Permit retry in some error situations VConsole.log("Heartbeat response OK"); scheduleHeartbeat(); + } else if (status == Response.SC_GONE) { + showSessionExpiredError(null); } else { - VConsole.error("Heartbeat request failed with status code " + VConsole.error("Failed sending heartbeat to server. Error code: " + status); } } @Override public void onError(Request request, Throwable exception) { - VConsole.error("Heartbeat request resulted in exception"); - VConsole.error(exception); + VConsole.error("Exception sending heartbeat: " + exception); } }; -- cgit v1.2.3