Browse Source

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"
tags/8.1.0.alpha1
Artur 7 years ago
parent
commit
04a20bf666

+ 2
- 1
client/src/main/java/com/vaadin/client/communication/DefaultConnectionStateHandler.java View File

@@ -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,

+ 44
- 0
uitest/src/main/java/com/vaadin/tests/applicationservlet/VaadinRefreshServlet.java View File

@@ -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);
}
}

+ 9
- 0
uitest/src/main/webapp/WEB-INF/web.xml View File

@@ -63,6 +63,11 @@
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<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>
@@ -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>

+ 5
- 0
uitest/src/main/webapp/statictestfiles/login.html View File

@@ -0,0 +1,5 @@
<html>
<!-- Vaadin-Refresh: context://statictestfiles/login.html -->
<body>Please login
</body>
</html>

+ 35
- 0
uitest/src/test/java/com/vaadin/tests/applicationservlet/VaadinRefreshServletTest.java View File

@@ -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());
}
}

Loading…
Cancel
Save