summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2013-11-26 14:49:12 +0200
committerVaadin Code Review <review@vaadin.com>2013-12-03 13:35:56 +0000
commit26b5b672df0aa3bdefdced81ed4619c11f3e945a (patch)
tree2a82389c617d0ba8715a695f3aa95b143c73cb5d
parent25fc48c52067237faa208cea849a775a7aa1668c (diff)
downloadvaadin-framework-26b5b672df0aa3bdefdced81ed4619c11f3e945a.tar.gz
vaadin-framework-26b5b672df0aa3bdefdced81ed4619c11f3e945a.zip
Timeout redirect timer is reset on server activity (#12446)
Change-Id: Iec2e3de627bc1cf5c7d39bf98715b1bf343e7519
-rw-r--r--WebContent/WEB-INF/web.xml15
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java4
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java74
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java85
4 files changed, 177 insertions, 1 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index 8a917966a1..f98b7c78d1 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -77,6 +77,16 @@
</servlet>
<servlet>
+ <!--
+ This servlet is a separate instance for the sole purpose of
+ testing #12446 (com.vaadin.tests.components.ui.TimeoutRedirectResetsOnActivity)
+ because it modifies the VaadinService timeout parameters
+ -->
+ <servlet-name>VaadinApplicationRunnerWithTimeoutRedirect</servlet-name>
+ <servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>VaadinApplicationRunnerWithPush</servlet-name>
<servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class>
<init-param>
@@ -117,6 +127,11 @@
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>VaadinApplicationRunnerWithTimeoutRedirect</servlet-name>
+ <url-pattern>/12446/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
<servlet-name>VaadinApplicationRunnerWithPush</servlet-name>
<url-pattern>/run-push/*</url-pattern>
</servlet-mapping>
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index f95cec4fbc..a87fa3e342 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -64,7 +64,6 @@ import com.google.gwt.user.client.Window.ClosingHandler;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
-import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadListener;
import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
@@ -1417,6 +1416,9 @@ public class ApplicationConnection {
if (meta.containsKey("timedRedirect")) {
final ValueMap timedRedirect = meta
.getValueMap("timedRedirect");
+ if (redirectTimer != null) {
+ redirectTimer.cancel();
+ }
redirectTimer = new Timer() {
@Override
public void run() {
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
new file mode 100644
index 0000000000..2c649c9ca8
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2013 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.components.ui;
+
+import com.vaadin.server.CustomizedSystemMessages;
+import com.vaadin.server.SystemMessages;
+import com.vaadin.server.SystemMessagesInfo;
+import com.vaadin.server.SystemMessagesProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class TimeoutRedirectResetsOnActivity extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ setupTimout(request);
+
+ addComponent(new Button("clicky", new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ // NOOP
+ }
+ }));
+ }
+
+ private void setupTimout(VaadinRequest request) {
+ request.getService().setSystemMessagesProvider(
+ new SystemMessagesProvider() {
+ @Override
+ public SystemMessages getSystemMessages(
+ SystemMessagesInfo systemMessagesInfo) {
+ CustomizedSystemMessages msgs = new CustomizedSystemMessages();
+ msgs.setSessionExpiredMessage(null);
+ msgs.setSessionExpiredCaption(null);
+ msgs.setSessionExpiredNotificationEnabled(true);
+ msgs.setSessionExpiredURL("http://example.com/");
+ return msgs;
+ }
+ });
+ /*
+ * NOTE: in practice, this means a timeout after 25 seconds, because of
+ * implementation details in
+ * com.vaadin.server.communication.MetadataWriter
+ */
+ getSession().getSession().setMaxInactiveInterval(10);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "The timeout redirect timer should reset if there's activity between the client and server.";
+ }
+
+ @Override
+ @SuppressWarnings("boxing")
+ protected Integer getTicketNumber() {
+ return 12446;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
new file mode 100644
index 0000000000..272bacb8d5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2000-2013 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.components.ui;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TimeoutRedirectResetsOnActivityTest extends MultiBrowserTest {
+ @Test
+ public void verifyRedirectWorks() throws Exception {
+ setDebug(true);
+ openTestURL();
+
+ long startTime = System.currentTimeMillis();
+ while (System.currentTimeMillis() - startTime < 30000) {
+ clickTheButton();
+ Thread.sleep(1000);
+ }
+
+ assertTrue("button disappeared before timeout", buttonIsStillThere());
+
+ Thread.sleep(30000);
+ assertTrue("no redirection occurred within 30 seconds",
+ !buttonIsStillThere());
+ }
+
+ private boolean buttonIsStillThere() {
+ try {
+ return getButton() != null;
+ } catch (NoSuchElementException e) {
+ return false;
+ }
+ }
+
+ private void clickTheButton() {
+ getButton().click();
+ }
+
+ private WebElement getButton() {
+ /*
+ * For some reason, the vaadinElement() method doesn't work when tests
+ * are run outside of "/run/" and "/run-push/" contexts. The given error
+ * message says that the generated Vaadin path doesn't match any
+ * elements, but when that selector is put into the recorder, the
+ * recorder finds it.
+ *
+ * XPath works fine.
+ */
+ /*-
+ return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]");
+ */
+ return getDriver().findElement(
+ By.xpath("//div[contains(@class,'v-button')]"));
+ }
+
+ @Override
+ protected String getDeploymentPath() {
+ /*
+ * AbstractTB3Test assumes only /run/ and /run-push/ contexts, so this
+ * method needs some overriding.
+ */
+ return "/12446/"
+ + TimeoutRedirectResetsOnActivity.class.getCanonicalName()
+ + "?restartApplication&debug";
+ }
+}