コード例 #1
0
  public void setConnector(int port) throws Exception {
    Connector listener = new SelectChannelConnector();

    listener.setHost("127.0.0.1");
    listener.setPort(port);
    server.addConnector(listener);
  }
コード例 #2
0
  @Test
  public void submitJob() throws Exception {
    org.h2.tools.Server h2 = org.h2.tools.Server.createTcpServer();
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8081);
    connector.setHost("127.0.0.1");
    server.addConnector(connector);

    WebAppContext wac = new WebAppContext();
    wac.setContextPath("/springbatchadmin");
    wac.setWar("./src/main/webapp");
    server.setHandler(wac);
    server.setStopAtShutdown(true);

    try {
      h2.start();
      server.start();
      assertTrue(restTemplate.getForObject(BASE_URL + "jobs.json", String.class).contains(JOB));
    } finally {
      server.stop();
      h2.stop();
    }
  }
コード例 #3
0
ファイル: HttpServer.java プロジェクト: rforge/biocep
  public static void main(String[] args) throws Exception {
    int port = 8080;
    try {
      if (System.getProperty("port") != null && !System.getProperty("port").equals("")) {
        port = Integer.decode(System.getProperty("port"));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    boolean rhttpEnabled = (args.length == 0);
    boolean rsoapEnabled =
        args.length == 0
            && System.getProperty("soapenabled") != null
            && System.getProperty("soapenabled").equals("true");

    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    connector.setHost(getHostIp());
    server.addConnector(connector);

    Connector connectorLocal = new SelectChannelConnector();
    connectorLocal.setPort(port);
    connectorLocal.setHost("127.0.0.1");
    server.addConnector(connectorLocal);

    if (rhttpEnabled) {
      cacheJar(
          new URL("http://biocep-distrib.r-forge.r-project.org/appletlibs/rvirtual.war"),
          ServerManager.INSTALL_DIR,
          LOG_PRGRESS_TO_SYSTEM_OUT,
          false);
      if (rsoapEnabled) {
        cacheJar(
            new URL("http://biocep-distrib.r-forge.r-project.org/appletlibs/rws.war"),
            ServerManager.INSTALL_DIR,
            LOG_PRGRESS_TO_SYSTEM_OUT,
            false);
        args =
            new String[] {
              ServerManager.INSTALL_DIR + "rvirtual.war", ServerManager.INSTALL_DIR + "rws.war"
            };
      } else {
        args = new String[] {ServerManager.INSTALL_DIR + "rvirtual.war"};
      }
    }

    for (int i = 0; i < args.length; ++i) {
      File warfile = new File(args[i]);
      if (!warfile.exists()) {
        System.out.println("couldn't find the war file :" + args[i]);
        System.exit(0);
      }

      String contextPath = "/" + warfile.getName();
      if (contextPath.endsWith(".war"))
        contextPath = contextPath.substring(0, contextPath.length() - ".war".length());

      WebAppContext wac = new WebAppContext();
      wac.setContextPath(contextPath);
      wac.setWar(warfile.getAbsolutePath());
      server.addHandler(wac);
    }

    server.setStopAtShutdown(true);
    server.start();

    while (!server.isStarted()) {
      try {
        Thread.sleep(20);
      } catch (Exception ex) {
      }
    }

    System.out.println("--> Http Server Started sucessfully on port " + port);

    if (rhttpEnabled) {
      System.out.println("R-HTTP URL: http://" + getHostIp() + ":" + port + "/rvirtual/cmd");
      System.out.println(
          "--> From the Virtual R Workbench, in Http mode, connect via the following URL:"
              + "http://"
              + getHostIp()
              + ":"
              + port
              + "/rvirtual/cmd");
    }

    if (rsoapEnabled) {
      System.out.println(
          "R-SOAP WSDL:" + "http://" + getHostIp() + ":" + port + "/rws/rGlobalEnvFunction?wsdl");
    }
  }
コード例 #4
0
ファイル: Refine.java プロジェクト: Arcadelia/OpenRefine
  public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");

    String memory = Configurations.get("refine.memory");
    if (memory != null) {
      logger.info(
          "refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }

    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);

    threadPool =
        new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);

    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));

    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
    connector.setStatsOn(false);
    this.addConnector(connector);

    File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));

    if (!isWebapp(webapp)) {
      webapp = new File("main/webapp");
      if (!isWebapp(webapp)) {
        webapp = new File("webapp");
        if (!isWebapp(webapp)) {
          logger.warn(
              "Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
          System.exit(-1);
        }
      }
    }

    final String contextPath = Configurations.get("refine.context_path", "/");

    logger.info(
        "Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
    WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
    context.setMaxFormContentSize(1048576);

    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);

    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload", false)) {
      scanForUpdates(webapp, context);
    }

    // start the server
    try {
      this.start();
    } catch (BindException e) {
      logger.error(
          "Failed to start server - is there another copy running already on this port/address?");
      throw e;
    }

    configure(context);
  }
コード例 #5
0
ファイル: OsgwtuiMain.java プロジェクト: fuse-gks/OneSwarm
  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);
  }
コード例 #6
0
ファイル: OsgwtuiMain.java プロジェクト: fuse-gks/OneSwarm
  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();
  }