Ejemplo n.º 1
0
  public void applyHandle(Boolean warDeployFlag) {
    if (StringUtils.isBlank(webDefault)) {
      webDefault = "org.eclipse.jetty.webapp.webdefault.xml";
    }

    // contexts handler
    ContextHandlerCollection contexthandler = new ContextHandlerCollection();

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(contextPath);
    webapp.setDefaultsDescriptor(webDefault);
    webapp.setTempDirectory(new File(warTmp));

    // webapp.setParentLoaderPriority(true);
    if (!warDeployFlag) {
      webapp.setResourceBase(resourceBase);
      webapp.setDescriptor(webXmlPath);
    } else {
      webapp.setWar(warPath);
    }

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] {"index.html"});
    resource_handler.setResourceBase(resourceBase);

    contexthandler.setHandlers(
        new Handler[] {
          webapp, resource_handler, new DefaultHandler(), new StatisticsHandler(), new GzipHandler()
        });

    super.setHandler(contexthandler);
  }
Ejemplo n.º 2
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;
    }
  }
Ejemplo n.º 3
0
  public static Server addWebApplication(
      final Server jetty, final String webAppContext, final String warFilePath) {
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(webAppContext);
    webapp.setWar(warFilePath);
    webapp.setParentLoaderPriority(false);

    File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
    tmpPath.mkdirs();
    webapp.setTempDirectory(tmpPath);

    ((HandlerCollection) jetty.getHandler()).addHandler(webapp);

    return jetty;
  }
Ejemplo n.º 4
0
  private static WebAppContext buildContext() throws IOException {
    ProtectionDomain protectionDomain = Startup.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();

    WebAppContext context = new WebAppContext();
    WebAppClassLoader webAppClassLoader =
        new WebAppClassLoader(Startup.class.getClassLoader(), context);
    context.setClassLoader(webAppClassLoader);
    context.setContextPath(URIUtil.SLASH);
    context.setWar(location.toExternalForm());

    if (tempDir != null) {
      File tempDirectory = new File(tempDir);
      context.setTempDirectory(tempDirectory);
    }
    return context;
  }
Ejemplo n.º 5
0
 public EmbeddedWebServer(BimServer bimServer, boolean localDev) {
   server = new Server();
   //		Disabled 26-04-2015, I am pretty sure we don't use session anymore at all
   //		HashSessionIdManager hashSessionIdManager = new HashSessionIdManager(new Random()); //
   // Should be SecureRandom, but this makes startup slow on certain systems
   //		server.setSessionIdManager(hashSessionIdManager);
   ServerConnector socketConnector = new ServerConnector(server);
   socketConnector.setPort(bimServer.getConfig().getPort());
   server.addConnector(socketConnector);
   context = new WebAppContext(server, "", "/");
   context.setTempDirectory(bimServer.getHomeDir().resolve("jettytmp").toFile());
   if (localDev) {
     // TODO document why
     context.setDefaultsDescriptor("www/WEB-INF/webdefault.xml");
   }
   context.getServletContext().setAttribute("bimserver", bimServer);
   if (context.getResourceBase() == null) {
     context.setResourceBase("../BimServer/www");
   }
 }
Ejemplo n.º 6
0
  /** @param args */
  public static void main(String[] args) throws Exception {
    new Runner();
    final int port = Integer.parseInt(System.getProperty("port", "9999"));
    final int thread = Integer.parseInt(System.getProperty("thread", "50"));
    final int idleTimeout = Integer.parseInt(System.getProperty("thread", "60000"));
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(thread);
    server = new Server(threadPool);

    String jettyVersion = Server.getVersion();
    ProtectionDomain protectionDomain = NetworkTrafficServerConnector.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    String warFile = location.toExternalForm();
    String currentDir = new File(location.getPath()).getParent();
    File workDir = new File(currentDir, "work");

    System.out.println("##########port=" + port);
    System.out.println("##########thread=" + thread);
    System.out.println("##########idleTimeout=" + idleTimeout);
    System.out.println("##########jettyVersion=" + jettyVersion);
    System.out.println("##########port=" + port);
    System.out.println("##########currentDir=" + currentDir);
    System.out.println("##########workDir=" + workDir);
    System.out.println("##########warFile=" + warFile);

    webapp = new WebAppContext();
    webapp.setContextPath("/");
    // webapp.setResourceBase(".");
    webapp.setTempDirectory(workDir);
    // webapp.setClassLoader(Thread.currentThread().getContextClassLoader());
    webapp.setWar(warFile);

    connector = new NetworkTrafficServerConnector(server);
    connector.setPort(port);
    connector.setIdleTimeout(idleTimeout);
    server.addConnector(connector);
    server.setHandler(webapp);
    server.start();
    server.join();
  }
Ejemplo n.º 7
0
  private static Server createServer(String contextPath, int port) {
    // use Eclipse JDT compiler
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");

    Server server = new Server(port);
    server.setStopAtShutdown(true);

    ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    String warFile = location.toExternalForm();

    WebAppContext context = new WebAppContext(warFile, contextPath);
    context.setServer(server);

    // 设置work dir,war包将解压到该目录,jsp编译后的文件也将放入其中。
    String currentDir = new File(location.getPath()).getParent();
    File workDir = new File(currentDir, "work");
    context.setTempDirectory(workDir);

    server.setHandler(context);
    return server;
  }
Ejemplo n.º 8
0
  public static void main(String[] args) throws Exception {

    setThreadClassLoader();
    processOptions();
    WebAppContext context = buildContext();

    if (tempDir != null) {
      File tempDirectory = new File(tempDir);
      context.setTempDirectory(tempDirectory);
    }

    Server server = new Server();
    if (usingSSL) {
      server.setConnectors(new Connector[] {buildConnector(), buildSslConnector()});
    } else {
      server.setConnectors(new Connector[] {buildConnector()});
    }
    server.setHandler(context);
    server.setSendServerVersion(false);

    run(server);
  }