Java 类org.eclipse.jetty.server.handler.ContextHandlerCollection 实例源码

项目:ccow    文件:WebSocketsTestSuite.java   
@BeforeClass
public static void beforeClass() throws Exception {
    ccowServer = new Server(serverPort);

    final CCOWContextListener c = new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule());

    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    ccowServer.addBean(mbContainer);

    final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(ccowServer, "/ws",
            ServletContextHandler.SESSIONS);
    webSocketServletContextHandler.addEventListener(c);
    WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler);

    final ServletContextHandler restServletContextHandler = new ServletContextHandler(ccowServer, "/");
    restServletContextHandler.addEventListener(c);
    restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

     final ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler});

    ccowServer.setHandler(contexts);
    ccowServer.start();

}
项目:incubator-pulsar    文件:ServerManager.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:incubator-pulsar    文件:ProxyServer.java   
public void start() throws PulsarServerException {
    log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebService.java   
public void start() throws PulsarServerException {
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();

        log.info("Web Service started at {}", pulsar.getWebServiceAddress());
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebServer.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:step    文件:Grid.java   
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);
}
项目:service-base    文件:JServer.java   
/**
 *
 * @param webapp
 * @return
 */
private static ContextHandlerCollection setupHttpsRedirect(WebAppContext webapp) {
    /*HANDLERS BUSINESS*/
    SecuredRedirectHandler securedRedirect = new SecuredRedirectHandler();

    // Establish all handlers that have a context
    ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
    webapp.setVirtualHosts(new String[]{"@secured"});   // handles requests that come through the sslConnector connector ...

    ContextHandler redirectHandler = new ContextHandler();
    redirectHandler.setContextPath("/");
    redirectHandler.setHandler(securedRedirect);
    redirectHandler.setVirtualHosts(new String[]{"@unsecured"});  // handls requests that come through the Connector (unsecured) ...
    contextHandlers.setHandlers(new Handler[]{redirectHandler, webapp});
    return contextHandlers;
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:FinanceAnalytics    文件:EmbeddedJettyComponentFactory.java   
private Server initJettyServer(ComponentRepository repo) {
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(getPort());
  connector.setConfidentialPort(getSecurePort());
  connector.setRequestHeaderSize(16384);

  Server jettyServer = new Server();
  jettyServer.setConnectors(new Connector[] {connector});

  ContextHandlerCollection contexts = new ContextHandlerCollection();
  HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contexts);
  addHandlers(repo, jettyServer, contexts);

  jettyServer.setHandler(handlers);
  jettyServer.setStopAtShutdown(true);
  jettyServer.setGracefulShutdown(2000);
  jettyServer.setSendDateHeader(true);
  jettyServer.setSendServerVersion(true);

  ComponentInfo info = new ComponentInfo(Server.class, "jetty");
  repo.registerComponent(info, jettyServer);
  repo.registerLifecycle(new ServerLifecycle(jettyServer));
  return jettyServer;
}
项目:FinanceAnalytics    文件:RemoteViewRunnerTest.java   
@BeforeClass
public void startServer() throws Exception {
  int port = 49152 + RandomUtils.nextInt(65535 - 49152);
  String serverUrl = "http://localhost:" + port + "/jax";
  SelectChannelConnector connector = new SelectChannelConnector();
  connector.setPort(port);
  _jettyServer = new Server();
  _jettyServer.setConnectors(new Connector[]{connector});
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contexts);
  WebAppContext ogWebAppContext = new WebAppContext("RemoteViewRunnerTest", "/");
  org.springframework.core.io.Resource resource = new ClassPathResource("web-engine");
  ogWebAppContext.setBaseResource(Resource.newResource(resource.getFile()));
  DataViewRunnerResource viewRunnerResource = new DataViewRunnerResource(new TestViewRunner());
  ComponentRepository repo = new ComponentRepository(ComponentLogger.Console.VERBOSE);
  repo.getRestComponents().publishResource(viewRunnerResource);
  repo.getRestComponents().publishHelper(new FudgeObjectBinaryConsumer());
  repo.getRestComponents().publishHelper(new FudgeObjectBinaryProducer());
  ogWebAppContext.setEventListeners(new EventListener[]{new ComponentRepositoryServletContextListener(repo)});
  handlers.addHandler(ogWebAppContext);
  _jettyServer.setHandler(handlers);
  _jettyServer.start();
  _remoteViewRunner = new RemoteViewRunner(URI.create(serverUrl));
}
项目:routing-bird    文件:RestfulServer.java   
public RestfulServer(boolean loopback,
    int port,
    String applicationName,
    boolean sslEnabled,
    String keyStoreAlias,
    String keyStorePassword,
    String keyStorePath,
    int maxNumberOfThreads,
    int maxQueuedRequests) {

    this.applicationName = applicationName;
    int maxThreads = maxNumberOfThreads + ACCEPTORS + SELECTORS;
    BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(MIN_THREADS, MIN_THREADS, maxQueuedRequests);
    this.queuedThreadPool = new QueuedThreadPool(maxThreads, MIN_THREADS, IDLE_TIMEOUT, queue);
    this.server = new Server(queuedThreadPool);
    this.handlers = new ContextHandlerCollection();

    server.addEventListener(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
    server.setHandler(handlers);

    if (sslEnabled) {
        server.addConnector(makeSslConnector(keyStoreAlias, keyStorePassword, keyStorePath, port));
    } else {
        server.addConnector(makeConnector(loopback, port));
    }
}
项目:hadoop-mini-clusters    文件:GatewayServer.java   
private static HandlerCollection createHandlers(
        final GatewayConfig config,
        final GatewayServices services,
        final ContextHandlerCollection contexts) {
    HandlerCollection handlers = new HandlerCollection();
    RequestLogHandler logHandler = new RequestLogHandler();
    logHandler.setRequestLog(new AccessHandler());

    TraceHandler traceHandler = new TraceHandler();
    traceHandler.setHandler(contexts);
    traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter"));

    CorrelationHandler correlationHandler = new CorrelationHandler();
    correlationHandler.setHandler(traceHandler);

    DefaultTopologyHandler defaultTopoHandler = new DefaultTopologyHandler(config, services, contexts);

    handlers.setHandlers(new Handler[]{correlationHandler, defaultTopoHandler, logHandler});
    return handlers;
}
项目:nano-framework    文件:JettyCustomServer.java   
private void applyHandle(final String contextPath, final String warPath) {
    final ContextHandlerCollection handler = new ContextHandlerCollection();
    final WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    webapp.setDefaultsDescriptor(WEB_DEFAULT);
    if (StringUtils.isEmpty(warPath)) {
        webapp.setResourceBase(DEFAULT_RESOURCE_BASE);
        webapp.setDescriptor(DEFAULT_WEB_XML_PATH);
    } else {
        webapp.setWar(warPath);
    }

    applySessionHandler(webapp);

    handler.addHandler(webapp);
    super.setHandler(handler);
}
项目:MoodCat.me-Core    文件:App.java   
private ContextHandlerCollection attachHandlers(final File staticsFolder, final Module... overrides) {
    final MoodcatHandler moodcatHandler = new MoodcatHandler(this, staticsFolder, overrides);

    final ResourceHandler resources = new ResourceHandler();
    resources.setBaseResource(Resource.newResource(staticsFolder));
    resources.setDirectoriesListed(false);
    resources.setCacheControl("max-age=3600");

    final HashSessionManager hashSessionManager = new HashSessionManager();
    hashSessionManager.setMaxInactiveInterval(SESSION_KEEP_ALIVE);

    final ContextHandlerCollection handlers = new ContextHandlerCollection();
    // CHECKSTYLE:OFF
    handlers.addContext("/", "/").setHandler(resources);
    handlers.addContext("/", "/").setHandler(moodcatHandler);
    // CHECKSTYLE:ON

    return handlers;
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:xdocreport.samples    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:bigdataviewer-server    文件:ManagerHandler.java   
public ManagerHandler(
        final String baseURL,
        final Server server,
        final ConnectorStatistics connectorStats,
        final StatisticsHandler statHandler,
        final ContextHandlerCollection handlers,
        final String thumbnailsDirectoryName )
                throws IOException, URISyntaxException
{
    this.baseURL = baseURL;
    this.server = server;
    this.handlers = handlers;
    this.statHandler = statHandler;
    this.connectorStats = connectorStats;
    this.thumbnailsDirectoryName = thumbnailsDirectoryName;
    setContextPath( "/" + Constants.MANAGER_CONTEXT_NAME );
}
项目:bigdataviewer-server    文件:BigDataServer.java   
private static ContextHandlerCollection createHandlers( final String baseURL, final Map< String, String > dataSet, final String thumbnailsDirectoryName ) throws SpimDataException, IOException
{
    final ContextHandlerCollection handlers = new ContextHandlerCollection();

    for ( final Entry< String, String > entry : dataSet.entrySet() )
    {
        final String name = entry.getKey();
        final String xmlpath = entry.getValue();
        final String context = "/" + name;
        final CellHandler ctx = new CellHandler( baseURL + context + "/", xmlpath, name, thumbnailsDirectoryName );
        ctx.setContextPath( context );
        handlers.addHandler( ctx );
    }

    return handlers;
}
项目:CryptMeme    文件:ConfigClientsHandler.java   
/**
 * Big hack for the moment, not using properties for directory and port
 * Go through all the Jetty servers, find the one serving port 7657,
 * requested and add the .war to that one
 */
private void startWebApp(String app) {
    ContextHandlerCollection s = WebAppStarter.getConsoleServer();
    if (s != null) {
                try {
                    File path = new File(_context.getBaseDir(), "webapps");
                    path = new File(path, app + ".war");
                    WebAppStarter.startWebApp(_context, s, app, path.getAbsolutePath());
                    addFormNoticeNoEscape(_("WebApp") + " <a href=\"/" + app + "/\">" + _(app) + "</a> " + _("started") + '.');
                } catch (Throwable e) {
                    addFormError(_("Failed to start") + ' ' + _(app) + " " + e + '.');
                    _log.error("Failed to start webapp " + app, e);
                }
                return;
    }
    addFormError(_("Failed to find server."));
}
项目:CryptMeme    文件:WebAppStarter.java   
/**
 *  stop it and remove the context
 *  @throws just about anything, caller would be wise to catch Throwable
 */
static void stopWebApp(String appName) {
    ContextHandler wac = getWebApp(appName);
    if (wac == null)
        return;
    try {
        // not graceful is default in Jetty 6?
        wac.stop();
    } catch (Exception ie) {}
    ContextHandlerCollection server = getConsoleServer();
    if (server == null)
        return;
    try {
        server.removeHandler(wac);
        server.mapContexts();
    } catch (IllegalStateException ise) {}
}
项目:CryptMeme    文件:WebAppStarter.java   
/** @since Jetty 6 */
static ContextHandler getWebApp(String appName) {
    ContextHandlerCollection server = getConsoleServer();
    if (server == null)
        return null;
    Handler handlers[] = server.getHandlers();
    if (handlers == null)
        return null;
    String path = '/'+ appName;
    for (int i = 0; i < handlers.length; i++) {
        if (!(handlers[i] instanceof ContextHandler))
            continue;
        ContextHandler ch = (ContextHandler) handlers[i];
        if (path.equals(ch.getContextPath()))
            return ch;
    }
    return null;
}
项目:hortonmachine    文件:GeopaparazziServer.java   
@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);

}
项目:codeine    文件:AbstractCodeineBootstrap.java   
protected void execute1(String component) throws Exception {
    System.out.println("Starting codeine "+component+" at version " + CodeineVersion.get());
    injector = Guice.createInjector(getModules(component));
    FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
    ServletContextHandler handler = createServletContextHandler();
    handler.setContextPath("/");
    FilterHolder crossHolder = new FilterHolder(new CrossOriginFilter());
    crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET, POST, PUT, DELETE");
    crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Origin,Content-Type,Accept,api_token");
    handler.addFilter(crossHolder, "/api/*", EnumSet.allOf(DispatcherType.class));
    handler.addFilter(crossHolder, "/api-with-token/*", EnumSet.allOf(DispatcherType.class));
    handler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));
    createAdditionalServlets(handler);
    ContextHandlerCollection contexts = createFileServerContexts();
    contexts.addHandler(handler);
    int port = startServer(contexts);
    log.info("jetty started on port " + port);
    injector.getInstance(CodeineRuntimeInfo.class).setPort(port);
    execute();
}
项目:openfire    文件:HttpBindManager.java   
private HttpBindManager() {
    // JSP 2.0 uses commons-logging, so also override that implementation.
    System.setProperty("org.apache.commons.logging.LogFactory", "org.jivesoftware.util.log.util.CommonsLogFactory");

    JiveGlobals.migrateProperty(HTTP_BIND_ENABLED);
    JiveGlobals.migrateProperty(HTTP_BIND_PORT);
    JiveGlobals.migrateProperty(HTTP_BIND_SECURE_PORT);
    JiveGlobals.migrateProperty(HTTP_BIND_THREADS);
    JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED);
    JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_FOR);
    JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_SERVER);
    JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_HOST);
    JiveGlobals.migrateProperty(HTTP_BIND_FORWARDED_HOST_NAME);
    JiveGlobals.migrateProperty(HTTP_BIND_CORS_ENABLED);
    JiveGlobals.migrateProperty(HTTP_BIND_CORS_ALLOW_ORIGIN);

    PropertyEventDispatcher.addListener(new HttpServerPropertyListener());
    this.httpSessionManager = new HttpSessionManager();
    contexts = new ContextHandlerCollection();

    // setup the cache for the allowed origins
    this.setupAllowedOriginsMap();
}
项目:buck-cutom    文件:WebServer.java   
public synchronized void start() throws WebServerException {
  if (server.isStarted()) {
    return;
  }

  // Package up all of the handlers into a ContextHandlerCollection to serve as the handler for
  // the server.
  List<? extends Handler> handlers = createHandlers();
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  contexts.setHandlers(handlers.toArray(new Handler[0]));
  server.setHandler(contexts);

  try {
    server.start();
  } catch (Exception e) {
    throw new WebServerException("Cannot start Websocket server.", e);
  }
}
项目:ironjacamar    文件:WebServer.java   
/**
 * Post deploy
 * @exception Throwable Thrown if an error occurs
 */
public void postDeploy() throws Throwable
{
   if (server != null &&
       !server.isRunning() &&
       handlers != null && handlers.getHandlers() != null && handlers.getHandlers().length > 0)
   {
      try
      {
         ContextHandlerCollection chc = new ContextHandlerCollection();
         chc.setHandlers(handlers.getHandlers());

         server.setHandler(chc);

         server.start();
      }
      catch (Exception e)
      {
         log.error("Could not start Jetty webserver", e);
      }
   }
}
项目:buck    文件:WebServer.java   
/**
 * Update state and start the server if necessary.
 *
 * @param artifactCache cache to serve.
 * @throws WebServerException
 */
public synchronized void updateAndStartIfNeeded(Optional<ArtifactCache> artifactCache)
    throws WebServerException {
  artifactCacheHandler.setArtifactCache(artifactCache);

  if (server.isStarted()) {
    return;
  }

  // Package up all of the handlers into a ContextHandlerCollection to serve as the handler for
  // the server.
  ImmutableList<? extends Handler> handlers = createHandlers();
  ContextHandlerCollection contexts = new ContextHandlerCollection();
  contexts.setHandlers(handlers.toArray(new Handler[0]));
  server.setHandler(contexts);

  try {
    server.start();
  } catch (Exception e) {
    throw new WebServerException("Cannot start Websocket server.", e);
  }
}
项目:apiman    文件:ManagerApiTestServer.java   
/**
 * Start/run the server.
 */
public void start() throws Exception {
    long startTime = System.currentTimeMillis();
    System.out.println("**** Starting Server (" + getClass().getSimpleName() + ")");
    preStart();

    ContextHandlerCollection handlers = new ContextHandlerCollection();
    addModulesToJetty(handlers);

    // Create the server.
    int serverPort = serverPort();
    server = new Server(serverPort);
    server.setHandler(handlers);
    server.start();
    long endTime = System.currentTimeMillis();
    System.out.println("******* Started in " + (endTime - startTime) + "ms");
}
项目:apiman    文件:GatewayMicroService.java   
/**
 * Start/run the server.
 * @throws Exception when any exception occurs
 */
public void start() throws Exception {
    long startTime = System.currentTimeMillis();

    ContextHandlerCollection handlers = new ContextHandlerCollection();
    addModulesToJetty(handlers);

    // Create the server.
    int serverPort = serverPort();
    System.out.println("**** Starting Gateway (" + getClass().getSimpleName() + ") on port: " + serverPort);
    server = new Server(serverPort);
    server.setHandler(handlers);
    server.start();
    long endTime = System.currentTimeMillis();
    System.out.println("******* Started in " + (endTime - startTime) + "ms");
}
项目:apiman    文件:GatewayServer.java   
/**
 * Configure the web application(s).
 * @param handlers
 * @throws Exception
 */
protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception {
    /* *************
     * Gateway
     * ************* */
    ServletContextHandler server = new ServletContextHandler(ServletContextHandler.SESSIONS);
    server.setContextPath("/");
    server.addEventListener(new WarGatewayBootstrapper());
    ServletHolder servlet = new ServletHolder(new WarGatewayServlet());
    server.addServlet(servlet, "/gateway/*");
    servlet = new ServletHolder(new HttpServletDispatcher());
    servlet.setInitParameter("javax.ws.rs.Application", TestGatewayApplication.class.getName());
    servlet.setInitParameter("resteasy.servlet.mapping.prefix", "/api");
    servlet.setInitOrder(1);
    server.addServlet(servlet, "/api/*");

    // Add the web contexts to jetty
    handlers.addHandler(server);
}
项目:apiman    文件:EchoServer.java   
/**
 * Start/run the server.
 */
public EchoServer start() throws Exception {
    long startTime = System.currentTimeMillis();
    System.out.println("**** Starting Server (" + getClass().getSimpleName() + ") on port " +  port); //$NON-NLS-1$ //$NON-NLS-2$
    preStart();

    ContextHandlerCollection handlers = new ContextHandlerCollection();
    addModulesToJetty(handlers);

    // Create the server.
    server = new Server(port);
    server.setHandler(handlers);
    server.start();
    long endTime = System.currentTimeMillis();
    System.out.println("******* Started in " + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
    return this;
}
项目:overlord-commons    文件:DevServer.java   
/**
 * Start/run the server.
 */
public void go() throws Exception {
    long startTime = System.currentTimeMillis();
    System.out.println("**** Starting Development Server (" + getClass().getSimpleName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
    preConfig();
    DevServerEnvironment environment = createDevEnvironment();
    addModules(environment);

    ContextHandlerCollection handlers = new ContextHandlerCollection();
    addModulesToJetty(environment, handlers);

    environment.createAppConfigs();

    // Create the server.
    int serverPort = serverPort();
    Server server = new Server(serverPort);
    server.setHandler(handlers);
    server.start();
    long endTime = System.currentTimeMillis();
    System.out.println("******* Started in " + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$

    postStart(environment);

    server.join();
}
项目:overlord-commons    文件:ErraiDevServer.java   
/**
 * @see org.overlord.commons.dev.server.DevServer#addModulesToJetty(org.overlord.commons.dev.server.DevServerEnvironment, org.eclipse.jetty.server.handler.ContextHandlerCollection)
 */
@Override
protected void addModulesToJetty(DevServerEnvironment environment, ContextHandlerCollection handlers)
        throws Exception {
    if (environment.isModuleInIDE(getErraiModuleId()) && !environment.isUsingClassHiderAgent()) {
        System.out.println("******************************************************************"); //$NON-NLS-1$
        System.out.println("WARNING: we detected that you are running from within an IDE"); //$NON-NLS-1$
        System.out.println("         but are not using the Errai class hiding agent.  As"); //$NON-NLS-1$
        System.out.println("         a result, you may see a number of Weld related errors "); //$NON-NLS-1$
        System.out.println("         during startup.  This is due to client-only classes"); //$NON-NLS-1$
        System.out.println("         being included on the server classpath.  To address"); //$NON-NLS-1$
        System.out.println("         this issue, please see:"); //$NON-NLS-1$
        System.out.println("         "); //$NON-NLS-1$
        System.out.println("         https://github.com/jfuerth/client-local-class-hider"); //$NON-NLS-1$
        System.out.println("         "); //$NON-NLS-1$
        System.out.println("         The above is a Java Agent that will hide the client-"); //$NON-NLS-1$
        System.out.println("         only classes from Weld, thereby suppressing the errors."); //$NON-NLS-1$
        System.out.println("******************************************************************"); //$NON-NLS-1$
        try {Thread.sleep(5000);} catch (InterruptedException e) {}
    }

}
项目:Run4WinTournamentManager    文件:Launcher.java   
@Override
public void run() {
    System.out.println("Creating ContextHandler");
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    System.out.println("Building Web Application Context");
    contexts.setHandlers(new Handler[] { new AppContextBuilder().buildWebAppContext()});
    System.out.println("Setting Handler");
    jettyServer.setHandler(contexts);
    try {
        System.out.println("Starting jetty");
        jettyServer.start();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }
}
项目:joynr    文件:ServersUtil.java   
public static Server startControlledBounceproxy(String bpId) throws Exception {

        final int port = ServletUtil.findFreePort();
        final String bpUrl = "http://localhost:" + port + "/bounceproxy/";

        System.setProperty("joynr.bounceproxy.id", bpId);
        System.setProperty("joynr.bounceproxy.controller.baseurl",
                           System.getProperty(MessagingPropertyKeys.BOUNCE_PROXY_URL));
        System.setProperty("joynr.bounceproxy.url4cc", bpUrl);
        System.setProperty("joynr.bounceproxy.url4bpc", bpUrl);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[]{ createControlledBounceproxyWebApp("", null) });
        Server server = startServer(contexts, port);

        System.clearProperty("joynr.bounceproxy.id");
        System.clearProperty("joynr.bounceproxy.controller.baseurl");
        System.clearProperty("joynr.bounceproxy.url4cc");
        System.clearProperty("joynr.bounceproxy.url4bpc");

        return server;
    }
项目:joynr    文件:ServersUtil.java   
private static Server startServer(ContextHandlerCollection contexts, int port) throws Exception {
    System.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, "http://localhost:" + port);
    setBounceProxyUrl();
    setDirectoriesUrl();
    logger.info("HOST PATH: {}", System.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH));

    final Server jettyServer = new Server();
    ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(new HttpConfiguration()));
    connector.setPort(port);
    connector.setAcceptQueueSize(1);
    jettyServer.setConnectors(new Connector[]{ connector });

    jettyServer.setHandler(contexts);
    jettyServer.start();

    logger.trace("Started jetty server:\n{}", jettyServer.dump());

    return jettyServer;
}
项目:fuchsia    文件:HttpServiceImpl.java   
public void registerServlet(String context, Servlet servlet, Dictionary dictionary, HttpContext httpContext) throws ServletException, NamespaceException {

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        server.setHandler(contexts);
        ServletContextHandler root = new ServletContextHandler(contexts, "/",
                ServletContextHandler.SESSIONS);
        ServletHolder servletHolder = new ServletHolder(servlet);
        root.addServlet(servletHolder, context);

        if (!server.getServer().getState().equals(server.STARTED)) {
            try {
                server.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }