diff options
author | Artur Signell <artur@vaadin.com> | 2015-08-31 11:43:31 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-08-31 13:23:24 +0300 |
commit | 9aafe4d1c535e9f79c09f33d2e1a1f8cc344eaa0 (patch) | |
tree | 59a3e8acc083a06376c62e95a8b2f9ff7c0610a4 | |
parent | b71cc2ffa9b96cfcaa045692eee4952678391850 (diff) | |
download | vaadin-framework-9aafe4d1c535e9f79c09f33d2e1a1f8cc344eaa0.tar.gz vaadin-framework-9aafe4d1c535e9f79c09f33d2e1a1f8cc344eaa0.zip |
Use Transport.WEBSOCKET_XHR instead of setter for mixing websockets and XHR (#11733)
Change-Id: I2fad7d367d8a4ba476ae0705672ebc2ee7cfeb1c
6 files changed, 44 insertions, 47 deletions
diff --git a/client/src/com/vaadin/client/communication/ServerCommunicationHandler.java b/client/src/com/vaadin/client/communication/ServerCommunicationHandler.java index 38b3321b27..12f7dee1d1 100644 --- a/client/src/com/vaadin/client/communication/ServerCommunicationHandler.java +++ b/client/src/com/vaadin/client/communication/ServerCommunicationHandler.java @@ -328,11 +328,17 @@ public class ServerCommunicationHandler { * @return A string representation of the current transport type */ public String getCommunicationMethodName() { + String clientToServer = "XHR"; + String serverToClient = "-"; if (push != null) { - return "Push (" + push.getTransportType() + ")"; - } else { - return "XHR"; + serverToClient = push.getTransportType(); + if (push.isBidirectional()) { + clientToServer = serverToClient; + } } + + return "Client to server: " + clientToServer + ", " + + "server to client: " + serverToClient; } private CommunicationProblemHandler getCommunicationProblemHandler() { diff --git a/server/src/com/vaadin/ui/PushConfiguration.java b/server/src/com/vaadin/ui/PushConfiguration.java index 22941ea5ae..6eaf683d99 100644 --- a/server/src/com/vaadin/ui/PushConfiguration.java +++ b/server/src/com/vaadin/ui/PushConfiguration.java @@ -139,33 +139,6 @@ 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 { @@ -234,8 +207,14 @@ class PushConfigurationImpl implements PushConfiguration { @Override public Transport getTransport() { try { - return Transport + Transport tr = Transport .getByIdentifier(getParameter(PushConfigurationState.TRANSPORT_PARAM)); + if (tr == Transport.WEBSOCKET + && getState(false).alwaysUseXhrForServerRequests) { + return Transport.WEBSOCKET_XHR; + } else { + return tr; + } } catch (IllegalArgumentException e) { return null; } @@ -250,8 +229,16 @@ class PushConfigurationImpl implements PushConfiguration { */ @Override public void setTransport(Transport transport) { - setParameter(PushConfigurationState.TRANSPORT_PARAM, - transport.getIdentifier()); + if (transport == Transport.WEBSOCKET_XHR) { + getState().alwaysUseXhrForServerRequests = true; + // Atmosphere knows only about "websocket" + setParameter(PushConfigurationState.TRANSPORT_PARAM, + Transport.WEBSOCKET.getIdentifier()); + } else { + getState().alwaysUseXhrForServerRequests = false; + setParameter(PushConfigurationState.TRANSPORT_PARAM, + transport.getIdentifier()); + } } /* @@ -278,6 +265,10 @@ class PushConfigurationImpl implements PushConfiguration { */ @Override public void setFallbackTransport(Transport fallbackTransport) { + if (fallbackTransport == Transport.WEBSOCKET_XHR) { + throw new IllegalArgumentException( + "WEBSOCKET_XHR can only be used as primary transport"); + } setParameter(PushConfigurationState.FALLBACK_TRANSPORT_PARAM, fallbackTransport.getIdentifier()); } @@ -318,14 +309,4 @@ 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/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java b/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java index 305b2e06cd..80e7dd9261 100644 --- a/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java +++ b/server/tests/src/com/vaadin/ui/PushConfigurationTransportTest.java @@ -40,6 +40,12 @@ public class PushConfigurationTransportTest { ui.getPushConfiguration().setTransport(transport); Assert.assertEquals(ui.getPushConfiguration().getTransport(), transport); + + if (transport == Transport.WEBSOCKET_XHR) { + Assert.assertTrue(ui.getState().pushConfiguration.alwaysUseXhrForServerRequests); + } else { + Assert.assertFalse(ui.getState().pushConfiguration.alwaysUseXhrForServerRequests); + } } } diff --git a/shared/src/com/vaadin/shared/ui/ui/Transport.java b/shared/src/com/vaadin/shared/ui/ui/Transport.java index 54d0f08434..6263f3039d 100644 --- a/shared/src/com/vaadin/shared/ui/ui/Transport.java +++ b/shared/src/com/vaadin/shared/ui/ui/Transport.java @@ -28,6 +28,12 @@ public enum Transport { */ WEBSOCKET("websocket"), /** + * Websockets for server to client, XHR for client to server + * + * @since 7.6 + */ + WEBSOCKET_XHR("websocket-xhr"), + /** * HTTP streaming * * @deprecated Use the more reliable {@link Transport#LONG_POLLING} instead. diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index 296e68008e..33ff504d8d 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -125,8 +125,7 @@ public abstract class AbstractTestUI extends UI { } else if ("websocket".equals(transport)) { enablePush(Transport.WEBSOCKET); } else if ("websocket-xhr".equals(transport)) { - enablePush(Transport.WEBSOCKET); - getPushConfiguration().setAlwaysUseXhrForServerRequests(true); + enablePush(Transport.WEBSOCKET_XHR); } else if ("streaming".equals(transport)) { enablePush(Transport.STREAMING); } else if ("long-polling".equals(transport)) { diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java index 4f0769e3d7..e31eb2a369 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketXhr.java @@ -20,7 +20,7 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.Transport; import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; -@Push(transport = Transport.WEBSOCKET) +@Push(transport = Transport.WEBSOCKET_XHR) public class BasicPushWebsocketXhr extends BasicPush { @Override @@ -29,7 +29,6 @@ public class BasicPushWebsocketXhr extends BasicPush { // Don't use fallback so we can easier detect if websocket fails getPushConfiguration().setParameter( PushConfigurationState.FALLBACK_TRANSPORT_PARAM, "none"); - getPushConfiguration().setAlwaysUseXhrForServerRequests(true); } } |