Exemple #1
0
  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    Context root = new Context(server, "/");
    root.setResourceBase("./pom.xml");
    root.setHandler(new ResourceHandler());

    server.setStopAtShutdown(true);
    server.start();
  }
Exemple #2
0
  private synchronized void enableRemoteAccess() throws Exception {

    if (remoteAccessForward == null) {
      logger.fine("enabling remote access");
      Connector connector = new SelectChannelConnector();
      connector.setHost(LOCALHOST);
      connector.setPort(Constants.LOCAL_WEB_SERVER_PORT_AUTH);

      authenticatedServer = new Server();
      authenticatedServer.addConnector(connector);

      // sets the thread pool (just so it is deamon=true)
      QueuedThreadPool threadPool = new QueuedThreadPool();
      threadPool.setMinThreads(5);
      // threadPool.setMaxThreads(10);
      threadPool.setName("Auth Jetty thread pool");
      threadPool.setDaemon(true);
      authenticatedServer.setThreadPool(threadPool);

      Constraint constraint = new Constraint();
      constraint.setName(Constraint.__BASIC_AUTH);
      constraint.setRoles(new String[] {"remote_user"});
      constraint.setAuthenticate(true);

      ConstraintMapping cm = new ConstraintMapping();
      cm.setConstraint(constraint);
      cm.setPathSpec("/*");

      SecurityHandler securityHandler = new SecurityHandler();
      securityHandler.setUserRealm(
          new ExtraSaltHashUserRealm(
              RemoteAccessConfig.usesMD5Sha1Password(),
              "OneSwarm Remote",
              RemoteAccessConfig.REMOTE_ACCESS_FILE.getCanonicalPath()));
      securityHandler.setConstraintMappings(new ConstraintMapping[] {cm});

      ContextHandlerCollection contexts = new ContextHandlerCollection();

      authenticatedServer.setHandler(contexts);
      Context root = new Context(contexts, "/", Context.NO_SESSIONS);

      root.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.ALL);

      MultiHandler mh = new MultiHandler(coreInterface, true);

      if (System.getProperty("com.sun.management.jmxremote") != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();

        NCSARequestLog requestLog = new NCSARequestLog("/tmp/jetty-yyyy_mm_dd.remoterequest.log");
        requestLog.setRetainDays(1);
        requestLog.setAppend(false);
        requestLog.setExtended(true);
        requestLog.setLogTimeZone("GMT");
        requestLogHandler.setRequestLog(requestLog);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] {mh, requestLogHandler});
        root.setHandler(handlers);
      } else {
        root.setHandler(mh);
      }

      root.addHandler(securityHandler);

      // make sure that the class loader can find all classes in the
      // osgwtui
      // plugin dir...
      root.setClassLoader(pluginInterface.getPluginClassLoader());

      authenticatedServer.start();

      remoteAccessForward = new RemoteAccessForward();
      remoteAccessForward.start();
      logger.fine("remote access enabled");
    }
    coreInterface.setRemoteAccess(remoteAccessForward);
  }
Exemple #3
0
  public void initialize(PluginInterface pluginInterface) throws PluginException {
    this.coreInterface = new CoreInterface(pluginInterface);

    // make sure to unload in case of shutdown

    this.pluginInterface = pluginInterface;

    logger.fine("oneswarm ui plugin loaded");

    Connector connector = new SelectChannelConnector();
    connector.setHost(LOCALHOST);
    connector.setPort(Constants.LOCAL_WEB_SERVER_PORT);

    server = new Server();

    /** If we're running with jconsole support, start the MBean server */
    if (System.getProperty("com.sun.management.jmxremote") != null) {
      connector.setStatsOn(true);

      logger.info("Starting managemenat bean");
      // MBeanServer mBeanServer =
      // ManagementFactory.getPlatformMBeanServer();
      // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
      // server.getContainer().addEventListener(mBeanContainer);
      // mBeanContainer.start();
    }

    checkAutoStartRegistry();
    server.addConnector(connector);

    // sets the thread pool (just so it is deamon=true)
    BoundedThreadPool threadPool = new BoundedThreadPool();
    threadPool.setMinThreads(5);
    // threadPool.setMaxThreads(10);
    threadPool.setName("Jetty thread pool");
    threadPool.setDaemon(true);
    server.setThreadPool(threadPool);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    server.setHandler(contexts);
    Context root = new Context(contexts, "/", Context.NO_SESSIONS);

    MultiHandler mh = new MultiHandler(coreInterface, false);

    if (System.getProperty("com.sun.management.jmxremote") != null) {
      RequestLogHandler requestLogHandler = new RequestLogHandler();

      NCSARequestLog requestLog = new NCSARequestLog("/tmp/jetty-yyyy_mm_dd.request.log");
      requestLog.setRetainDays(1);
      requestLog.setAppend(false);
      requestLog.setExtended(true);
      requestLog.setLogTimeZone("GMT");
      requestLogHandler.setRequestLog(requestLog);

      HandlerCollection handlers = new HandlerCollection();
      handlers.setHandlers(new Handler[] {mh, requestLogHandler});
      root.setHandler(handlers);
    } else {
      root.setHandler(mh);
    }

    // make sure that the class loader can find all classes in the osgwtui
    // plugin dir...
    root.setClassLoader(pluginInterface.getPluginClassLoader());

    root.setVirtualHosts(new String[] {LOCALHOST});

    try {
      server.start();
      if (isRemoteAccessAllowed()) {
        enableRemoteAccess();
      }
      installRemoteAccessPropertyListener();
      // Thread.sleep(10000);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    CommunityServerManager.get();

    // check to see if we can parse a planetlab-style experiment config file
    try {
      Class expConfigManagerClass =
          Class.forName("edu.washington.cs.oneswarm.planetlab.ExperimentConfigManager");
      if (expConfigManagerClass != null) {

        Method getMethod = expConfigManagerClass.getMethod("get");
        Object configManager = getMethod.invoke(null, new Object[] {});
        if (configManager != null) {
          logger.info("Got experimental manager");
          Method setCore =
              expConfigManagerClass.getMethod("setCore", new Class[] {CoreInterface.class});
          setCore.invoke(configManager, coreInterface);
          logger.info("Set core");
          Method startHeartbeats = expConfigManagerClass.getMethod("startHeartbeats");
          startHeartbeats.invoke(configManager);
          logger.info("startHeartbeats");
        } else {
          logger.info("configManager is null -- classes found but experimental mode not enabled");
        }
      }

    } catch (ClassNotFoundException e) {
      logger.info("PlanetLab classes not found -- not running in experimental mode.");
    } catch (Exception e) {
      System.err.println(e);
      logger.info("PlanetLab classes failed to load -- not running in experimental mode.");
    }

    // make sure community server refreshes whether we load the web UI or
    // not.
    CommunityServerManager.get();

    /*
     * add the listener to the sha1 hasher manager
     */
    Sha1HashManager.getInstance()
        .addJobListener(
            new Sha1HashJobListener() {
              public Sha1CalcListener jobAdded(String name) {
                final int taskID =
                    BackendTaskManager.get()
                        .createTask(
                            "Hashing: " + name,
                            new CancellationListener() {
                              public void cancelled(int inID) {
                                Sha1HashManager.getInstance().stop();
                              }
                            });
                final BackendTask task = BackendTaskManager.get().getTask(taskID);
                task.setSummary("Calculating SHA1 and ED2K hashes of " + name);
                return new Sha1CalcListener() {
                  public void progress(double fraction) {
                    int percent = (int) Math.round(100 * fraction);
                    task.setProgress(percent + "%");
                  }

                  public void errorOccured(Throwable cause) {
                    BackendTaskManager.get().removeTask(taskID);
                  }

                  public void completed(Sha1Result result) {
                    BackendTaskManager.get().removeTask(taskID);
                  }
                };
              }
            });

    /** Start health checking */
    HealthChecker health = new HealthChecker();
    health.start();
  }