Search in sources :

Example 36 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project Anserini by castorini.

the class TweetSearcher method main.

public static void main(String[] args) throws IOException, InterruptedException, ParseException {
    Options options = new Options();
    options.addOption(INDEX_OPTION, true, "index path");
    options.addOption(PORT_OPTION, true, "port");
    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        System.err.println("Error parsing command line: " + e.getMessage());
        System.exit(-1);
    }
    if (!cmdline.hasOption(INDEX_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(TweetSearcher.class.getName(), options);
        System.exit(-1);
    }
    int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : 8080;
    TweetSearcher nrtsearch = new TweetSearcher(cmdline.getOptionValue(INDEX_OPTION));
    TweetStreamIndexer its = new TweetStreamIndexer();
    Thread itsThread = new Thread(its);
    itsThread.start();
    LOG.info("Starting HTTP server on port " + port);
    HandlerList mainHandler = new HandlerList();
    Server server = new Server(port);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setWelcomeFiles(new String[] { "index.html" });
    resource_handler.setResourceBase("src/main/java/io/anserini/nrts/public");
    ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    handler.setContextPath("/");
    ServletHolder jerseyServlet = new ServletHolder(ServletContainer.class);
    jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", TweetSearcherAPI.class.getCanonicalName());
    handler.addServlet(jerseyServlet, "/*");
    mainHandler.addHandler(resource_handler);
    mainHandler.addHandler(handler);
    server.setHandler(mainHandler);
    try {
        server.start();
        LOG.info("Accepting connections on port " + port);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    server.join();
    itsThread.join();
    nrtsearch.close();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Options(org.apache.commons.cli.Options) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) GnuParser(org.apache.commons.cli.GnuParser) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 37 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project Universal-G-Code-Sender by winder.

the class PendantUI method start.

/**
 * Launches the local web server.
 * @return the url for the pendant interface
 */
public List<PendantURLBean> start() {
    server = new Server(port);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);
    resourceHandler.setWelcomeFiles(new String[] { "index.html" });
    resourceHandler.setBaseResource(getBaseResource());
    resourceHandler.setDirectoriesListed(true);
    ContextHandler sendGcodeContext = new ContextHandler();
    sendGcodeContext.setContextPath("/sendGcode");
    sendGcodeContext.setBaseResource(getBaseResource());
    sendGcodeContext.setClassLoader(Thread.currentThread().getContextClassLoader());
    sendGcodeContext.setHandler(new SendGcodeHandler());
    ContextHandler adjustManualLocationContext = new ContextHandler();
    adjustManualLocationContext.setContextPath("/adjustManualLocation");
    adjustManualLocationContext.setBaseResource(getBaseResource());
    adjustManualLocationContext.setClassLoader(Thread.currentThread().getContextClassLoader());
    adjustManualLocationContext.setHandler(new AdjustManualLocationHandler());
    ContextHandler getSystemStateContext = new ContextHandler();
    getSystemStateContext.setContextPath("/getSystemState");
    getSystemStateContext.setBaseResource(getBaseResource());
    getSystemStateContext.setClassLoader(Thread.currentThread().getContextClassLoader());
    getSystemStateContext.setHandler(new GetSystemStateHandler());
    ContextHandler configContext = new ContextHandler();
    configContext.setContextPath("/config");
    configContext.setBaseResource(getBaseResource());
    configContext.setClassLoader(Thread.currentThread().getContextClassLoader());
    configContext.setHandler(new ConfigHandler());
    configContext.setInitParameter("cacheControl", "max-age=0, public");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { configContext, sendGcodeContext, adjustManualLocationContext, getSystemStateContext, resourceHandler, new DefaultHandler() });
    server.setHandler(handlers);
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return getUrlList();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ServletException(javax.servlet.ServletException) SocketException(java.net.SocketException) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 38 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project incubator-gobblin by apache.

the class AdminWebServer method buildStaticResourceHandler.

private ResourceHandler buildStaticResourceHandler() {
    ResourceHandler staticResourceHandler = new ResourceHandler();
    staticResourceHandler.setDirectoriesListed(true);
    staticResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    String staticDir = getClass().getClassLoader().getResource("static").toExternalForm();
    staticResourceHandler.setResourceBase(staticDir);
    return staticResourceHandler;
}
Also used : ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 39 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project archiva by apache.

the class RemoteRepositoryConnectivityCheckTest method buildStaticServer.

protected Server buildStaticServer(Path path) {
    Server repoServer = new Server();
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[] { "index.html" });
    resourceHandler.setResourceBase(path.toAbsolutePath().toString());
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
    repoServer.setHandler(handlers);
    return repoServer;
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 40 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project selenium_java by sergueik.

the class RunScriptTest method beforeSuiteMethod.

@BeforeSuite
public void beforeSuiteMethod() throws Exception {
    ((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
    webServer = new Server(new QueuedThreadPool(5));
    ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
    connector.setPort(8080);
    webServer.addConnector(connector);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });
    resource_handler.setResourceBase("src/test/webapp");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    webServer.setHandler(handlers);
    webServer.start();
    driver = new FirefoxDriver();
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    hashesFinderScript = getScriptContent("hashesFinder.js");
    resultFinderScript = getScriptContent("resultFinder.js");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) StdErrLog(org.eclipse.jetty.util.log.StdErrLog) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)53 Server (org.eclipse.jetty.server.Server)31 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)20 HandlerList (org.eclipse.jetty.server.handler.HandlerList)20 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)16 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)15 ServerConnector (org.eclipse.jetty.server.ServerConnector)14 File (java.io.File)13 IOException (java.io.IOException)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 HashLoginService (org.eclipse.jetty.security.HashLoginService)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 Constraint (org.eclipse.jetty.util.security.Constraint)5 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4 Handler (org.eclipse.jetty.server.Handler)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 Path (java.nio.file.Path)3