summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/launcher
diff options
context:
space:
mode:
authorMarc Englund <marc@vaadin.com>2013-05-08 09:31:09 +0300
committerMarc Englund <marc@vaadin.com>2013-05-08 09:31:09 +0300
commit1b188073c46c5c21bb8ddeb21674452c9bc414fd (patch)
treeffd26aebca49b4372cdbeb472e6a916e8249167f /uitest/src/com/vaadin/launcher
parent7d9f544d584edb90b1c9231987e356dfaf0b7b35 (diff)
downloadvaadin-framework-1b188073c46c5c21bb8ddeb21674452c9bc414fd.tar.gz
vaadin-framework-1b188073c46c5c21bb8ddeb21674452c9bc414fd.zip
Remove pre-loader element after pre-loading, fixes #10863
Change-Id: Ibd2009315aadb25e574c82f3b4b54c501d9b1395 Ticket: 10863
Diffstat (limited to 'uitest/src/com/vaadin/launcher')
-rw-r--r--uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
index 381091206a..ec060bc73a 100644
--- a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
+++ b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
@@ -22,9 +22,20 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
@@ -160,6 +171,25 @@ public class DevelopmentServerLauncher {
webappcontext.setWar(serverArgs.get("webroot"));
server.setHandler(webappcontext);
+ // --slowdown=/run/APP/PUBLISHED/*,/other/path/asd.jpg
+ // slows down specified paths
+ if (serverArgs.containsKey("slowdown")) {
+ String[] paths = serverArgs.get("slowdown").split(",");
+ for (String p : paths) {
+ System.out.println("Slowing down: " + p);
+ webappcontext.addFilter(SlowFilter.class, p, 1);
+ }
+ }
+ // --cache=/run/APP/PUBLISHED/*,/other/path/asd.jpg
+ // caches specified paths
+ if (serverArgs.containsKey("cache")) {
+ String[] paths = serverArgs.get("cache").split(",");
+ for (String p : paths) {
+ System.out.println("Enabling cache for: " + p);
+ webappcontext.addFilter(CacheFilter.class, p, 1);
+ }
+ }
+
try {
server.start();
@@ -240,4 +270,83 @@ public class DevelopmentServerLauncher {
return map;
}
+ /**
+ * Sleeps for 2-5 seconds when serving resources that matches given
+ * pathSpec. --slowdown=/run/APP/PUBLISHED/*,/other/path/asd.jpg
+ */
+ public static class SlowFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+
+ String path = ((HttpServletRequest) request).getPathInfo();
+ long delay = Math.round(Math.random() * 3000) + 2000;
+ System.out.println("Delaying " + path + " for " + delay);
+
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ System.out.println("Delay interrupted for " + path);
+ } finally {
+ System.out.println("Resuming " + path);
+ }
+
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+ }
+
+ }
+
+ /**
+ * Adds "Expires" and "Cache-control" headers when serving resources that
+ * match given pathSpec, in order to cache resource for CACHE_MINUTES.
+ * --cache=/run/APP/PUBLISHED/*,/other/path/asd.jpg
+ */
+ public static class CacheFilter implements Filter {
+
+ private static final int CACHE_MINUTES = 1;
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+
+ String path = ((HttpServletRequest) request).getPathInfo();
+ System.out.println("Caching " + path + " for " + CACHE_MINUTES
+ + " minutes");
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.MINUTE, CACHE_MINUTES);
+
+ String expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z")
+ .format(calendar.getTime());
+
+ ((HttpServletResponse) response).setHeader("Expires", expires);
+ ((HttpServletResponse) response).setHeader("Cache-Control",
+ "max-age=" + (CACHE_MINUTES * 60));
+
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+ }
+
+ }
+
}