From 13d5b3e98954c2ade382305f8d044b2b49fdbd0b Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 8 Oct 2012 08:11:51 +0300 Subject: Bootstrap UI using relative URLs with servlets (#6771) * Configure widgetset using URLs relative to the requested page * Provide a Util method for getting an absolute URL from a relative URL * Test by using an embedded Jetty acting as a transparent proxy * Make /embed1 use the Buttons test to enable testing UIDL requests Change-Id: I4ef9b40e3954ae16b682d743a339f4360db40d4d --- .../com/vaadin/tests/integration/ProxyTest.html | 111 +++++++++++++++ .../com/vaadin/tests/integration/ProxyTest.java | 155 +++++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/integration/ProxyTest.html create mode 100644 uitest/src/com/vaadin/tests/integration/ProxyTest.java (limited to 'uitest/src/com/vaadin/tests') diff --git a/uitest/src/com/vaadin/tests/integration/ProxyTest.html b/uitest/src/com/vaadin/tests/integration/ProxyTest.html new file mode 100644 index 0000000000..f52f35ed55 --- /dev/null +++ b/uitest/src/com/vaadin/tests/integration/ProxyTest.html @@ -0,0 +1,111 @@ + + + + + + +AddAndRemoveTabs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AddAndRemoveTabs
open/run/com.vaadin.tests.integration.ProxyTest?restartApplication
clickvaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLink[0]/domChild[0]/domChild[0]
pause2000
assertTextvaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]A generic test for Buttons in different configurations
mouseClickvaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]5,5
assertCSSClassvaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]v-disabled
open/run/com.vaadin.tests.integration.ProxyTest
clickvaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VLink[0]/domChild[0]/domChild[0]
pause2000
mouseClickvaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]7,5
assertNotCSSClassvaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]v-disabled
open/run/com.vaadin.tests.integration.ProxyTest
clickvaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VLink[0]/domChild[0]/domChild[0]
pause2000
mouseClickvaadin=runcomvaadintestscomponentsbuttonButtons::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]35,7
assertCSSClassvaadin=runcomvaadintestscomponentsbuttonButtons::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]v-disabled
open/run/com.vaadin.tests.integration.ProxyTest
clickvaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]
+ + diff --git a/uitest/src/com/vaadin/tests/integration/ProxyTest.java b/uitest/src/com/vaadin/tests/integration/ProxyTest.java new file mode 100644 index 0000000000..97a4efe90e --- /dev/null +++ b/uitest/src/com/vaadin/tests/integration/ProxyTest.java @@ -0,0 +1,155 @@ +/* + * Copyright 2011 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.integration; + +import javax.servlet.http.HttpServletRequest; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.servlets.ProxyServlet; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.server.ExternalResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServletService; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Link; +import com.vaadin.ui.VerticalLayout; + +@PreserveOnRefresh +public class ProxyTest extends AbstractTestUI { + + private Server server; + + private final Button startButton = new Button("Start proxy", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + startProxy(); + stopButton.setEnabled(true); + } + }); + private final Button stopButton = new Button("Stop proxy", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + stopProxy(); + startButton.setEnabled(true); + } + }); + private VerticalLayout linkHolder = new VerticalLayout(); + + @Override + protected void setup(VaadinRequest request) { + stopButton.setDisableOnClick(true); + stopButton.setEnabled(false); + startButton.setDisableOnClick(true); + + addCleanupListener(new CleanupListener() { + @Override + public void cleanup(CleanupEvent event) { + if (server != null && server.isRunning()) { + try { + server.stop(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + }); + + addComponent(startButton); + addComponent(stopButton); + addComponent(linkHolder); + } + + private void startProxy() { + HttpServletRequest request = VaadinServletService + .getCurrentServletRequest(); + + // Set up a server + server = new Server(); + SelectChannelConnector connector = new SelectChannelConnector(); + // Uses random available port by default, uncomment this to make local + // testing easier (you can just reload old tab after restarting proxy) + // connector.setPort(8889); + server.setConnectors(new Connector[] { connector }); + + // Create root context and add the ProxyServlet.Transparent to it + ServletContextHandler contextHandler = new ServletContextHandler(); + server.setHandler(contextHandler); + contextHandler.setContextPath("/"); + ServletHolder servletHolder = contextHandler.addServlet( + ProxyServlet.Transparent.class, "/*"); + + // Configure servlet to forward to the root of the original server + servletHolder.setInitParameter( + "ProxyTo", + "http://" + request.getLocalAddr() + ":" + + request.getLocalPort() + "/"); + // Configure servlet to strip beginning of paths + servletHolder.setInitParameter("Prefix", "/proxypath/"); + + // Start the server + try { + server.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + // Add links to some proxied urls to tests + String linkBase = "http://" + request.getLocalName() + ":" + + connector.getLocalPort() + "/proxypath/"; + + linkHolder.removeAllComponents(); + linkHolder.addComponent(new Link("Open embed1 in proxy", + new ExternalResource(linkBase + "embed1"))); + linkHolder.addComponent(new Link("Open embed1/ in proxy", + new ExternalResource(linkBase + "embed1/"))); + linkHolder.addComponent(new Link("Open Buttons in proxy", + new ExternalResource(linkBase + + "run/com.vaadin.tests.components.button.Buttons"))); + + } + + private void stopProxy() { + linkHolder.removeAllComponents(); + try { + server.stop(); + } catch (Exception e) { + throw new RuntimeException(e); + } + server.destroy(); + server = null; + } + + @Override + protected String getTestDescription() { + return "Test UI for starting an embedded Jetty on a different port that proxies requests back to the original server using a different path."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(6771); + } + +} -- cgit v1.2.3