]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add transport parameter to @Push (#11966)
authorArtur Signell <artur@vaadin.com>
Mon, 3 Jun 2013 20:15:43 +0000 (23:15 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 5 Jun 2013 12:17:10 +0000 (12:17 +0000)
Change-Id: Ic47e68a41ba407917a990ef82a98c1526a9510ef

server/src/com/vaadin/annotations/Push.java
server/src/com/vaadin/server/UIProvider.java
server/src/com/vaadin/server/communication/UIInitHandler.java
uitest/src/com/vaadin/tests/push/BasicPushStreaming.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html [new file with mode: 0644]

index 58e70acf21ad098cefd09fa31ca2d34284341eff..d5e42d6f605756e409a3c442f0ffb5084b100950 100644 (file)
@@ -22,6 +22,7 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 import com.vaadin.shared.communication.PushMode;
+import com.vaadin.shared.ui.ui.Transport;
 import com.vaadin.ui.UI;
 
 /**
@@ -46,4 +47,13 @@ public @interface Push {
      */
     public PushMode value() default PushMode.AUTOMATIC;
 
+    /**
+     * Returns the transport type used for the push for the annotated UI. The
+     * default transport type when this annotation is present is
+     * {@link Transport#WEBSOCKET}.
+     * 
+     * @return the transport type to use
+     */
+    public Transport transport() default Transport.DEFAULT;
+
 }
index 0305b907e68db1090ea5ae7b392a6f5c5b60275b..3e7c85aea9d56e2ebb1719a7085f753d56fef040 100644 (file)
@@ -25,6 +25,7 @@ import com.vaadin.annotations.Theme;
 import com.vaadin.annotations.Title;
 import com.vaadin.annotations.Widgetset;
 import com.vaadin.shared.communication.PushMode;
+import com.vaadin.shared.ui.ui.Transport;
 import com.vaadin.ui.UI;
 
 public abstract class UIProvider implements Serializable {
@@ -174,4 +175,27 @@ public abstract class UIProvider implements Serializable {
             return push.value();
         }
     }
+
+    /**
+     * Finds the {@link Transport} to use for a specific UI. If no transport is
+     * defined, <code>null</code> is returned.
+     * <p>
+     * The default implementation uses the @{@link Push} annotation if it's
+     * defined for the UI class.
+     * 
+     * @param event
+     *            the UI create event with information about the UI and the
+     *            current request.
+     * @return the transport type to use, or <code>null</code> if the default
+     *         transport type should be used
+     */
+    public Transport getPushTransport(UICreateEvent event) {
+        Push push = getAnnotationFor(event.getUIClass(), Push.class);
+        if (push == null) {
+            return null;
+        } else {
+            return push.transport();
+        }
+    }
+
 }
index 9807ea6a9fccf719b909ae70d6b595fcc6eeaf52..d4b0bc709ffd14ee3b9fa84294f8f8976c547712 100644 (file)
@@ -39,6 +39,7 @@ import com.vaadin.server.VaadinService;
 import com.vaadin.server.VaadinSession;
 import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.communication.PushMode;
+import com.vaadin.shared.ui.ui.Transport;
 import com.vaadin.shared.ui.ui.UIConstants;
 import com.vaadin.ui.UI;
 
@@ -211,6 +212,11 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler {
         }
         ui.getPushConfiguration().setPushMode(pushMode);
 
+        Transport transport = provider.getPushTransport(event);
+        if (transport != null) {
+            ui.getPushConfiguration().setTransport(transport);
+        }
+
         // Set thread local here so it is available in init
         UI.setCurrent(ui);
 
diff --git a/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java b/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java
new file mode 100644 (file)
index 0000000..37a8afd
--- /dev/null
@@ -0,0 +1,12 @@
+package com.vaadin.tests.push;
+
+import com.vaadin.annotations.Push;
+import com.vaadin.shared.ui.ui.Transport;
+
+@Push(transport = Transport.STREAMING)
+public class BasicPushStreaming extends BasicPush {
+    @Override
+    protected void setup(com.vaadin.server.VaadinRequest request) {
+        addComponent(new PushConfigurator(this));
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java
new file mode 100644 (file)
index 0000000..6fc27e8
--- /dev/null
@@ -0,0 +1,8 @@
+package com.vaadin.tests.push;
+
+import com.vaadin.annotations.Push;
+import com.vaadin.shared.ui.ui.Transport;
+
+@Push(transport = Transport.WEBSOCKET)
+public class BasicPushWebsocket extends BasicPush {
+}
diff --git a/uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html b/uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html
new file mode 100644 (file)
index 0000000..854dd45
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.push.BasicPushStreaming?debug&amp;restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForTextPresent</td>
+       <td>Push connection established using streaming</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertTextNotPresent</td>
+       <td>Push connection established using websocket</td>
+       <td></td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.push.BasicPushWebsocket?debug&amp;restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertTextNotPresent</td>
+       <td>Push connection established using streaming</td>
+       <td></td>
+</tr>
+<tr>
+       <td>waitForTextPresent</td>
+       <td>Push connection established using websocket</td>
+       <td></td>
+</tr>
+</tbody></table>
+</body>
+</html>