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