diff options
author | Artur <artur@vaadin.com> | 2017-02-22 12:21:38 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-02-22 12:21:38 +0200 |
commit | 04a20bf66646bc10f219966ad18af8b7bd995c77 (patch) | |
tree | b1c7d54c72c9c09da45549389a059bce32528981 | |
parent | ca1bfa7511e35fad802271604158afd7be6531d0 (diff) | |
download | vaadin-framework-04a20bf66646bc10f219966ad18af8b7bd995c77.tar.gz vaadin-framework-04a20bf66646bc10f219966ad18af8b7bd995c77.zip |
Support Vaadin custom protocols in Vaadin-Refresh redirects (#8597)
A login page you want to redirect to is typically in the webapp root,
which you can now refer to as "Vaadin-Refresh: context://login.html"
5 files changed, 95 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/communication/DefaultConnectionStateHandler.java b/client/src/main/java/com/vaadin/client/communication/DefaultConnectionStateHandler.java index af3f229312..f98165b105 100644 --- a/client/src/main/java/com/vaadin/client/communication/DefaultConnectionStateHandler.java +++ b/client/src/main/java/com/vaadin/client/communication/DefaultConnectionStateHandler.java @@ -421,7 +421,8 @@ public class DefaultConnectionStateHandler implements ConnectionStateHandler { + "(:\\s*(.*?))?(\\s|$)") .exec(responseText); if (refreshToken != null) { - WidgetUtil.redirect(refreshToken.getGroup(2)); + WidgetUtil.redirect(getConnection() + .translateVaadinUri(refreshToken.getGroup(2))); } else { handleUnrecoverableCommunicationError( "Invalid JSON response from server: " + responseText, diff --git a/uitest/src/main/java/com/vaadin/tests/applicationservlet/VaadinRefreshServlet.java b/uitest/src/main/java/com/vaadin/tests/applicationservlet/VaadinRefreshServlet.java new file mode 100644 index 0000000000..ef179d012b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/applicationservlet/VaadinRefreshServlet.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2016 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.applicationservlet; + +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.VaadinServlet; + +@VaadinServletConfiguration(ui = ContextProtocol.class, productionMode = false) +public class VaadinRefreshServlet extends VaadinServlet { + + @Override + protected void service(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + if (request.getRequestURI().contains("/UIDL")) { + InputStream loginHtml = request.getServletContext() + .getResourceAsStream("/statictestfiles/login.html"); + IOUtils.copy(loginHtml, response.getOutputStream()); + return; + } + super.service(request, response); + } +} diff --git a/uitest/src/main/webapp/WEB-INF/web.xml b/uitest/src/main/webapp/WEB-INF/web.xml index 5a1e3357da..b1ec909d21 100644 --- a/uitest/src/main/webapp/WEB-INF/web.xml +++ b/uitest/src/main/webapp/WEB-INF/web.xml @@ -64,6 +64,11 @@ <async-supported>false</async-supported> </servlet> <servlet> + <servlet-name>VaadinRefresh</servlet-name> + <servlet-class>com.vaadin.tests.applicationservlet.VaadinRefreshServlet</servlet-class> + <async-supported>true</async-supported> + </servlet> + <servlet> <servlet-name>VaadinApplicationRunner</servlet-name> <servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class> <!-- Non-default values for testing purposes --> @@ -203,6 +208,10 @@ <servlet-name>ResourcesFromServlet</servlet-name> <url-pattern>/servlet-with-resources/*</url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name>VaadinRefresh</servlet-name> + <url-pattern>/vaadinrefresh/*</url-pattern> + </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> diff --git a/uitest/src/main/webapp/statictestfiles/login.html b/uitest/src/main/webapp/statictestfiles/login.html new file mode 100644 index 0000000000..5057643cbf --- /dev/null +++ b/uitest/src/main/webapp/statictestfiles/login.html @@ -0,0 +1,5 @@ +<html> +<!-- Vaadin-Refresh: context://statictestfiles/login.html --> +<body>Please login +</body> +</html> diff --git a/uitest/src/test/java/com/vaadin/tests/applicationservlet/VaadinRefreshServletTest.java b/uitest/src/test/java/com/vaadin/tests/applicationservlet/VaadinRefreshServletTest.java new file mode 100644 index 0000000000..06911b909f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/applicationservlet/VaadinRefreshServletTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2016 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.applicationservlet; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class VaadinRefreshServletTest extends SingleBrowserTest { + + @Test + public void redirectWorksWithContextPath() { + getDriver().get(getBaseURL() + "/vaadinrefresh/"); + waitUntil((WebDriver d) -> "Please login" + .equals(findElement(By.tagName("body")).getText())); + Assert.assertEquals(getBaseURL() + "/statictestfiles/login.html", + getDriver().getCurrentUrl()); + } +} |