예제 #1
0
  private void addWebApp(String path, String warPath) throws Exception {
    if (handlerCollection != null) {
      //			boolean extractWar = warPath.endsWith(".war");
      //			boolean parentLoaderPriority = true;

      // add it to the server
      //			boolean restartHandler = handlerCollection.isRunning();
      //			if (restartHandler) {
      //				handlerCollection.stop();
      //			}

      logger.log(Level.INFO, "Adding web app: " + warPath + " to path " + path);

      // create a webapp
      WebAppContext wah = new WebAppContext(handlerCollection, warPath, path);

      // configure it
      //			wah.setExtractWAR(extractWar);
      //			wah.setParentLoaderPriority(parentLoaderPriority);

      wah.setClassLoader(ObjectUtility.class.getClassLoader()); // set MeemServer classloader

      handlerCollection.addHandler(wah);
      wah.start();

      //			if (restartHandler) {
      //				handlerCollection.start();
      //			}
    }
  }
예제 #2
0
  private void addResourceHandler(String contextPath, String filePath) throws Exception {
    if (handlerCollection != null) {
      logger.log(Level.INFO, "Adding resource : " + contextPath + "=>" + filePath);

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

      logger.log(Level.INFO, "serving: " + resourceHandler.getBaseResource());

      ContextHandler contextHandler = new ContextHandler(contextPath);
      contextHandler.setHandler(resourceHandler);

      handlerCollection.addHandler(contextHandler);

      try {
        resourceHandler.start();
        contextHandler.start();
      } catch (Exception e) {
        logger.log(Level.INFO, "Could not start resource context", e);
      }
    }
  }
예제 #3
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);
  }