Exemplo n.º 1
0
  private void addServlet(ServletSpec spec) {
    synchronized (servletSpecs) {
      servletSpecs.add(spec);
      try {
        // TODO make sure context has appropriate settings
        // servletContext.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(name)

        addServletToContext(servletContext, spec);
      } catch (Exception ex) {
        logger.log(Level.INFO, "Could not add servlet", ex);
        lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
        return;
      }
    }
  }
Exemplo n.º 2
0
  protected void startServer() {

    if (server == null) {
      // stop excessive logging
      Log.setLog(null);
      System.setProperty("DEBUG", "false");
      System.setProperty("VERBOSE", "false");

      server = new Server();
    }

    Connector connector = null;
    if (useSSL) {
      SslContextFactory contextFactory = new SslContextFactory();
      contextFactory.setKeyStore(sslKeystore);
      contextFactory.setKeyStorePassword(sslPassword);
      contextFactory.setKeyManagerPassword(sslKeyPassword);
      contextFactory.setNeedClientAuth(needClientAuth);
      connector = new SslSelectChannelConnector(contextFactory);

      // Setup JSSE keystore and set parameters here correctly
      //			connector = new SslSocketConnector();
      //			((SslSocketConnector)connector).setKeystore(sslKeystore);
      //			((SslSocketConnector)connector).setPassword(sslPassword);
      //			((SslSocketConnector)connector).setKeyPassword(sslKeyPassword);
      //			((SslSocketConnector)connector).setNeedClientAuth(needClientAuth);
      // uses an entry in the keystore called "jetty"
    } else {
      // connector = new SocketConnector();
      connector = new SelectChannelConnector();
    }
    connector.setPort(port);
    server.addConnector(connector);

    // set the Server's HandlerCollection. Other handlers will be added to the HandlerCollection
    handlerCollection = new ContextHandlerCollection();
    server.setHandler(handlerCollection);

    // create servlet context
    servletContext =
        new ServletContextHandler(
            handlerCollection, servletContextString, ServletContextHandler.SESSIONS);
    //		servletContext = new ServletContextHandler(handlerCollection, servletContextString,
    // ServletContextHandler.SESSIONS);

    // create web app context
    // webAppContext = new Context(handlerCollection, webAppContextString, Context.SESSIONS);

    try {

      // add ResourceHandlers
      addResourceHandlers();

      // add servlets to the servlet context
      // servletContext.addHandler(new SecurityHandler());
      addServletsToContext(servletContext);

      //
      addWebApps();

      // add default handler to the server
      handlerCollection.addHandler(new DefaultHandler());

      // start a Jetty
      server.start();
    } catch (BindException ex) {
      logger.log(
          Level.INFO, "Could not start web server on port " + port + ": " + ex.getMessage(), ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (InstantiationException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (IllegalAccessException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (ClassNotFoundException ex) {
      logger.log(Level.INFO, "Could not add servlet: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (MultiException ex) {
      logger.log(Level.INFO, "Problem while starting the web server: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    } catch (Exception ex) {
      logger.log(Level.INFO, "Problem while starting the web server: ", ex);
      lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), false);
      return;
    }

    lifeCycleControlConduit.vote(meemContext.getWedgeIdentifier(), true);
  }