當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。