示例#1
0
  /**
   * Start Jetty web server
   *
   * @param version of bigloupe-chart
   * @return
   * @throws Exception
   */
  private Server startWebServer(String version) throws Exception {
    if (!cmd.hasOption(OPTION_NO_WEBSERVER)) {

      applyOptionWithWebServer();

      Server server = new Server(getPortWebServer());

      WebAppContext root = new WebAppContext();
      root.setContextPath("/");

      if (cmd.hasOption(OPTION_WEBSERVER_WEBROOT)) {
        String webRoot = cmd.getOptionValue(OPTION_WEBSERVER_WEBROOT);
        Resource resource = FileResource.newResource(webRoot);
        root.setBaseResource(resource);

      } else {
        String webFiles = "bigloupe-chart-" + version + "-webapp.war";
        File fileWebApp = new File(webFiles);
        if (!fileWebApp.exists()) {
          if (version.equals("'undefined'")) {
            Resource resource = FileResource.newResource("src/main/webapp");
            root.setBaseResource(resource);
            root.setDefaultsDescriptor("./etc/webdefault.xml");
            logger.info(
                "Embedded webServer started with base resource "
                    + resource.getFile().getAbsolutePath());
          } else {
            logger.info(webFiles + " file not available");
            logger.info("Embedded webServer will be not started");
            return null;
          }
        } else {
          root.setWar(fileWebApp.getAbsolutePath());
        }
      }

      File tmp = new File("tmp");
      if (!tmp.exists()) tmp.mkdir();
      root.setTempDirectory(tmp);

      ContextHandlerCollection contexts = new ContextHandlerCollection();
      Handler handlerHawtIO = addWebApplicationHawtIO();
      if (handlerHawtIO != null) contexts.setHandlers(new Handler[] {root, handlerHawtIO});
      else contexts.setHandlers(new Handler[] {root});
      server.setHandler(contexts);

      server.start();
      addWebServerJMXSupport(server);
      return server;
    } else {
      applyOptionWithoutWebServer();
      return null;
    }
  }
  @Override
  public ServletContainer start(TreeLogger logger, int port, File appRootDir) throws Exception {

    ServletContainer sc = super.start(logger, port, appRootDir);
    org.eclipse.jetty.util.resource.FileResource.setCheckAliases(false);

    return sc;
  }