Example #1
0
  /** @param args Not used */
  public static void main(final String[] args) {
    LOG.info("Starting service");

    final Properties velocityConfig = new Properties();
    try {
      velocityConfig.load(Start.class.getResourceAsStream("/velocity.properties"));
    } catch (final IOException e1) {
      LOG.error("Cannot read velocity config", e1);
      error("Internal error. Check the logs!");
    }
    Velocity.init(velocityConfig);

    FileReader r;
    try {
      r = new FileReader(new File("config.properties"));
    } catch (final FileNotFoundException e1) {
      error("Missing config file (./config.properties) See config.sample.properties!");
      throw new RuntimeException(e1);
    }

    //
    // Read configuration
    //
    final Properties config = new Properties();
    try {
      config.load(r);
    } catch (final IOException e1) {
      error("Error reading config file (./config.properties)");
      throw new RuntimeException(e1);
    }

    /* *****************************************************
     *
     * HTTP Client
     */

    // httpclient.host
    // Active Collab API host
    String apiHost = config.getProperty("httpclient.apihost");
    if (null == apiHost || apiHost.isEmpty()) {
      error("Missing parameter: 'apihost'");
    }
    if (apiHost.endsWith("/")) {
      apiHost = apiHost.substring(0, apiHost.length() - 1);
    }

    // create client
    final ACHttpClient client =
        new ACHttpClient(
            apiHost,
            getIntValue(config, "httpclient.maxConnections", "20"),
            getIntValue(config, "httpclient.threadPoolSize", "100"),
            true);

    /* *****************************************************
     *
     * Task cache
     */

    // init caches
    TaskCache.init(client);
    CompanyCache.init(
        client,
        getLongValue(config, "cache.company.timeout", "1800000"),
        getLongValue(config, "cache.company.size", "5000"));
    ProjectCache.init(client);

    // creating handlers
    final HandlerList hc = new HandlerList();

    // cookie handling
    hc.addHandler(new FileServerHandler());

    // cookie handling
    hc.addHandler(new ApiKeyCheckerHandler(client));

    // handler for project list
    hc.addHandler(new ProjectListHandler(client));

    // handler for project home
    hc.addHandler(new ProjectHomeHandler());

    // creating the server
    final Server server = new Server(getIntValue(config, "server.port", "8080"));
    server.setHandler(hc);

    try {
      server.start();
    } catch (final Exception e) {
      LOG.error("Cannot start web server", e);
      System.exit(1);
    }
    try {
      server.join();
    } catch (final InterruptedException e) {
      LOG.error("Cannot join web server", e);
      System.exit(2);
    }

    LOG.info("Service stopped");
  }