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


Java ContextHandler.setHandler方法代碼示例

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


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

示例1: startJetty

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
private void startJetty() throws Exception {
	QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
	Server server = new Server(jettyThreadPool);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
	http.setPort(jettyListenPort);
	
	server.addConnector(http);
	
	ContextHandler contextHandler = new ContextHandler();
	contextHandler.setHandler(botSocketHandler);
	server.setHandler(contextHandler);
	
   	server.start();
   	server.join();
}
 
開發者ID:BuaBook,項目名稱:buabook-api-interface,代碼行數:17,代碼來源:BuaBookApiInterface.java

示例2: getAllServices

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的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

示例3: mockConfigServerHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
private ContextHandler mockConfigServerHandler(final int statusCode, final ApolloConfig result,
                                               final boolean failedAtFirstTime) {
  ContextHandler context = new ContextHandler("/configs/*");
  context.setHandler(new AbstractHandler() {
    AtomicInteger counter = new AtomicInteger(0);

    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request,
                       HttpServletResponse response) throws IOException, ServletException {
      if (failedAtFirstTime && counter.incrementAndGet() == 1) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        baseRequest.setHandled(true);
        return;
      }

      response.setContentType("application/json;charset=UTF-8");
      response.setStatus(statusCode);
      response.getWriter().println(gson.toJson(result));
      baseRequest.setHandled(true);
    }
  });
  return context;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:24,代碼來源:ConfigIntegrationTest.java

示例4: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        
        // connector
//        server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class)
//                .setHttpCompliance(HttpCompliance.LEGACY);
//        server.setHandler(new HelloHandler("Hi JettyEmbeded "," light測試"));
        
        // Add a single handler on context "/hello"
        ContextHandler context = new ContextHandler();
        context.setContextPath( "/hello" );
        context.setHandler( new HelloHandler("Hi JettyEmbeded "," light測試") );
        // Can be accessed using http://localhost:8080/hello
        server.setHandler( context );

        server.start();
        server.join();
    }
 
開發者ID:lrtdc,項目名稱:book_ldrtc,代碼行數:19,代碼來源:OneHandler.java

示例5: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    final ApiServer api = new ApiServer(new InetSocketAddress(9998));

    PrometheusConfig cfg = createPrometheusConfig(args);
    final Optional<File> _cfg = cfg.getConfiguration();
    if (_cfg.isPresent())
        registry_ = new PipelineBuilder(_cfg.get()).build();
    else
        registry_ = new PipelineBuilder(Configuration.DEFAULT).build();

    api.start();
    Runtime.getRuntime().addShutdownHook(new Thread(api::close));

    Server server = new Server(cfg.getPort());
    ContextHandler context = new ContextHandler();
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setContextPath(cfg.getPath());
    context.setHandler(new DisplayMetrics(registry_));
    server.setHandler(context);
    server.start();
    server.join();
}
 
開發者ID:groupon,項目名稱:monsoon,代碼行數:23,代碼來源:PrometheusServer.java

示例6: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	URI baseUri = UriBuilder.fromUri("http://localhost").port(SERVER_PORT)
			.build();
	ResourceConfig config = new ResourceConfig(Calculator.class);
	Server server = JettyHttpContainerFactory.createServer(baseUri, config,
			false);

	ContextHandler contextHandler = new ContextHandler("/rest");
	contextHandler.setHandler(server.getHandler());
	
	ProtectionDomain protectionDomain = EmbeddedServer.class
			.getProtectionDomain();
	URL location = protectionDomain.getCodeSource().getLocation();
	
	ResourceHandler resourceHandler = new ResourceHandler();
	resourceHandler.setWelcomeFiles(new String[] { "index.html" });
	resourceHandler.setResourceBase(location.toExternalForm());
	System.out.println(location.toExternalForm());
	HandlerCollection handlerCollection = new HandlerCollection();
	handlerCollection.setHandlers(new Handler[] { resourceHandler,
			contextHandler, new DefaultHandler() });
	server.setHandler(handlerCollection);
	server.start();
	server.join();
}
 
開發者ID:AlanHohn,項目名稱:jaxrs,代碼行數:26,代碼來源:EmbeddedServer.java

示例7: setUpGuiHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
/**
     * do setup for the static resource handler
     * @return ContextHandler for the static resource handler
     */
    private static ContextHandler setUpGuiHandler() throws MalformedURLException
    {
    	ContextHandler context1 = new ContextHandler();
		context1.setContextPath("/");        
		ResourceHandler res = new ResourceHandler();
		res.setWelcomeFiles(new String[]{"index.html"});
		res.setBaseResource(Resource.newResource("./resources/"));
		context1.setHandler(res);
		logger.info("<---gui handler initialised--->");
		
//    WebAppContext webApp = new WebAppContext();
//    webApp.setContextPath("/");
//    webApp.setResourceBase("/home/orpheus/projects/BeSeen/BeSeenium/resources/");
//    webApp.setWar("/home/orpheus/projects/BeSeen/BeSeenium/resources/quercus-4.0.18.war");
//    webApp.setServer(server);
   // context1.setHandler(webApp);
		
		return context1;
    }
 
開發者ID:jpchanson,項目名稱:BeSeenium,代碼行數:24,代碼來源:HttpServer.java

示例8: systemRestart

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
private ContextHandler systemRestart() {
	AbstractHandler system = new AbstractHandler() {
		@Override
		public void handle(String target, Request baseRequest,
				HttpServletRequest request, HttpServletResponse response)
				throws IOException, ServletException {
			restartContexts();
			response.setContentType("text/html;charset=utf-8");
			response.setStatus(HttpServletResponse.SC_OK);
			baseRequest.setHandled(true);
			response.getWriter().println("<h1>Done</h1>");
		}
	};
	ContextHandler context = new ContextHandler();
	context.setContextPath("/vraptor/restart");
	context.setResourceBase(".");
	context.setClassLoader(Thread.currentThread().getContextClassLoader());
	context.setHandler(system);
	return context;
}
 
開發者ID:caelum,項目名稱:mamute,代碼行數:21,代碼來源:VRaptorServer.java

示例9: doPreStart

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
@Override
protected void doPreStart() {
    ContextHandler welcomeContext = new ContextHandler("/");
    welcomeContext.setContextPath("/");
    welcomeContext.setHandler(new WelcomeHandler(gpapProjectsFolder));

    ContextHandler projectsListContext = new ContextHandler("/stage_gplist_download");
    projectsListContext.setHandler(new ProjectListHandler(gpapProjectsFolder));

    ContextHandler projectDownloadContext = new ContextHandler("/stage_gpproject_download");
    projectDownloadContext.setHandler(new ProjectDownloadHandler(gpapProjectsFolder));

    ContextHandler projectUploadContext = new ContextHandler("/stage_gpproject_upload");
    projectUploadContext.setHandler(new ProjectUploadHandler(gpapProjectsFolder));

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(new Handler[]{welcomeContext, projectDownloadContext, projectUploadContext, projectsListContext});

    _server.setHandler(contexts);

}
 
開發者ID:TheHortonMachine,項目名稱:hortonmachine,代碼行數:22,代碼來源:GeopaparazziServer.java

示例10: listen

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
@Override
public HttpServer listen(int port) throws Exception {

    SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class));
    sessionHandler.setHandler(new MiddlewareHandler(app));

    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setResourceBase(".");
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setHandler(sessionHandler);

    Server server = new Server(port);

    server.setSessionIdManager(new HashSessionIdManager());
    server.setHandler(context);

    server.start();
    server.join();

    return this;
}
 
開發者ID:wmluke,項目名稱:pipes,代碼行數:23,代碼來源:JettyHttpServer.java

示例11: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Server server = new Server(8085);
    
    ContextHandler context = new ContextHandler("/");
    context.setContextPath("/");
    
    context.setHandler(new HandlerGUI("Root Hello"));
    
    ContextHandler contextFR = new ContextHandler("/fr");
    contextFR.setHandler(new HandlerGUI("Bonjoir"));
    
    ContextHandler contextIT = new ContextHandler("/it");
    contextIT.setHandler(new HandlerGUI("Bongiorno"));
    
    ContextHandler contextV = new ContextHandler("/");
    contextV.setVirtualHosts(new String[] { "127.0.0.2" });
    contextV.setHandler(new HandlerGUI("Virtual Hello"));
    
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    
    contexts.setHandlers(new Handler[] { context, contextFR, contextIT, contextV });
    
    server.setHandler(contexts);
    server.start();
    server.join();
}
 
開發者ID:jimjonesbr,項目名稱:lod4wfs,代碼行數:27,代碼來源:ManyContexts.java

示例12: configServer

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
@Override
protected void configServer(Server server, int port) {
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.setConnectors(new Connector[]{connector});

    ResourceHandler handler = new ResourceHandler();
    ContextHandler context = new ContextHandler();
    context.setContextPath("/dbus/");

    context.setResourceBase(SystemUtils.USER_DIR + File.separator + "html");
    context.setHandler(handler);

    server.setHandler(context);
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:16,代碼來源:ResourceHttpServer.java

示例13: run

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的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

示例14: mockMetaServerHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
protected ContextHandler mockMetaServerHandler(final boolean failedAtFirstTime) {
  final ServiceDTO someServiceDTO = new ServiceDTO();
  someServiceDTO.setAppName(someAppName);
  someServiceDTO.setInstanceId(someInstanceId);
  someServiceDTO.setHomepageUrl(configServiceURL);
  final AtomicInteger counter = new AtomicInteger(0);

  ContextHandler context = new ContextHandler("/services/config");
  context.setHandler(new AbstractHandler() {
    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request,
                       HttpServletResponse response) throws IOException, ServletException {
      if (failedAtFirstTime && counter.incrementAndGet() == 1) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        baseRequest.setHandled(true);
        return;
      }
      response.setContentType("application/json;charset=UTF-8");
      response.setStatus(HttpServletResponse.SC_OK);

      response.getWriter().println(gson.toJson(Lists.newArrayList(someServiceDTO)));

      baseRequest.setHandled(true);
    }
  });

  return context;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:29,代碼來源:BaseIntegrationTest.java

示例15: mockPollNotificationHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入方法依賴的package包/類
private ContextHandler mockPollNotificationHandler(final long pollResultTimeOutInMS,
                                                   final int statusCode,
                                                   final List<ApolloConfigNotification> result,
                                                   final boolean failedAtFirstTime) {
  ContextHandler context = new ContextHandler("/notifications/v2");
  context.setHandler(new AbstractHandler() {
    AtomicInteger counter = new AtomicInteger(0);

    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request,
                       HttpServletResponse response) throws IOException, ServletException {
      if (failedAtFirstTime && counter.incrementAndGet() == 1) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        baseRequest.setHandled(true);
        return;
      }

      try {
        TimeUnit.MILLISECONDS.sleep(pollResultTimeOutInMS);
      } catch (InterruptedException e) {
      }

      response.setContentType("application/json;charset=UTF-8");
      response.setStatus(statusCode);
      response.getWriter().println(gson.toJson(result));
      baseRequest.setHandled(true);
    }
  });

  return context;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:32,代碼來源:ConfigIntegrationTest.java


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