summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/client/communication/AtmospherePushConnection.java8
-rw-r--r--server/src/com/vaadin/ui/PushConfiguration.java37
-rw-r--r--shared/src/com/vaadin/shared/ui/ui/UIState.java1
-rw-r--r--uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java35
-rw-r--r--uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhrTest.java29
5 files changed, 110 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
index fb261cb9b6..ee2a35fcc2 100644
--- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
+++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java
@@ -227,6 +227,10 @@ public class AtmospherePushConnection implements PushConnection {
// If we are not using websockets, we want to send XHRs
return false;
}
+ if (getPushConfigurationState().alwaysUseXhrForServerRequests) {
+ // If user has forced us to use XHR, let's abide
+ return false;
+ }
if (state == State.CONNECT_PENDING) {
// Not sure yet, let's go for using websockets still as still will
// delay the message until a connection is established. When the
@@ -237,6 +241,10 @@ public class AtmospherePushConnection implements PushConnection {
};
+ private PushConfigurationState getPushConfigurationState() {
+ return connection.getUIConnector().getState().pushConfiguration;
+ }
+
@Override
public void push(JsonObject message) {
if (!isBidirectional()) {
diff --git a/server/src/com/vaadin/ui/PushConfiguration.java b/server/src/com/vaadin/ui/PushConfiguration.java
index 90ad28542c..22941ea5ae 100644
--- a/server/src/com/vaadin/ui/PushConfiguration.java
+++ b/server/src/com/vaadin/ui/PushConfiguration.java
@@ -139,6 +139,33 @@ public interface PushConfiguration extends Serializable {
*/
public void setParameter(String parameter, String value);
+ /**
+ * Sets whether to force the use of XHR when sending data from the client to
+ * the server.
+ *
+ * This settings currently only has effect when using websockets, which by
+ * default send client to server requests through the websockets channel. If
+ * you need to support cookies, HTTP auth or similar features not available
+ * in websockets communication you can set this to true.
+ *
+ * @since 7.6
+ * @param alwaysUseXhrForServerRequests
+ * true to always use XHR for server requests, false otherwise
+ */
+ public void setAlwaysUseXhrForServerRequests(
+ boolean alwaysUseXhrForServerRequests);
+
+ /**
+ * Checks whether to force the use of XHR when sending data from the client
+ * to the server.
+ *
+ * @see #setAlwaysUseXhrForServerRequests(boolean)
+ *
+ * @since 7.6
+ * @return true to always use XHR for server requests, false otherwise
+ */
+ public boolean isAlwaysUseXhrForServerRequests();
+
}
class PushConfigurationImpl implements PushConfiguration {
@@ -291,4 +318,14 @@ class PushConfigurationImpl implements PushConfiguration {
.keySet());
}
+ @Override
+ public void setAlwaysUseXhrForServerRequests(
+ boolean alwaysUseXhrForServerRequests) {
+ getState().alwaysUseXhrForServerRequests = alwaysUseXhrForServerRequests;
+ }
+
+ @Override
+ public boolean isAlwaysUseXhrForServerRequests() {
+ return getState(false).alwaysUseXhrForServerRequests;
+ }
}
diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java
index 0e21324cc2..6991f2b1cb 100644
--- a/shared/src/com/vaadin/shared/ui/ui/UIState.java
+++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java
@@ -114,6 +114,7 @@ public class UIState extends TabIndexState {
public static final String TRANSPORT_PARAM = "transport";
public static final String FALLBACK_TRANSPORT_PARAM = "fallbackTransport";
+ public boolean alwaysUseXhrForServerRequests = false;
public PushMode mode = PushMode.DISABLED;
public Map<String, String> parameters = new HashMap<String, String>();
{
diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java
new file mode 100644
index 0000000000..4f0769e3d7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.push;
+
+import com.vaadin.annotations.Push;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.ui.Transport;
+import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
+
+@Push(transport = Transport.WEBSOCKET)
+public class BasicPushWebsocketXhr extends BasicPush {
+
+ @Override
+ public void init(VaadinRequest request) {
+ super.init(request);
+ // Don't use fallback so we can easier detect if websocket fails
+ getPushConfiguration().setParameter(
+ PushConfigurationState.FALLBACK_TRANSPORT_PARAM, "none");
+ getPushConfiguration().setAlwaysUseXhrForServerRequests(true);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhrTest.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhrTest.java
new file mode 100644
index 0000000000..430246d66a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhrTest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.push;
+
+import java.util.List;
+
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.tb3.WebsocketTest;
+
+public class BasicPushWebsocketXhrTest extends BasicPushTest {
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ return getBrowsersSupportingWebSocket();
+ }
+}