Java 类org.eclipse.jetty.servlet.ServletHolder 实例源码

项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        //page reloaded by the timer
        context.addServlet(TimerServlet.class, "/timer");
        //part of a page reloaded by the timer
        context.addServlet(AjaxTimerServlet.class, "/server-time");
        //long-polling waits till a message
        context.addServlet(new ServletHolder(new MessengerServlet()), "/messenger");
        //web chat
        context.addServlet(WebSocketChatServlet.class, "/chat");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:websocket    文件:WebSocketServer.java   
/**
 * 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);
    }
}
项目:crawling-framework    文件:Application.java   
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);
    }
}
项目:minijax    文件:Minijax.java   
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    // (0) Sort the resource methods by literal length
    application.sortResourceMethods();

    // (1) Add Minijax filter (must come before websocket!)
    context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));

    // (2) WebSocket endpoints
    if (OptionalClasses.WEB_SOCKET_UTILS != null) {
        OptionalClasses.WEB_SOCKET_UTILS
                .getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
                .invoke(null, context, application);
    }

    // (3) Dynamic JAX-RS content
    final MinijaxServlet servlet = new MinijaxServlet(application);
    final ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
    context.addServlet(servletHolder, "/*");
}
项目:pinto    文件:Demo.java   
public void run() throws Exception {
    org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
    Server server = new Server(port);
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setWelcomeFiles(new String[]{ "demo.html" });
       context.setResourceBase(httpPath);
       HashSessionIdManager idmanager = new HashSessionIdManager();
       server.setSessionIdManager(idmanager);
       HashSessionManager manager = new HashSessionManager();
       SessionHandler sessions = new SessionHandler(manager);
       sessions.setHandler(context);
       context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
       ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
       context.addServlet(holderPwd,"/*");
       server.setHandler(sessions);
       server.start();
       server.join();
}
项目:spring-reactive-sample    文件:Application.java   
@Bean
public Server jettyServer(ApplicationContext context) throws Exception {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    Servlet servlet = new JettyHttpHandlerAdapter(handler);

    Server server = new Server();
    ServletContextHandler contextHandler = new ServletContextHandler(server, "");
    contextHandler.addServlet(new ServletHolder(servlet), "/");
    contextHandler.start();

    ServerConnector connector = new ServerConnector(server);
    connector.setHost("localhost");
    connector.setPort(port);
    server.addConnector(connector);

    return server;
}
项目:crawling-framework    文件:Application.java   
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", AnalysisUI.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);
    }
}
项目:jetty-embed-reverse-proxy-example    文件:ProxyServer.java   
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();
}
项目:jmeter-prometheus-plugin    文件:PrometheusListener.java   
public void testStarted() {
    // update the configuration
    this.reconfigure();
    this.server = new Server(this.getSaveConfig().getPort());

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");

    try {
        server.start();
    } catch (Exception e) {
        log.error("Couldn't start http server", e);
    }

}
项目:traccar-service    文件:WebServer.java   
private void initClientProxy() {
    int port = Context.getConfig().getInteger("osmand.port");
    if (port != 0) {
        ServletContextHandler servletHandler = new ServletContextHandler() {
            @Override
            public void doScope(
                    String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                    throws IOException, ServletException {
                if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) {
                    super.doScope(target, baseRequest, request, response);
                }
            }
        };
        ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent());
        servletHolder.setInitParameter("proxyTo", "http://localhost:" + port);
        servletHandler.addServlet(servletHolder, "/");
        handlers.addHandler(servletHandler);
    }
}
项目:traccar-service    文件:WebServer.java   
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);
}
项目:cf-java-client-sap    文件:CloudFoundryClientTest.java   
/**
 * To test that the CF client is able to go through a proxy, we point the CC client to a broken url that can only be resolved by going
 * through an inJVM proxy which rewrites the URI. This method starts this inJvm proxy.
 *
 * @throws Exception
 */
private static void startInJvmProxy() throws Exception {
    inJvmProxyPort = getNextAvailablePort(8080);
    inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); // forcing use of loopback
    // that will be used both for Httpclient proxy and SocketDestHelper
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(1);
    inJvmProxyServer.setThreadPool(threadPool);

    HandlerCollection handlers = new HandlerCollection();
    inJvmProxyServer.setHandler(handlers);

    ServletHandler servletHandler = new ServletHandler();
    handlers.addHandler(servletHandler);
    nbInJvmProxyRcvReqs = new AtomicInteger();
    ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs);
    servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*");

    // Setup proxy handler to handle CONNECT methods
    ConnectHandler proxyHandler;
    proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs);
    handlers.addHandler(proxyHandler);

    inJvmProxyServer.start();
}
项目:otus_java_2017_06    文件:Main.java   
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();
}
项目:otus_java_2017_06    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:Avalon-Executive    文件:MainServer.java   
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);
}
项目:JInsight    文件:JettyFilterInstrumentationTest.java   
@BeforeClass
public static void setUp() throws Exception {
  System.out.println("Jetty [Configuring]");

  ServletContextHandler servletContext = new ServletContextHandler();
  servletContext.setContextPath("/");
  servletContext.addServlet(PingPongServlet.class, PingPongServlet.PATH);
  servletContext.addServlet(ExceptionServlet.class, ExceptionServlet.PATH);
  ServletHolder servletHolder = servletContext.addServlet(AsyncServlet.class, AsyncServlet.PATH);
  servletHolder.setAsyncSupported(true);

  jetty = new Server(0);
  jetty.setHandler(servletContext);
  System.out.println("Jetty [Starting]");
  jetty.start();
  System.out.println("Jetty [Started]");
  serverPort = ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
}
项目:mpd-2017-i41d    文件:WeatherWebApp.java   
public static void main(String[] args) throws Exception {
    try(HttpRequest http = new HttpRequest()) {
        WeatherService service = new WeatherServiceCache(new WeatherWebApi(http));
        WeatherController weatherCtr = new WeatherController(service);

        ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class);
        String resPath = getSystemResource("public").toString();
        holderHome.setInitParameter("resourceBase", resPath);
        holderHome.setInitParameter("dirAllowed", "true");
        holderHome.setInitParameter("pathInfoOnly", "true");

        int[] counter = {0};
        new HttpServer(3000)
                .addHandler("/search", weatherCtr::getSearch)
                .addHandler("/search/city", weatherCtr::searchCity)
                .addHandler("/weather/*", weatherCtr::last30daysWeather)
                .addServletHolder("/public/*", holderHome)
                .run();
    }
}
项目:thingweb-directory    文件:HTTPServer.java   
@Override
public void delete(String path)
{
  ServletMapping mapping = handler.getServletMapping(path);
  ServletMapping[] mappings = new ServletMapping [handler.getServletMappings().length - 1];
  ServletHolder[] servlets = new ServletHolder [handler.getServlets().length - 1];
  int mLength = 0, sLength = 0;

  for (ServletMapping m : handler.getServletMappings()) {
    if (!m.equals(mapping)) {
      mappings[mLength++] = m;
    }
  }

  for (ServletHolder s : handler.getServlets()) {
    if (!s.equals(handler.getServlet(mapping.getServletName()))) {
      servlets[sLength++] = s;
    }
  }

  handler.setServletMappings(mappings);
  handler.setServlets(servlets);
}
项目:Wechat-Group    文件:WxCpDemoServer.java   
public static void main(String[] args) throws Exception {
  initWeixin();

  Server server = new Server(8080);

  ServletHandler servletHandler = new ServletHandler();
  server.setHandler(servletHandler);

  ServletHolder endpointServletHolder = new ServletHolder(new WxCpEndpointServlet(wxCpConfigStorage, wxCpService, wxCpMessageRouter));
  servletHandler.addServletWithMapping(endpointServletHolder, "/*");

  ServletHolder oauthServletHolder = new ServletHolder(new WxCpOAuth2Servlet(wxCpService));
  servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");

  server.start();
  server.join();
}
项目:Wechat-Group    文件:WxMpDemoServer.java   
public static void main(String[] args) throws Exception {
  initWeixin();

  Server server = new Server(8080);

  ServletHandler servletHandler = new ServletHandler();
  server.setHandler(servletHandler);

  ServletHolder endpointServletHolder = new ServletHolder(
    new WxMpEndpointServlet(wxMpConfigStorage, wxMpService,
      wxMpMessageRouter));
  servletHandler.addServletWithMapping(endpointServletHolder, "/*");

  ServletHolder oauthServletHolder = new ServletHolder(
    new WxMpOAuth2Servlet(wxMpService));
  servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");

  server.start();
  server.join();
}
项目:https-github.com-apache-zookeeper    文件:JettyAdminServer.java   
public JettyAdminServer(String address, int port, int timeout, String commandUrl) {
    this.port = port;
    this.idleTimeout = timeout;
    this.commandUrl = commandUrl;
    this.address = address;

    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address);
    connector.setPort(port);
    connector.setIdleTimeout(idleTimeout);
    server.addConnector(connector);

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

    context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*");
}
项目:otus_java_2017_04    文件:Main.java   
public static void main(String[] args) throws Exception {

        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setResourceBase(PUBLIC_HTML);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

        context.addServlet(new ServletHolder(new LoginServlet("anonymous")), "/login");
        context.addServlet(AdminServlet.class, "/admin");
        context.addServlet(TimerServlet.class, "/timer");

        Server server = new Server(PORT);
        server.setHandler(new HandlerList(resourceHandler, context));

        server.start();
        server.join();
    }
项目:uavstack    文件:JettyPlusIT.java   
/**
 * onServletStart
 * 
 * @param args
 */
public void onServletStart(Object... args) {

    ServletHolder sh = (ServletHolder) args[0];
    Servlet servlet;
    try {
        servlet = sh.getServlet();
    }
    catch (ServletException e) {
        // ignore
        return;
    }

    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.AFTER_SERVET_INIT);
    context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());

    context.put(InterceptConstants.CONTEXTPATH, sh.getContextPath());

    iSupport.doIntercept(context);
}
项目:uavstack    文件:JettyPlusIT.java   
/**
 * onServletStop
 * 
 * @param args
 */
public void onServletStop(Object... args) {

    ServletHolder sh = (ServletHolder) args[0];
    Servlet servlet;
    try {
        servlet = sh.getServlet();
    }
    catch (ServletException e) {
        // ignore
        return;
    }

    InterceptSupport iSupport = InterceptSupport.instance();
    InterceptContext context = iSupport.createInterceptContext(Event.BEFORE_SERVLET_DESTROY);
    context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
    context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader());
    context.put(InterceptConstants.CONTEXTPATH, sh.getContextPath());
    iSupport.doIntercept(context);
}
项目:wisp    文件:ServerMain.java   
public static void main(String[] args) throws Exception {

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

        Server jettyServer = new Server(8067);
        jettyServer.setHandler(context);

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

        // Tells the Jersey Servlet which REST service/class to load.
        jerseyServlet.setInitParameter(
                "jersey.config.server.provider.classnames",
                EntryPointTestHandler.class.getCanonicalName());

        try {
            jettyServer.start();
            jettyServer.join();
        } finally {
            jettyServer.destroy();
        }
    }
项目:strictfp-back-end    文件:MainServer.java   
public static void main(@NotNull @NonNls String[] args) throws Exception {
    PropertyConfigurator.configure(System.getProperty("user.dir") + "/log4j.properties");
    logger.warn("StrictFP | Back-end");
    logger.info("StrictFP Back-end is now running...");
    Server server = new Server(Constant.SERVER.SERVER_PORT);
    ServletContextHandler context =
            new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/api/v0");
    server.setHandler(context);
    server.setStopAtShutdown(true);
    // 像下面这行一样
    context.addServlet(new ServletHolder(new GetQuiz()), "/misc/getquiz");
    context.addServlet(new ServletHolder(new TimeLine()), "/timeline");
    context.addServlet(new ServletHolder(new Counter()), "/misc/counter");
    context.addServlet(new ServletHolder(new User()), "/user");
    context.addServlet(new ServletHolder(new Heartbeat()), "/misc/heartbeat");
    context.addServlet(new ServletHolder(new SafeCheck()), "/misc/safecheck");
    context.addServlet(new ServletHolder(new CheckCert()), "/auth/check_cert");
    //
    server.start();
    server.join();
}
项目:cassandra-prometheus    文件:PrometheusExporter.java   
public PrometheusExporter(int port, String path) {

    QueuedThreadPool threadPool = new QueuedThreadPool(25);
    server = new Server(threadPool);

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);

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

    CollectorRegistry collectorRegistry = new CollectorRegistry();

    collectorRegistry.register(new PrometheusExports(CassandraMetricsRegistry.Metrics));

    MetricsServlet metricsServlet = new MetricsServlet(collectorRegistry);

    context.addServlet(new ServletHolder(metricsServlet), "/" + path);
    try {
        server.start();
    } catch (Exception e) {
        System.err.println("cannot start metrics http server " + e.getMessage());
    }
}
项目:reactive-components    文件:TestRs.java   
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;
}
项目:pinto    文件:Main.java   
public void run() throws Exception {

        org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
        Server server = new Server(port);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(httpPath);
        HashSessionIdManager idmanager = new HashSessionIdManager();
        server.setSessionIdManager(idmanager);
        HashSessionManager manager = new HashSessionManager();
        SessionHandler sessions = new SessionHandler(manager);
        sessions.setHandler(context);
        context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
        ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
        context.addServlet(holderPwd,"/*");
        server.setHandler(sessions);
        new Thread(new Console(getPinto(),port,build, () -> {
            try {
                server.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }), "console_thread").start();
        server.start();
        server.join();
    }
项目:endpoints-management-java    文件:IntegrationTestServer.java   
public void start() throws Exception {
  URL keystoreUrl = IntegrationTestServer.class.getClassLoader().getResource("keystore.jks");
  SslContextFactory sslContextFactory = new SslContextFactory();
  sslContextFactory.setKeyStorePath(keystoreUrl.getPath());
  sslContextFactory.setKeyStorePassword("keystore");

  SecureRequestCustomizer src = new SecureRequestCustomizer();
  HttpConfiguration httpsConfiguration = new HttpConfiguration();
  httpsConfiguration.setSecureScheme("https");
  httpsConfiguration.addCustomizer(src);

  ServerConnector https = new ServerConnector(server,
      new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
          new HttpConnectionFactory(httpsConfiguration));
  https.setPort(this.httpsPort);

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

  ResourceConfig resourceConfig = new ResourceConfig(this.resourceClass);
  ServletContainer servletContainer = new ServletContainer(resourceConfig);
  ServletHolder servletHolder = new ServletHolder(servletContainer);
  ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/*");
  servletContextHandler.addServlet(servletHolder, "/*");

  this.server.start();
}
项目:Camel    文件:JettyTestServer.java   
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());
    }
}
项目:incubator-zeppelin-druid    文件:ZeppelinServer.java   
private static WebAppContext setupWebAppContext(
    ZeppelinConfiguration conf) {

  WebAppContext webApp = new WebAppContext();
  webApp.setContextPath(conf.getServerContextPath());
  File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
  if (warPath.isDirectory()) {
    // Development mode, read from FS
    // webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
    webApp.setResourceBase(warPath.getPath());
    webApp.setParentLoaderPriority(true);
  } else {
    // use packaged WAR
    webApp.setWar(warPath.getAbsolutePath());
    File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
    warTempDirectory.mkdir();
    LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
    webApp.setTempDirectory(warTempDirectory);
  }
  // Explicit bind to root
  webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
  return webApp;
}
项目:steve-plugsurfing    文件:SteveAppContext.java   
private WebAppContext initWebApp() throws IOException {
    WebAppContext ctx = new WebAppContext();
    ctx.setContextPath(CONFIG.getContextPath());
    ctx.setResourceBase(new ClassPathResource("webapp").getURI().toString());

    // Disable directory listings if no index.html is found.
    ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    ServletHolder web = new ServletHolder("spring-dispatcher", new DispatcherServlet(springContext));
    ServletHolder cxf = new ServletHolder("cxf", new CXFServlet());

    ctx.addEventListener(new ContextLoaderListener(springContext));
    ctx.addServlet(web, CONFIG.getSpringMapping());
    ctx.addServlet(cxf, CONFIG.getCxfMapping());

    if (CONFIG.getProfile().isProd()) {
        addSecurityFilter(ctx);
    }

    initJSP(ctx);
    return ctx;
}
项目:scheduled    文件:AbstractRestServer.java   
@Override
public void start() {
    try {
        servletContext.setContextPath("/");
        server.setHandler(servletContext);

        // configure servlets
        servlets.keySet().forEach(path -> {
            Class<? extends HttpServlet> servletClazz = servlets.get(path);
            HttpServlet servlet = ReflectionUtils.newInstance(
                    servletClazz, HttpServlet.class, new Object[]{ componentManager });
            LOG.info("Servlet instance created: path=" + path + ", servlet=" + servlet);

            servletContext.addServlet(new ServletHolder(servlet), path);
        });

        server.start();
    } catch (Exception e) {
        Throwables.propagate(e);
    } finally {
        stop();
    }
}
项目:pvwatts-java    文件:PvWattsServer.java   
public static void main(String[] args) throws Exception {
  Injector injector = Guice.createInjector(getModules(args));

  Server server = new Server(injector.getInstance(Key.get(Integer.class, Port.class)));
  ServletContextHandler handler = new ServletContextHandler(server, "/pvwatts");

  handler.addEventListener(injector.getInstance(
    GuiceResteasyBootstrapServletContextListener.class));

  ServletHolder sh = new ServletHolder(HttpServletDispatcher.class);
  handler.addServlet(sh, "/*");
  server.setHandler(handler);

  server.start();
  server.join();
}
项目:stepic-java-web-service    文件:Main.java   
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();
}
项目:Camel    文件:AbstractBaseEsbPerformanceIntegrationTest.java   
@Before
@Override
public void setUp() throws Exception {
    server = new Server(9000);

    ServerConnector connector0 = new ServerConnector(server);
    connector0.setReuseAddress(true);
    server.setConnectors(new Connector[]{connector0});

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/service");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new EchoService()), "/EchoService");
    server.start();

    payload = readPayload();

    super.setUp();
}
项目:storytime-backend    文件:StartServer.java   
/**
 * 
 * @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");
}
项目:stepic-java-web-service    文件:Main.java   
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();
}
项目:histone-java2    文件:HttpConcreteTest.java   
@Test
public void concreteTest() throws Exception {

    HistoneTestCase.Case testCase = new HistoneTestCase.Case();
    testCase.setExpectedResult("true");
    testCase.setContext(getMap());
    testCase.setInput("{{var response = loadJSON('http://127.0.0.1:4442/', [headers: ['via': 123]])}}{{response -> isArray() && response.headers['via'] != '123'}}");
    try {
        ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        servletContextHandler.setContextPath("/");

        // CXF Servlet
        ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
        cxfServletHolder.setInitParameter("jaxrs.serviceClasses", TestServerResource.class.getName());
        servletContextHandler.addServlet(cxfServletHolder, "/*");

        server = new Server(4442);
        server.setHandler(servletContextHandler);

        server.start();
        Log.setLog(new StdErrLog());

        new CoreTestConsumer(parser, rtti, evaluator).accept(testCase);
    } finally {
        try {
            server.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}