Пример #1
0
  public static void main(String[] args) throws Exception {
    Server server = new Server();

    SelectChannelConnector connector0 = new SelectChannelConnector();
    connector0.setPort(8080);
    connector0.setMaxIdleTime(30000);
    connector0.setRequestHeaderSize(8192);

    SelectChannelConnector connector1 = new SelectChannelConnector();
    connector1.setHost("127.0.0.1");
    connector1.setPort(8888);
    connector1.setThreadPool(new QueuedThreadPool(20));
    connector1.setName("admin");

    SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();
    String jetty_home =
        System.getProperty("jetty.home", "../jetty-distribution/target/distribution");
    System.setProperty("jetty.home", jetty_home);
    ssl_connector.setPort(8443);
    SslContextFactory cf = ssl_connector.getSslContextFactory();
    cf.setKeyStorePath(jetty_home + "/etc/keystore");
    cf.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    cf.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");

    server.setConnectors(new Connector[] {connector0, connector1, ssl_connector});

    server.setHandler(new HelloHandler());

    server.start();
    server.join();
  }
Пример #2
0
  public void start(Injector injector) throws Exception {
    ResourceHandler resHandler = new ResourceHandler();
    resHandler.setDirectoriesListed(false);
    resHandler.setWelcomeFiles(new String[] {"index.html"});
    resHandler.setResourceBase(args.get("jetty.resourcebase", "./src/main/webapp"));

    server = new Server();
    // getSessionHandler and getSecurityHandler should always return null
    ServletContextHandler servHandler =
        new ServletContextHandler(
            ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    servHandler.setContextPath("/");

    servHandler.addServlet(new ServletHolder(new InvalidRequestServlet()), "/*");

    FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
    servHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));

    SelectChannelConnector connector0 = new SelectChannelConnector();
    int httpPort = args.getInt("jetty.port", 8989);
    String host = args.get("jetty.host", "");
    connector0.setPort(httpPort);
    if (!host.isEmpty()) connector0.setHost(host);

    server.addConnector(connector0);

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resHandler, servHandler});
    server.setHandler(handlers);
    server.start();
    logger.info("Started server at HTTP " + host + ":" + httpPort);
  }
  /**
   * set up the ssl connectors with strong ciphers
   *
   * @throws Exception
   */
  protected void initConnectors() throws Exception {
    if (!_disableHTTP) {
      if (_unsecuredConnector == null) {
        _unsecuredConnector = new SelectChannelConnector();
      }
      if (_unsecurePort != null) {
        _unsecuredConnector.setPort(Integer.parseInt(_unsecurePort));
      } else {
        _unsecuredConnector.setPort(_serviceInfo.getEndpoint().getPort());
      }
      if (_httpBindAddress != null) {
        _unsecuredConnector.setHost(_httpBindAddress);
      }
      if (lowResourcesConnections != null) {
        _unsecuredConnector.setLowResourcesConnections(lowResourcesConnections);
      }
      if (lowResourcesMaxIdleTime != null) {
        _unsecuredConnector.setLowResourcesMaxIdleTime(lowResourcesMaxIdleTime);
      }
      if (threadPool != null) {
        _unsecuredConnector.setThreadPool(threadPool);
      }
      _server.addConnector(_unsecuredConnector);
    }
    if (!_disableSSL) {
      SslContextFactory sslFac = new SslContextFactory();
      sslFac.setIncludeCipherSuites(_ciphers);

      KeyStore ks = KeyStoreUtil.getViPRKeystore(_coordinatorClient);
      _log.debug(
          "The certificates in Jetty is {}. ",
          ks.getCertificateChain(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS));

      sslFac.setCertAlias(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS);
      sslFac.setKeyStore(ks);
      _securedConnector = new SslSelectChannelConnector(sslFac);
      if (_securePort != null) {
        _securedConnector.setPort(Integer.parseInt(_securePort));
      } else {
        _securedConnector.setPort(_serviceInfo.getEndpoint().getPort());
      }
      if (_bindAddress != null) {
        _securedConnector.setHost(_bindAddress);
      }
      if (lowResourcesConnections != null) {
        _securedConnector.setLowResourcesConnections(lowResourcesConnections);
      }
      if (lowResourcesMaxIdleTime != null) {
        _securedConnector.setLowResourcesMaxIdleTime(lowResourcesMaxIdleTime);
      }
      if (threadPool != null) {
        _securedConnector.setThreadPool(threadPool);
      }
      _server.addConnector(_securedConnector);
    }
    _server.setSendServerVersion(false);
  }
Пример #4
0
  public SimpleHttpHandler() {
    this.server = new Server();
    SelectChannelConnector connector0 = new SelectChannelConnector();
    connector0.setPort(8888);
    connector0.setMaxIdleTime(30000);
    connector0.setRequestHeaderSize(8192);

    SelectChannelConnector connector1 = new SelectChannelConnector();
    connector1.setHost("127.0.0.1");
    connector1.setPort(8843);
    connector1.setThreadPool(new QueuedThreadPool(20));
    connector1.setName("admin");
    server.setConnectors(new Connector[] {connector0, connector1});

    server.setHandler(this);
  }
Пример #5
0
  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {

    CommandLineParser parser = new PosixParser();
    String warcDir = null;
    String workDir = null;
    String host = "localhost";

    Options options = new Options();
    options.addOption("h", "help", false, "Show this help message.");
    options.addOption(
        "i",
        "index-folder",
        true,
        "Specify a custom directory for caching the web archiving index files. Indexes are usually re-built every time you start WaybackPlayer, which might be cumbersome for large indexes. Use this option to specify a folder in which to cache the indexes.");
    options.addOption(
        "s", "server-name", true, "Specify a server name to use, defaults to 'localhost'");
    try {
      CommandLine line = parser.parse(options, args);
      String cli_args[] = line.getArgs();

      // Check there is an argument for the warcs folder:
      if (!(cli_args.length > 0)) {
        printUsage(options);
        return;
      }
      warcDir = cli_args[0];

      // Show help if required:
      if (line.hasOption("h")) {
        printUsage(options);
        return;
      }

      // Allow index folder to be overridden (and thus cached):
      if (line.hasOption("i")) {
        workDir = line.getOptionValue("i");
      }

      // Allow the host to be overridden:
      if (line.hasOption("s")) {
        host = line.getOptionValue("s");
      }

    } catch (ParseException e1) {
      e1.printStackTrace();
      return;
    }

    // Avoid requiring the JDK for Jetty JSP compilation.
    // See http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");

    // An embedded server:
    Server server = new Server();

    // Default connector for playback:
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(18080);
    connector.setHost(host);

    // Connector for Proxy mode:
    SelectChannelConnector connector2 = new SelectChannelConnector();
    connector2.setPort(18090);
    connector2.setHost(host);

    // Attach the two connectors:
    server.setConnectors(new Connector[] {connector, connector2});

    // Set a property so Wayback Spring can find the WARCs etc.
    System.setProperty("wayback.warc.dir", warcDir);

    // Set a propery so the host and ports are known:
    System.setProperty("wayback.host", host);
    System.setProperty("wayback.port", "" + 18080);
    System.setProperty("wayback.proxy.port", "" + 18090);

    // TODO Option to wipe it if it's there and looks like ours?
    File waywork = null;
    if (workDir == null) {
      waywork = File.createTempFile("wayback-play", "");
      waywork.delete();
      waywork.mkdir();
      System.setProperty("wayback.work.dir", waywork.getAbsolutePath());
      waywork.deleteOnExit();
    } else {
      waywork = new File(workDir);
      System.setProperty("wayback.work.dir", workDir);
    }
    System.err.println("Indexes held in: " + System.getProperty("wayback.work.dir"));

    // Prior to start up, generate CDX files and path-index.txt file and put them in
    // wayback.work.dir:
    File wdf = new File(warcDir);
    List<String> paths = new ArrayList<String>();
    for (File wf : wdf.listFiles()) {
      paths.add(wf.getName() + "\t" + wf.getAbsolutePath());
      System.out.println("LINE: " + wf.getAbsolutePath());
      // CDX generation:
      File cdxFile = new File(waywork, wf.getName() + ".cdx");
      if (!cdxFile.exists()) {
        System.out.println("Generating " + cdxFile.getPath() + " from " + wf.getPath() + "...");
        IndexWorker.main(new String[] {wf.getAbsolutePath(), cdxFile.getAbsolutePath()});
      } else {
        System.out.println(
            "The CDX " + cdxFile.getPath() + " for " + wf.getPath() + " already exists.");
      }
    }

    // For path-index.txt:
    Collections.sort(paths);
    PrintWriter writer = new PrintWriter(new File(waywork, "path-index.txt"), "UTF-8");
    for (String path : paths) {
      writer.println(path);
    }
    writer.close();

    // Set up the Wayback web app:
    WebAppContext wac = new WebAppContext();
    wac.setContextPath("/");
    // this is path to .war OR TO expanded, existing webapp; WILL FIND web.xml and parse it
    // wac.setWar("/Users/andy/Documents/workspace/waybacks/wayback-play/target/wayback-play");
    URL resourceUrl =
        ClassLoader.getSystemClassLoader().getResource("lib/warc-explorer-player.war");
    // Copy to tmp space:
    File tmpWar = File.createTempFile("wayback-player", ".war");
    tmpWar.deleteOnExit();
    IOUtils.copy(resourceUrl.openStream(), new FileOutputStream(tmpWar));
    // Fire it up:
    wac.setWar(tmpWar.getAbsolutePath());
    server.setHandler(wac);
    server.setStopAtShutdown(true);

    // Launch the server:
    try {
      server.start();
      server.join();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      //
      connector.close();
      try {
        server.stop();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (waywork != null) {
        if (waywork.exists()) {
          waywork.delete();
        }
      }
    }

    System.err.println("Bye.");
  }