Search in sources :

Example 46 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList 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 47 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList 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 48 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project ddf by codice.

the class JettySessionManagementTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    // To get the AccessRequestLog to log in the target folder
    System.setProperty("ddf.data", "target");
    server = new Server();
    HandlerList handlers = new HandlerList();
    server.setHandler(handlers);
    // Configure server according to the jetty.xml file
    XmlConfiguration configuration = new XmlConfiguration(JettySessionManagementTest.class.getResourceAsStream("/jetty-session.xml"));
    configuration.configure(server);
    // Have server bind to first available port
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(null, "/context1", ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new TestServlet()), "/");
    context.getSessionHandler().setMaxInactiveInterval(MAX_INACTIVE_INTERVAL_SECONDS);
    handlers.addHandler(context);
    ServletContextHandler context2 = new ServletContextHandler(null, "/context2", ServletContextHandler.SESSIONS);
    context2.addServlet(new ServletHolder(new TestServlet()), "/");
    context2.getSessionHandler().setMaxInactiveInterval(MAX_INACTIVE_INTERVAL_SECONDS);
    handlers.addHandler(context2);
    HouseKeeper houseKeeper = new HouseKeeper();
    houseKeeper.setIntervalSec(SCAVENGE_INTERVAL_SECONDS);
    server.getSessionIdManager().setSessionHouseKeeper(houseKeeper);
    server.start();
    port = connector.getLocalPort();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HouseKeeper(org.eclipse.jetty.server.session.HouseKeeper) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Example 49 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project leopard by tanhaichao.

the class WebappDaoImpl method getHandlerList.

protected Handler getHandlerList(List<String> hostList) {
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
    if (hostList.contains("fshop.leopard.io")) {
        if (false) {
            return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
        }
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
        handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
        try {
            handlerList.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return handlerList;
    }
    return null;
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) HostResourceHandler(io.leopard.jetty.handler.HostResourceHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 50 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project scheduling by ow2-proactive.

the class JettyStarter method printDeployedApplications.

private List<String> printDeployedApplications(Server server, String schedulerHost, int restPort, String httpProtocol) {
    HandlerList handlerList = null;
    if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
        HandlerList topLevelHandlerList = (HandlerList) server.getHandler();
        for (Handler handler : topLevelHandlerList.getHandlers()) {
            if (handler instanceof RewriteHandler) {
                handlerList = (HandlerList) ((RewriteHandler) handler).getHandler();
            }
        }
    } else {
        handlerList = (HandlerList) server.getHandler();
    }
    ArrayList<String> applicationsUrls = new ArrayList<>();
    if (handlerList.getHandlers() != null) {
        for (Handler handler : handlerList.getHandlers()) {
            if (!(handler instanceof WebAppContext)) {
                continue;
            }
            WebAppContext webAppContext = (WebAppContext) handler;
            Throwable startException = webAppContext.getUnavailableException();
            if (startException == null) {
                if (!"/".equals(webAppContext.getContextPath())) {
                    String applicationUrl = getApplicationUrl(httpProtocol, schedulerHost, restPort, webAppContext);
                    applicationsUrls.add(applicationUrl);
                    logger.info("The web application " + webAppContext.getContextPath() + " created on " + applicationUrl);
                }
            } else {
                logger.warn("Failed to start context " + webAppContext.getContextPath(), startException);
            }
        }
        logger.info("*** Get started at " + httpProtocol + "://" + schedulerHost + ":" + restPort + " ***");
    }
    return applicationsUrls;
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) SecuredRedirectHandler(org.eclipse.jetty.server.handler.SecuredRedirectHandler) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler)

Aggregations

HandlerList (org.eclipse.jetty.server.handler.HandlerList)71 Server (org.eclipse.jetty.server.Server)44 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)32 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)26 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)21 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)16 IOException (java.io.IOException)13 Handler (org.eclipse.jetty.server.Handler)12 File (java.io.File)11 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)8 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)8 ArrayList (java.util.ArrayList)7 ServletException (javax.servlet.ServletException)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)6 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 Test (org.junit.Test)6 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)5