use of org.eclipse.jetty.server.handler.ResourceHandler in project winery by eclipse.
the class WineryUsingHttpServer method createHttpServerForRepositoryUi.
/**
* Starts the repository UI on port {@value #REPOSITORY_UI_PORT}
*/
public static Server createHttpServerForRepositoryUi() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(REPOSITORY_UI_PORT);
server.setConnectors(new Connector[] { connector });
ResourceHandler rh0 = new ResourceHandler();
ContextHandler context0 = new ContextHandler();
context0.setContextPath("/");
// Path indexHtmlPath = MavenTestingUtils.getProjectFilePath("../org.eclipse.winery.repository.ui/dist/index.html").getParent();
Path indexHtmlPath = MavenTestingUtils.getBasePath().resolve("org.eclipse.winery.repository.ui").resolve("dist");
if (Files.exists(indexHtmlPath)) {
LOGGER.debug("Serving UI from " + indexHtmlPath.toString());
} else {
// not sure, why we sometimes have to use `getParent()`.
indexHtmlPath = MavenTestingUtils.getBasePath().getParent().resolve("org.eclipse.winery.repository.ui").resolve("dist");
if (Files.exists(indexHtmlPath)) {
LOGGER.debug("Serving UI from " + indexHtmlPath.toString());
} else {
LOGGER.error("Path does not exist " + indexHtmlPath);
}
}
context0.setBaseResource(Resource.newResource(indexHtmlPath.toFile()));
context0.setHandler(rh0);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { context0 });
server.setHandler(contexts);
return server;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project pf4j-update by pf4j.
the class WebServer method start.
public void start() throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
server.setStopAtShutdown(true);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(resourceBase);
resourceHandler.setDirectoriesListed(true);
// server.setHandler(contextHandler);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
server.setHandler(handlers);
server.start();
// server.join();
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project gitiles by GerritCodeReview.
the class DevServer method staticHandler.
private Handler staticHandler() throws IOException {
Path staticRoot = sourceRoot.resolve("resources/com/google/gitiles/static");
ResourceHandler rh = new ResourceHandler();
try {
rh.setBaseResource(new PathResource(staticRoot.toUri().toURL()));
} catch (URISyntaxException e) {
throw new IOException(e);
}
rh.setWelcomeFiles(new String[] {});
rh.setDirectoriesListed(false);
ContextHandler handler = new ContextHandler("/+static");
handler.setHandler(rh);
return handler;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project traccar by traccar.
the class WebServer method initWebApp.
private void initWebApp() {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(config.getString("web.path"));
if (config.getBoolean("web.debug")) {
resourceHandler.setWelcomeFiles(new String[] { "debug.html", "index.html" });
// avoid locking files on Windows
resourceHandler.setMinMemoryMappedContentLength(-1);
} else {
String cache = config.getString("web.cacheControl");
if (cache != null && !cache.isEmpty()) {
resourceHandler.setCacheControl(cache);
}
resourceHandler.setWelcomeFiles(new String[] { "release.html", "index.html" });
}
handlers.addHandler(resourceHandler);
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project Zong by Xenoage.
the class Webserver method enableWebServer.
private void enableWebServer() {
if (server.isRunning())
throw new IllegalStateException("Webserver can not be enabled while running");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[] { "index.html" });
resourceHandler.setResourceBase(webPath);
// cache 10 minutes
resourceHandler.setCacheControl("max-age=600,public");
ContextHandler contentHandler = new ContextHandler();
contentHandler.setContextPath("/");
contentHandler.setResourceBase(".");
contentHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
contentHandler.setHandler(resourceHandler);
handlers.add(contentHandler);
}
Aggregations