當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerList類代碼示例

本文整理匯總了Java中org.eclipse.jetty.server.handler.HandlerList的典型用法代碼示例。如果您正苦於以下問題:Java HandlerList類的具體用法?Java HandlerList怎麽用?Java HandlerList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HandlerList類屬於org.eclipse.jetty.server.handler包,在下文中一共展示了HandlerList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        //page reloaded by the timer
        context.addServlet(TimerServlet.class, "/timer");
        //part of a page reloaded by the timer
        context.addServlet(AjaxTimerServlet.class, "/server-time");
        //long-polling waits till a message
        context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
        //web chat
        context.addServlet(WebSocketChatServlet.class, "/chat");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:23,代碼來源:Main.java

示例2: startWebSocket

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
/**
 * start server
 * 
 * @param port
 * @param path
 * @param handlerClass
 */
public static void startWebSocket(int port, String path, String handlerClass) {
	try {
		Server server = new Server(port);
		HandlerList handlerList = new HandlerList();
		ServletContextHandler context = new ServletContextHandler(
				ServletContextHandler.SESSIONS);
		context.setContextPath("/");
		context.addServlet(new ServletHolder(new Jwservlet(handlerClass)),
				path);
		handlerList.addHandler(context);
		handlerList.addHandler(new DefaultHandler());
		server.setHandler(handlerList);
		server.start();
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
		LogUtil.LOG("start websocket server error:" + e.getMessage(),
				LogLev.ERROR, WebSocketServer.class);
		System.exit(1);
	}
}
 
開發者ID:Sunature,項目名稱:websocket,代碼行數:29,代碼來源:WebSocketServer.java

示例3: main

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:18,代碼來源:Main.java

示例4: start

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private void start() throws Exception {
    resourcesExample();

    ResourceHandler resourceHandler = new ResourceHandler();
    Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
    resourceHandler.setBaseResource(resource);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    context.addServlet(new ServletHolder(new TimerServlet()), "/timer");

    Server server = new Server(PORT);
    server.setHandler(new HandlerList(resourceHandler, context));

    server.start();
    server.join();
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:18,代碼來源:Main.java

示例5: main

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

        // Create a basic Jetty server object that will listen on port 8080
        Server server = new Server(8080);

        // Create the ResourceHandler. It is the object that will actually
        // handle the request for a given file. It is a Jetty Handler object
        // so it is suitable for chaining with other handlers as you will see
        // in other examples
        ResourceHandler resource_handler = new ResourceHandler();

        // Configure the ResourceHandler. Setting the resource base indicates
        // where the files should be served out of
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWelcomeFiles(new String[]{ "index.html" });
        resource_handler.setResourceBase("src/main/webapp/");

        // Add the ResourceHandler to the server
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
        server.setHandler(handlers);

        // Start server
        server.start();
        server.join();
    }
 
開發者ID:biblelamp,項目名稱:JavaEE,代碼行數:27,代碼來源:Main.java

示例6: prepare

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:22,代碼來源:DashBoardServer.java

示例7: getAllServices

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private HandlerList getAllServices() throws Exception{
    // File server & Context Handler for root, also setting the index.html
    // to be the "welcome file", i.e, autolink on root addresses.
    ContextHandler rootContext = new ContextHandler();
    rootContext.setContextPath("/*");
    rootContext.setHandler(getResourceHandlers());

    // Possible servlet lists, for all servlets or custom services you want to access later.
    // Warning, it might become a little bit nested if you add to many classes.
    ServletHandler questionHandler = new ServletHandler();
    questionHandler.addServletWithMapping(QuestionHandler.class, "/question");

    // Add the ResourceHandler to the server.
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {
            rootContext ,
            questionHandler,
    });

    return handlers;
}
 
開發者ID:Rebstorm,項目名稱:paul0-application-server,代碼行數:22,代碼來源:HomeServerConfig.java

示例8: startServer

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
private void startServer() {
    HttpAPIConfig cfg = getSettings();
    server = new Server(cfg.getPort());
    HandlerList lst = new HandlerList();
    LinkController ctr = new JDLinkController(LinkCollector.getInstance());
    if(cfg.getUsePassword() && cfg.getPassword() != null && !cfg.getPassword().equals("")) {
        lst.addHandler(new AuthorizationHandler(cfg.getPassword()));
    }
    lst.addHandler(new AjaxHandler(cfg.getAllowGet()));
    if(cfg.getAllowGet()) {
        lst.addHandler(new JDServerGETHandler(ctr));
    }
    lst.addHandler(new JDServerPOSTHandler(ctr));
    server.setHandler(lst);
    try {
        server.start();
    }
    catch(Exception e) {
        logger.log(new LogRecord(Level.SEVERE, e.getMessage()));
    }
}
 
開發者ID:nemec,項目名稱:JDHttpAPI,代碼行數:22,代碼來源:HttpAPIExtension.java

示例9: main

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) {
    int port = 8297;
    HandlerList lst = new HandlerList();

    String password = null;//"pass";
    Server server = new Server(port);
    JDServerPOSTHandler hnd;
    LinkController ctr = new SampleLinkController();
    if(password != null) {
        lst.addHandler(new AuthorizationHandler(password));
    }
    lst.addHandler(new AjaxHandler(true));
    lst.addHandler(new JDServerGETHandler(ctr));
    lst.addHandler(new JDServerPOSTHandler(ctr));
    server.setHandler(lst);
    try {
        server.start();
        server.join();
    }
    catch(Exception e) {
        System.out.println(e);
    }
}
 
開發者ID:nemec,項目名稱:JDHttpAPI,代碼行數:24,代碼來源:Program.java

示例10: getHandlerList

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
protected Handler getHandlerList(List<String> hostList) {
	// jettyServer.getWebappService().addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
	// 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;
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:21,代碼來源:WebappDaoImpl.java

示例11: start

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void start() {
    try {
        final ServerConnector httpConnector = new ServerConnector(server);

        httpConnector.setHost(root.host);
        httpConnector.setPort(root.port);
        httpConnector.setIdleTimeout(config.getInt("web.idle-timeout"));
        server.addConnector(httpConnector);

        final HandlerList handlers = new HandlerList();

        handlers.addHandler(inContext("/static", newResourcesHandler()));
        handlers.addHandler(inContext("/", new RootHandler(version, routes)));

        server.setHandler(handlers);
        server.start();

        log.info("Web Server started on http://" + root.host + ":" + root.port);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
}
 
開發者ID:alpian,項目名稱:tired,代碼行數:24,代碼來源:WebServer.java

示例12: setUpGlobal

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
@BeforeClass
@Override
public void setUpGlobal() throws Exception {
    port1 = findFreePort();
    port2 = findFreePort();

    server = newJettyHttpServer(port1);
    addHttpConnector(server, port2);

    HandlerList list = new HandlerList();
    list.addHandler(new AbstractHandler() {
        @Override
        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
            if (request.getLocalPort() == port2) {
                httpServletResponse.sendRedirect(getTargetUrl());
            }
        }
    });
    list.addHandler(getWebSocketHandler());
    server.setHandler(list);

    server.start();
    logger.info("Local HTTP server started successfully");
}
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:25,代碼來源:RedirectTest.java

示例13: start

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
/**
 * Start the file server (blocking).
 *
 * @throws Exception If server cannot start
 */
public final void start() throws Exception {
    LOGGER.info("Starting web interface at http://localhost:8000");

    Server server = new Server(8000);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("../website");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(
            new Handler[]{
                resource_handler,
                new DefaultHandler()});
    server.setHandler(handlers);

    server.start();
}
 
開發者ID:RUCD,項目名稱:apt-graph,代碼行數:25,代碼來源:FileServer.java

示例14: run

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:22,代碼來源:PerformanceServer.java

示例15: main

import org.eclipse.jetty.server.handler.HandlerList; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
 
開發者ID:SvichkarevAnatoly,項目名稱:stepic-java-web-service,代碼行數:22,代碼來源:Main.java


注:本文中的org.eclipse.jetty.server.handler.HandlerList類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。