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


Java ServletContextHandler.addServlet方法代碼示例

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


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

示例1: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) {
    int port = Configuration.INSTANCE.getInt("port", 8080);
    Server server = new Server(port);
    ServletContextHandler contextHandler
            = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/");
    ServletHolder sh = new ServletHolder(new VaadinServlet());
    contextHandler.addServlet(sh, "/*");
    contextHandler.setInitParameter("ui", CrawlerAdminUI.class.getCanonicalName());
    contextHandler.setInitParameter("productionMode", String.valueOf(PRODUCTION_MODE));
    server.setHandler(contextHandler);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        LOG.error("Failed to start application", e);
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:19,代碼來源:Application.java

示例2: reverseProxy

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private static void reverseProxy() throws Exception{
  Server server = new Server();

  SocketConnector connector = new SocketConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(8888);

  server.setConnectors(new Connector[]{connector});

  // Setup proxy handler to handle CONNECT methods
  ConnectHandler proxy = new ConnectHandler();
  server.setHandler(proxy);

  // Setup proxy servlet
  ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
  ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class);
  proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/");
  proxyServlet.setInitParameter("Prefix", "/");
  context.addServlet(proxyServlet, "/*");

  server.start();
}
 
開發者ID:tomkraljevic,項目名稱:jetty-embed-reverse-proxy-example,代碼行數:23,代碼來源:ProxyServer.java

示例3: initApi

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void initApi() {
    ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setContextPath("/api");
    servletHandler.getSessionHandler().setSessionManager(sessionManager);

    servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");

    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
    resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
    resourceConfig.packages(ServerResource.class.getPackage().getName());

    servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");

    handlers.addHandler(servletHandler);
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:17,代碼來源:WebServer.java

示例4: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的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.servlet.ServletContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876)
        .maxConcurrentCallsPerConnection(12).maxMessageSize(16777216)
        .addService(new MockApplicationRegisterService())
        .addService(new MockInstanceDiscoveryService())
        .addService(new MockJVMMetricsService())
        .addService(new MockServiceNameDiscoveryService())
        .addService(new MockTraceSegmentService()).build().start();

    Server jettyServer = new Server(new InetSocketAddress("0.0.0.0",
        Integer.valueOf(12800)));
    String contextPath = "/";
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    servletContextHandler.setContextPath(contextPath);
    servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH);
    servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH);
    servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH);
    jettyServer.setHandler(servletContextHandler);
    jettyServer.start();
}
 
開發者ID:SkywalkingTest,項目名稱:skywalking-mock-collector,代碼行數:21,代碼來源:Main.java

示例6: startComponent

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override
public void startComponent() {
  // Initialize servlet using RESTEasy and it's Guice bridge.
  // The listener must be injected by the same Guice module which also binds the REST endpoints.
  ServletContextHandler servletHandler = new ServletContextHandler();
  servletHandler.addEventListener(listener);
  servletHandler.addServlet(HttpServletDispatcher.class, "/*");

  // Starting up Jetty to serve the REST API.
  server = new Server(port);
  server.setHandler(servletHandler);

  try {
    server.start();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:mnemonic-no,項目名稱:act-platform,代碼行數:19,代碼來源:ApiServer.java

示例7: startServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void startServer() {
    server = new Server(PORT);
    port = PORT;

    ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletContext.setSecurityHandler(basicAuth("camel", "camelPass", "Private!"));
    servletContext.setContextPath("/");
    server.setHandler(servletContext);
    servletContext.addServlet(new ServletHolder(new MyHttpServlet()), "/*");
    try {
        server.start();
    } catch (Exception ex) {
        LOG.error("Could not start Server!", ex);
        fail(ex.getLocalizedMessage());
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:JettyTestServer.java

示例8: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
/**
 * 
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
	context.setContextPath("/");
	Logger mainLogger = Logger.getInstance();
	mainLogger.out(Level.INFORMATIVE, "Main", "Starting server");
	Server server = new Server(8080);
	mainLogger.out(Level.INFORMATIVE, "Main", "Set handler");
	server.setHandler(context);

	ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
	jerseyServlet.setInitOrder(0);

	jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
	jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "view");

	server.start();
	server.join();
	mainLogger.out(Level.INFORMATIVE, "Main", "Server started");
}
 
開發者ID:MartijnDevNull,項目名稱:storytime-backend,代碼行數:25,代碼來源:StartServer.java

示例9: initializeServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void initializeServer() {
	ResourceConfig resourceConfig = new ResourceConfig();
	resourceConfig.packages(GridServices.class.getPackage().getName());
	resourceConfig.register(JacksonJaxbJsonProvider.class);
	final Grid grid = this;
	
	resourceConfig.register(new AbstractBinder() {	
		@Override
		protected void configure() {
			bind(grid).to(Grid.class);
			bind(fileManager).to(FileProvider.class);
		}
	});
	ServletContainer servletContainer = new ServletContainer(resourceConfig);
			
	ServletHolder sh = new ServletHolder(servletContainer);
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	context.addServlet(sh, "/*");

	server = new Server(port);
	
	ContextHandlerCollection contexts = new ContextHandlerCollection();
       contexts.setHandlers(new Handler[] { context});
	server.setHandler(contexts);
}
 
開發者ID:denkbar,項目名稱:step,代碼行數:27,代碼來源:Grid.java

示例10: setUp

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    server = new Server(PORT);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    servletHolder = new ServletHolder(new CamelWebSocketServlet());
    servletHolder.setName("CamelWsServlet");
    servletHolder.setInitParameter("events", "true");
    context.addServlet(servletHolder, "/*");
    
    server.start();
    
    if (startCamelContext) {        
        super.setUp();
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:WebsocketCamelRouterWithInitParamTestSupport.java

示例11: main

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

示例12: SchedulerApiServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public SchedulerApiServer(SchedulerConfig schedulerConfig, Collection<Object> resources) {
    this.port = schedulerConfig.getApiServerPort();
    this.server = JettyHttpContainerFactory.createServer(
            UriBuilder.fromUri("http://0.0.0.0/").port(this.port).build(),
            new ResourceConfig(MultiPartFeature.class).registerInstances(new HashSet<>(resources)),
            false /* don't start yet. wait for start() call below. */);
    this.startTimeout = schedulerConfig.getApiServerInitTimeout();

    ServletContextHandler context = new ServletContextHandler();

    // Metrics + Prometheus
    Metrics.configureMetricsEndpoints(context, "/v1/metrics", "/v1/metrics/prometheus");

    // Resources
    ResourceConfig resourceConfig = new ResourceConfig(MultiPartFeature.class)
            .registerInstances(new HashSet<>(resources));
    ServletHolder resourceHolder = new ServletHolder(new ServletContainer(resourceConfig));
    context.addServlet(resourceHolder, "/*");

    final InstrumentedHandler handler = new InstrumentedHandler(Metrics.getRegistry());
    handler.setHandler(context);
    server.setHandler(handler);
}
 
開發者ID:mesosphere,項目名稱:dcos-commons,代碼行數:24,代碼來源:SchedulerApiServer.java

示例13: JSMServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public JSMServer(int port) {
    this.statsBroadcaster = new StatsBroadcaster();

    this.server = new Server(port);
    try {
        ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        handler.setContextPath("/");

        handler.addServlet(new ServletHolder(new StatsServlet()), "/stats");
        handler.addServlet(new ServletHolder(new SinkServlet()), "/sinks");

        this.server.setHandler(handler);
    } catch (Exception e) {
        logger.error("Exception in configuring servlet handlers", e);
    }
}
 
開發者ID:adohe,項目名稱:jsm,代碼行數:17,代碼來源:JSMServer.java

示例14: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void start() throws Exception {
    if (server != null) throw new IllegalStateException("started");
    Scheduler.Config config = Scheduler.$.config;

    QueuedThreadPool threadPool = new QueuedThreadPool(Runtime.getRuntime().availableProcessors() * 16);
    threadPool.setName("Jetty");

    server = new Server(threadPool);
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(config.apiPort());
    connector.setIdleTimeout(60 * 1000);

    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new Servlet()), "/");
    handler.setErrorHandler(new ErrorHandler());

    server.setHandler(handler);
    server.addConnector(connector);
    server.start();

    logger.info("started on port " + connector.getLocalPort());
}
 
開發者ID:elodina,項目名稱:hdfs-mesos,代碼行數:23,代碼來源:HttpServer.java

示例15: createServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/");
    handler.addServlet(new ServletHolder(new TestAsyncServlet()), "/");
    server.setHandler(handler);
    return server;
}
 
開發者ID:cschneider,項目名稱:reactive-components,代碼行數:13,代碼來源:TestServlet.java


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