当前位置: 首页>>代码示例>>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;未经允许,请勿转载。