Skip to content

Commit

Permalink
Java: Fixing JettyAppServer to pass AppServerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Feb 13, 2016
1 parent b3dbc01 commit f4a6958
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void startDriver() throws Throwable {

@Before
public void startServer() throws Throwable {
server = new WebbitAppServer();
server = new JettyAppServer();
server.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.testing.InProject;
import org.seleniumhq.jetty9.http.HttpVersion;
import org.seleniumhq.jetty9.http.MimeTypes;
import org.seleniumhq.jetty9.server.Connector;
import org.seleniumhq.jetty9.server.HttpConfiguration;
import org.seleniumhq.jetty9.server.HttpConnectionFactory;
Expand All @@ -35,10 +36,9 @@
import org.seleniumhq.jetty9.server.handler.AllowSymLinkAliasChecker;
import org.seleniumhq.jetty9.server.handler.ContextHandler.ApproveAliases;
import org.seleniumhq.jetty9.server.handler.ContextHandlerCollection;
import org.seleniumhq.jetty9.servlet.DefaultServlet;
import org.seleniumhq.jetty9.server.handler.ResourceHandler;
import org.seleniumhq.jetty9.servlet.ServletContextHandler;
import org.seleniumhq.jetty9.servlet.ServletHolder;
import org.seleniumhq.jetty9.servlets.MultiPartFilter;
import org.seleniumhq.jetty9.util.ssl.SslContextFactory;

import java.io.File;
Expand Down Expand Up @@ -104,8 +104,6 @@ public JettyAppServer(String hostName) {
addServlet(defaultContext, "/page/*", PageServlet.class);

addServlet(defaultContext, "/manifest/*", ManifestServlet.class);
addServlet(defaultContext, "*.appcache", ManifestServlet.class);
addServlet(jsContext, "*.appcache", ManifestServlet.class);
// Serves every file under DEFAULT_CONTEXT_PATH/utf8 as UTF-8 to the browser
addServlet(defaultContext, "/utf8/*", Utf8Servlet.class);

Expand Down Expand Up @@ -258,16 +256,21 @@ public void addFilter(

protected ServletContextHandler addResourceHandler(String contextPath, File resourceBase) {
ServletContextHandler context = new ServletContextHandler();
context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "true");
context.setInitParameter("org.eclipse.jetty.servlet.Default.aliases", "true");
context.setInitParameter("org.eclipse.jetty.servlet.Default.pathInfoOnly", "true");

ResourceHandler staticResource = new ResourceHandler();
staticResource.setDirectoriesListed(true);
staticResource.setWelcomeFiles(new String[] { "index.html" });
staticResource.setResourceBase(resourceBase.getAbsolutePath());
MimeTypes mimeTypes = new MimeTypes();
mimeTypes.addMimeMapping("appcache", "text/cache-manifest");
staticResource.setMimeTypes(mimeTypes);

context.setContextPath(contextPath);
context.setResourceBase(resourceBase.getAbsolutePath());
context.setHandler(staticResource);
context.setAliasChecks(ImmutableList.of(new ApproveAliases(), new AllowSymLinkAliasChecker()));
context.addServlet(new ServletHolder(new DefaultServlet()), "/*");

handlers.addHandler(context);

return context;
}

Expand Down

0 comments on commit f4a6958

Please sign in to comment.