当前位置: 首页>>代码示例>>Java>>正文


Java Server.setHandler方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.Server.setHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Server.setHandler方法的具体用法?Java Server.setHandler怎么用?Java Server.setHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.Server的用法示例。


在下文中一共展示了Server.setHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startWebSocket

import org.eclipse.jetty.server.Server; //导入方法依赖的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

示例2: start

import org.eclipse.jetty.server.Server; //导入方法依赖的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

示例3: onEnable

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
@Override
public void onEnable() {

    tpsPoller = new TpsPoller(this);
    Bukkit.getServer()
            .getScheduler()
            .scheduleSyncRepeatingTask(this, tpsPoller, 0, TpsPoller.POLL_INTERVAL);

    config.addDefault("port", 9225);
    config.options().copyDefaults(true);
    saveConfig();

    int port = config.getInt("port");
    server = new Server(port);
    server.setHandler(new MetricsController(this));

    try {
        server.start();

        getLogger().info("Started Prometheus metrics endpoint on port " + port);

    } catch (Exception e) {
        getLogger().severe("Could not start embedded Jetty server");
    }
}
 
开发者ID:sladkoff,项目名称:minecraft-prometheus-exporter,代码行数:26,代码来源:PrometheusExporter.java

示例4: main

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void main(String[] args) {  
try {  
    MergedLogSource src = new MergedLogSource(args);
    System.out.println(src);

    Server server = new Server(8182);
    server.setHandler(new LogServer(src));
    
    server.start();
    server.join();

} catch (Exception e) {  
    // Something is wrong.  
    e.printStackTrace();  
}  
   }
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:LogServer.java

示例5: createServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
            String path = req.getServletPath().substring(1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            resp.getWriter().append(path);
        }
        
    };
    handler.addServletWithMapping(new ServletHolder(servlet), "/");
    server.setHandler(handler);
    return server;
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:27,代码来源:TestRs.java

示例6: startJettyServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
/**
 * 启动jetty服务,加载server.war
 */
public static void startJettyServer(String path) throws  Exception{
    String configPath=path+ File.separator+"conf"+File.separator+"conf.properties";
    InputStream is = new FileInputStream(configPath);;
    Properties properties =new Properties();
    properties.load(is);
    is.close();
    int serverPort = Integer.parseInt(properties.getProperty("server.port"));
    Server server = new Server(serverPort);
    WebAppContext context = new WebAppContext();
    context.setContextPath("/");
    context.setWar(path+"/bin/service.war");
    server.setHandler(context);
    server.start();
    server.join();
}
 
开发者ID:elves-project,项目名称:openapi,代码行数:19,代码来源:ProgramEntrance.java

示例7: main

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	Runtime.getRuntime().addShutdownHook(new ShutdownHook());

	Initiator.init();

	Server server = new Server(PORT);
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath(CONTEXT_PATH);
	server.setHandler(context);
	server.setStopAtShutdown(true);

	context.addServlet(new ServletHolder(new GetAllLang()), "/get_all_lang");
	context.addServlet(new ServletHolder(new Compile()), "/compile");
	context.addServlet(new ServletHolder(new Run()), "/run");
	server.join();
	server.start();

	LOGGER.info("Avalon-Executive server is now running at http://127.0.0.1:" + PORT + CONTEXT_PATH);
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:20,代码来源:MainServer.java

示例8: initSocketServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public void initSocketServer() {
    server = new Server();
    ServerConnector connector = getServerConnector();
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addServlet(new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            try {
                resp.setContentType("text/html; charset=utf-8");
                resp.setStatus(HttpServletResponse.SC_OK);
                resp.getWriter().println("<div class=\"svg\" style=\"display: flex;align-items: center;justify-content: center;margin-top: 10%;\">\n"
                        + "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\" viewBox=\"-265 235 30 30\" >\n"
                        + "    <g fill=\"white\" stroke=\"#8EC343\" stroke-width=\"3\">\n"
                        + "      <circle  cx=\"-250.5\" cy=\"249.5\" r=\"10\"/>\n"
                        + "      <path d=\"M-257 250l4 3.6 8-8\"/>\n"
                        + "    </g>\n"
                        + "  </svg>\n"
                        + "</div>");
            } catch (Exception ex) {

            }
        }
    }), "/status/*");
    server.setHandler(context);

    // Add a websocket to a specific path spec
    ServletHolder holderEvents = new ServletHolder("ws-events", EventServlet.class);
    context.addServlet(holderEvents, "/");

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:34,代码来源:EventServer.java

示例9: main

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // assert that PrintWriter.print(String) uses UTF-8, much less verbose than Writer.write(byte[])
    if (defaultCharset() != UTF_8) throw new Exception("default charset must be UTF-8 (-Dfile.encoding=UTF-8)");

    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new HelloServlet()), "/*");

    Server server = new Server(8000);
    server.setHandler(handler);
    server.start();
    server.join();
}
 
开发者ID:ibaca,项目名称:autorest-streaming-example,代码行数:13,代码来源:Servlet.java

示例10: run

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public void run()  {
try {
    System.out.println("Listening on Reqs...");

  Server server = new Server(Config.PORT);

  // Handler for the voting API
  ContextHandler votingContext = new ContextHandler();
  votingContext.setContextPath("/vote");
  votingContext.setHandler(new VoteHandler());
  // Handler for the stats API
  ContextHandler statContext = new ContextHandler();
  statContext.setContextPath("/stats");
  statContext.setHandler(new StatsHandler());

  // summing all the Handlers up to one
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  contexts.setHandlers(new Handler[] { votingContext, statContext});
  server.setHandler(contexts);
  server.start();
  server.join();

  } catch (Exception e) {
    e.printStackTrace();
  }

}
 
开发者ID:Sigma-News,项目名称:Backend,代码行数:28,代码来源:RequestManager.java

示例11: startJetty

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private void startJetty(int port) throws Exception {
    Server server = new Server(port);
    WebApplicationContext webApplicationContext = createWebApplicationContext();
    ServletContextHandler handler = createHandlerWith(webApplicationContext);
    server.setHandler(handler);
    server.start();
    server.join();
}
 
开发者ID:BerniVarga,项目名称:brkr,代码行数:9,代码来源:EmbeddedJetty.java

示例12: WebUIApp

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public WebUIApp() throws IOException {
    server = new Server();

    AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    springContext.setClassLoader(this.getClass().getClassLoader());
    springContext.setConfigLocation("com.sst.burpextender.proxyhistory.webui.springmvc.config");

    DispatcherServlet dispatcherServlet = new DispatcherServlet(springContext);
    ServletHolder springServletHolder = new ServletHolder("mvc-dispatcher", dispatcherServlet);

    // ref: https://github.com/bkielczewski/example-spring-mvc-jetty
    // ref: https://github.com/fernandospr/spring-jetty-example
    ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath("/");
    contextHandler.addServlet(springServletHolder, "/*");
    contextHandler.addEventListener(new ContextLoaderListener(springContext));
    contextHandler.setResourceBase(new ClassPathResource("/webui", WebUIApp.class).getURI().toString());

    /* NOTE: Burp Extender において、 burp.BurpExtender については jar をロードしたclass loader内で実行される。
     * 一方、Tabなど独自のUIを追加した場合は、UIから呼ばれるコードはBurp自身のclass loader内で実行される。
     * つまり、Webアプリのstart/stopをBurp上に追加したUIからそのまま = Swingのスレッド内から呼び出す場合、
     * その一連の過程で使われるclass loaderはburp自身のものであり、
     * 「Burp Extender の jar 内のclassを見つけることができない。」
     * # 実際に見てみると、Thread.currentThread().getContextClassLoader() が sun.misc.Launcher$AppClassLoader となる.
     * 
     * その結果として、特に何の手当もしなかった場合、以下のような様々な、予期せぬclass loading関連の例外に遭遇する。
     * - Spring で setConfigLocation() で指定したパッケージがスキャンされない。
     * - Spring で @ComponentScan(basePackages = xxx) で指定したパッケージがスキャンされない。
     * ==> 結果として Spring MVC の初期化時に "No annotated classes found for specified class/package" のログが出力される。
     * - Spring + Thymeleaf 内部でのSpring EL式の生成で class not found 例外発生
     * 
     * そこで、Jetty側のレベルでclass loaderをカスタマイズする。
     * 本クラスのインスタンスをロードした class loader であれば、Burp Extender の jar をロードしているので、それを使うようにする。
     * これにより、Spring の annotation class のスキャンや、Spring MVC 内部で発生する様々な class loading が本来の形で動作するようになる。
     */
    contextHandler.setClassLoader(this.getClass().getClassLoader());

    CharacterEncodingFilter utf8Filter = new CharacterEncodingFilter();
    utf8Filter.setEncoding("UTF-8");
    utf8Filter.setForceEncoding(true);
    FilterHolder filterHolder = new FilterHolder(utf8Filter);
    EnumSet<DispatcherType> allDispatcher = EnumSet.of(
        DispatcherType.ASYNC,
        DispatcherType.ERROR,
        DispatcherType.FORWARD,
        DispatcherType.INCLUDE,
        DispatcherType.REQUEST);
    contextHandler.addFilter(filterHolder, "/*", allDispatcher);

    server.setHandler(contextHandler);
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:53,代码来源:WebUIApp.java

示例13: initJettyServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private void initJettyServer() {
    InetSocketAddress address = new InetSocketAddress(config.getHost(), config.getPort());
    jettyServer = new Server(address);

    handler = new ServletContextHandler();
    handler.setContextPath(config.getContextPath());
    handler.setClassLoader(new JbootServerClassloader(JettyServer.class.getClassLoader()));
    handler.setResourceBase(getRootClassPath());

    JbootShiroConfig shiroConfig = Jboot.config(JbootShiroConfig.class);
    if (shiroConfig.isConfigOK()) {
        handler.addEventListener(new EnvironmentLoaderListener());
        handler.addFilter(ShiroFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    }

    //JFinal
    FilterHolder jfinalFilter = handler.addFilter(JFinalFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    jfinalFilter.setInitParameter("configClass", Jboot.me().getJbootConfig().getJfinalConfig());

    JbootHystrixConfig hystrixConfig = Jboot.config(JbootHystrixConfig.class);
    if (StringUtils.isNotBlank(hystrixConfig.getUrl())) {
        handler.addServlet(HystrixMetricsStreamServlet.class, hystrixConfig.getUrl());
    }


    JbootMetricConfig metricsConfig = Jboot.config(JbootMetricConfig.class);
    if (StringUtils.isNotBlank(metricsConfig.getUrl())) {
        handler.addEventListener(new JbootMetricServletContextListener());
        handler.addEventListener(new JbootHealthCheckServletContextListener());
        handler.addServlet(AdminServlet.class, metricsConfig.getUrl());
    }

    io.jboot.server.Servlets jbootServlets = new io.jboot.server.Servlets();
    ContextListeners listeners = new ContextListeners();

    JbootAppListenerManager.me().onJbootDeploy(jbootServlets, listeners);


    for (Map.Entry<String, io.jboot.server.Servlets.ServletInfo> entry : jbootServlets.getServlets().entrySet()) {
        for (String path : entry.getValue().getUrlMapping()) {
            handler.addServlet(entry.getValue().getServletClass(), path);
        }
    }


    for (Class<? extends ServletContextListener> listenerClass : listeners.getListeners()) {
        handler.addEventListener(ClassKits.newInstance(listenerClass));
    }

    jettyServer.setHandler(handler);
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:52,代码来源:JettyServer.java

示例14: start

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public void start(boolean devMode, int port) throws Exception {

        Server server = new Server(new QueuedThreadPool(500));

        WebAppContext appContext = new WebAppContext();

        String resourceBasePath = "";
        //开发者模式
        if (devMode) {
            String artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
            resourceBasePath = artifact + "/src/main/webapp";
        }
        appContext.setDescriptor(resourceBasePath + "WEB-INF/web.xml");
        appContext.setResourceBase(resourceBasePath);
        appContext.setExtractWAR(true);

        //init param
        appContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        if (CommonUtils.isWindowOs()) {
            appContext.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        }

        //for jsp support
        appContext.addBean(new JettyJspParser(appContext));
        appContext.addServlet(JettyJspServlet.class, "*.jsp");

        appContext.setContextPath("/");
        appContext.getServletContext().setExtendedListenerTypes(true);
        appContext.setParentLoaderPriority(true);
        appContext.setThrowUnavailableOnStartupException(true);
        appContext.setConfigurationDiscovered(true);
        appContext.setClassLoader(Thread.currentThread().getContextClassLoader());

        ServerConnector connector = new ServerConnector(server);
        connector.setHost("0.0.0.0");
        connector.setPort(port);
        server.setConnectors(new Connector[]{connector});
        server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024 * 1024);
        server.setDumpAfterStart(false);
        server.setDumpBeforeStop(false);
        server.setStopAtShutdown(true);
        server.setHandler(appContext);
        logger.info("[opencron] JettyLauncher starting...");
        server.start();
    }
 
开发者ID:wolfboys,项目名称:opencron,代码行数:46,代码来源:JettyLauncher.java

示例15: main

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  // Check the command line arguments.
  if (args.length == 0) {
    printErrorMessageAndDie();
  }

  // Load all the properties.
  Properties props = new Properties();
  try (InputStream propStream = new FileInputStream(args[0])) {
    props.load(propStream);
  }

  int port = 9090;
  if (args.length > 1) {
    try {
      port = Integer.parseInt(args[1]);
    } catch (Exception e) {
      printErrorMessageAndDie();
    }
  }

  KafkaCruiseControl kafkaCruiseControl = new KafkaCruiseControl(new KafkaCruiseControlConfig(props));

  Server server = new Server(port);
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath("/");
  server.setHandler(context);
  // Placeholder for any static content
  DefaultServlet defaultServlet = new DefaultServlet();
  ServletHolder holderWebapp = new ServletHolder("default", defaultServlet);
  holderWebapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
  holderWebapp.setInitParameter("resourceBase", "./cruise-control-ui/dist/");
  context.addServlet(holderWebapp, "/*");
  // Kafka Cruise Control servlet data
  KafkaCruiseControlServlet kafkaCruiseControlServlet = new KafkaCruiseControlServlet(kafkaCruiseControl);
  ServletHolder servletHolder = new ServletHolder(kafkaCruiseControlServlet);
  context.addServlet(servletHolder, "/kafkacruisecontrol/*");
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      kafkaCruiseControl.shutdown();
    }
  });
  kafkaCruiseControl.startUp();
  server.start();
  System.out.println("Application directory: " + System.getProperty("user.dir"));
  System.out.println("Kafka Cruise Control started.");
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:49,代码来源:KafkaCruiseControlMain.java


注:本文中的org.eclipse.jetty.server.Server.setHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。