From 47f44682e05e9526949bae549800592f82ac1ae7 Mon Sep 17 00:00:00 2001 From: Aleksi Hietanen Date: Thu, 13 Apr 2017 11:48:49 +0300 Subject: Use separate identifier for push connections Closes #8700 --- .../communication/AtmospherePushConnection.java | 12 ++++++------ .../vaadin/client/communication/MessageHandler.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'client') diff --git a/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java index ba7fa39a7d..511a37b7e6 100644 --- a/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java @@ -207,10 +207,10 @@ public class AtmospherePushConnection implements PushConnection { String extraParams = UIConstants.UI_ID_PARAMETER + "=" + connection.getConfiguration().getUIId(); - String csrfToken = connection.getMessageHandler().getCsrfToken(); - if (!csrfToken.equals(ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE)) { - extraParams += "&" + ApplicationConstants.CSRF_TOKEN_PARAMETER + "=" - + csrfToken; + String pushId = connection.getMessageHandler().getPushId(); + if (pushId != null) { + extraParams += "&" + ApplicationConstants.PUSH_ID_PARAMETER + "=" + + pushId; } // uri is needed to identify the right connection when closing @@ -526,7 +526,7 @@ public class AtmospherePushConnection implements PushConnection { JavaScriptObject config) /*-{ var self = this; - + config.url = uri; config.onOpen = $entry(function(response) { self.@com.vaadin.client.communication.AtmospherePushConnection::onOpen(*)(response); @@ -552,7 +552,7 @@ public class AtmospherePushConnection implements PushConnection { config.onClientTimeout = $entry(function(request) { self.@com.vaadin.client.communication.AtmospherePushConnection::onClientTimeout(*)(request); }); - + return $wnd.vaadinPush.atmosphere.subscribe(config); }-*/; diff --git a/client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/client/src/main/java/com/vaadin/client/communication/MessageHandler.java index dcc3810a2d..c9cbf5737f 100644 --- a/client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -134,6 +134,9 @@ public class MessageHandler { // will hold the CSRF token once received private String csrfToken = ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE; + // holds the push identifier once received + private String pushId = null; + /** Timer for automatic redirect to SessionExpiredURL */ private Timer redirectTimer; @@ -350,6 +353,12 @@ public class MessageHandler { csrfToken = json .getString(ApplicationConstants.UIDL_SECURITY_TOKEN_ID); } + + // Get push id if present + if (json.containsKey(ApplicationConstants.UIDL_PUSH_ID)) { + pushId = json.getString(ApplicationConstants.UIDL_PUSH_ID); + } + getLogger().info(" * Handling resources from server"); if (json.containsKey("resources")) { @@ -1687,6 +1696,16 @@ public class MessageHandler { return csrfToken; } + /** + * Gets the push connection identifier for this session. Used when + * establishing a push connection with the client. + * + * @return the push connection identifier string + */ + public String getPushId() { + return pushId; + } + /** * Checks whether state changes are currently being processed. Certain * operations are not allowed when the internal state of the application -- cgit v1.2.3