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