コード例 #1
0
 public static void main(String[] args) throws Exception {
   Server server = new Server(80);
   WebAppContext webapp = new WebAppContext();
   webapp.setResourceBase("/");
   webapp.setContextPath("/*");
   webapp.setConfigurations(
       new Configuration[] {
         new WebXmlConfiguration(),
         new AnnotationConfiguration() {
           @Override
           public void preConfigure(WebAppContext context) throws Exception {
             ClassInheritanceMap map = new ClassInheritanceMap();
             map.put(
                 WebApplicationInitializer.class.getName(),
                 new ConcurrentHashSet<String>() {
                   {
                     add(Initializer.class.getName());
                     add(SpringSecurityInitializer.class.getName());
                   }
                 });
             context.setAttribute(CLASS_INHERITANCE_MAP, map);
             _classInheritanceHandler = new ClassInheritanceHandler(map);
           }
         }
       });
   server.setHandler(webapp);
   server.start();
   System.out.println("Application started!");
   server.join();
 }
コード例 #2
0
ファイル: EmbeddedServer.java プロジェクト: bbytes/zorba
  public static void main(String[] args) {
    ApplicationContext appContext =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/jetty-server.xml");

    Server server = appContext.getBean(Server.class);

    try {

      WebAppContext webAppContext = new WebAppContext();
      webAppContext.setContextPath("/");
      webAppContext.setWar(IDE_WAR_LOCATION);

      webAppContext.setServer(server);
      server.setHandler(webAppContext);
      server.start();
      server.join();
      System.out.println("Zorba web server running....");
      System.out.println("Enter :q and hit enter to quit: ");
      while (true) {

        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        String str = bufferRead.readLine();
        if (str != null && !str.isEmpty())
          if (str.trim().equals(":q")) {
            System.out.println("exiting system...");
            server.stop();
            System.exit(0);
          }
        Thread.sleep(1000);
      }

    } catch (Exception e) {
      logger.error("Error when starting", e);
    }
  }
コード例 #3
0
ファイル: StartExamples.java プロジェクト: tfreier/wicket
  /**
   * Main function, starts the jetty server.
   *
   * @param args
   */
  public static void main(String[] args) {
    //		System.setProperty("wicket.configuration", "development");

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.setConnectors(new Connector[] {connector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    server.setHandler(bb);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.getContainer().addEventListener(mBeanContainer);

    try {
      mBeanContainer.start();
      server.start();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
コード例 #4
0
  public void visitContainerInitializer(
      WebAppContext context, ContainerInitializer containerInitializer) {
    if (containerInitializer == null) return;

    // add the ContainerInitializer to the list of container initializers
    List<ContainerInitializer> containerInitializers =
        (List<ContainerInitializer>)
            context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
    if (containerInitializers == null) {
      containerInitializers = new ArrayList<ContainerInitializer>();
      context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS, containerInitializers);
    }

    containerInitializers.add(containerInitializer);

    // Ensure a bean is set up on the context that will invoke the ContainerInitializers as the
    // context starts
    ServletContainerInitializersStarter starter =
        (ServletContainerInitializersStarter)
            context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
    if (starter == null) {
      starter = new ServletContainerInitializersStarter(context);
      context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
      context.addBean(starter, true);
    }
  }
コード例 #5
0
  public static void main(String[] args) throws Exception {
    disableJavaLogging();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(determineServerPort());
    server.setConnectors(new Connector[] {connector});

    WebAppContext context = new WebAppContext();
    context.setServer(server);
    context.setContextPath("/");

    ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    context.setWar(location.toExternalForm());

    server.setHandler(context);
    server.start();

    Desktop.getDesktop().browse(URI.create("http://localhost:" + connector.getPort() + "/"));

    server.join();
  }
コード例 #6
0
  /**
   * @see
   *     org.eclipse.jetty.webapp.AbstractConfiguration#postConfigure(org.eclipse.jetty.webapp.WebAppContext)
   */
  @Override
  public void postConfigure(WebAppContext context) throws Exception {
    ConcurrentHashMap<String, ConcurrentHashSet<String>> classMap =
        (ClassInheritanceMap) context.getAttribute(CLASS_INHERITANCE_MAP);
    List<ContainerInitializer> initializers =
        (List<ContainerInitializer>) context.getAttribute(CONTAINER_INITIALIZERS);

    context.removeAttribute(CLASS_INHERITANCE_MAP);
    if (classMap != null) classMap.clear();

    context.removeAttribute(CONTAINER_INITIALIZERS);
    if (initializers != null) initializers.clear();

    if (_discoverableAnnotationHandlers != null) _discoverableAnnotationHandlers.clear();

    _classInheritanceHandler = null;
    if (_containerInitializerAnnotationHandlers != null)
      _containerInitializerAnnotationHandlers.clear();

    if (_parserTasks != null) {
      _parserTasks.clear();
      _parserTasks = null;
    }

    super.postConfigure(context);
  }
コード例 #7
0
  public EmbeddedJettyServer(int port, boolean useRestSession) throws Exception {
    server = new Server();
    connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    root = new WebAppContext();
    root.setContextPath("/");
    root.setResourceBase(".");
    if (useRestSession) {
      RestSessionIdManager idManager = new RestSessionIdManager();
      RestSessionManager sessionManager = new RestSessionManager();
      server.setSessionIdManager(idManager);
      sessionManager.setSessionIdManager(idManager);
      SessionHandler sessionHandler = new SessionHandler();
      sessionHandler.setSessionManager(sessionManager);
      root.setSessionHandler(sessionHandler);
      root.setClassLoader(getContextClassLoader());
    }

    server.setHandler(root);
    server.start();
    while (!server.isStarted()) {
      Thread.sleep(100);
    }
  }
コード例 #8
0
 private Handler createResourceHandler(String context, String resourceBase) {
   WebAppContext ctx = new WebAppContext();
   ctx.setContextPath(context);
   ctx.setResourceBase(resourceBase);
   ctx.setParentLoaderPriority(true);
   return ctx;
 }
コード例 #9
0
  private void addWebApp(String path, String warPath) throws Exception {
    if (handlerCollection != null) {
      //			boolean extractWar = warPath.endsWith(".war");
      //			boolean parentLoaderPriority = true;

      // add it to the server
      //			boolean restartHandler = handlerCollection.isRunning();
      //			if (restartHandler) {
      //				handlerCollection.stop();
      //			}

      logger.log(Level.INFO, "Adding web app: " + warPath + " to path " + path);

      // create a webapp
      WebAppContext wah = new WebAppContext(handlerCollection, warPath, path);

      // configure it
      //			wah.setExtractWAR(extractWar);
      //			wah.setParentLoaderPriority(parentLoaderPriority);

      wah.setClassLoader(ObjectUtility.class.getClassLoader()); // set MeemServer classloader

      handlerCollection.addHandler(wah);
      wah.start();

      //			if (restartHandler) {
      //				handlerCollection.start();
      //			}
    }
  }
コード例 #10
0
  /**
   * Check to see if the ServletContainerIntializer loaded via the ServiceLoader came from a jar
   * that is excluded by the fragment ordering. See ServletSpec 3.0 p.85.
   *
   * @param context
   * @param sci
   * @return true if excluded
   */
  public boolean isFromExcludedJar(
      WebAppContext context, ServletContainerInitializer sci, Resource sciResource)
      throws Exception {
    if (sci == null) throw new IllegalArgumentException("ServletContainerInitializer null");
    if (context == null) throw new IllegalArgumentException("WebAppContext null");

    if (LOG.isDebugEnabled()) LOG.debug("Checking {} for jar exclusion", sci);

    // A ServletContainerInitializer that came from the container's classpath cannot be excluded by
    // an ordering
    // of WEB-INF/lib jars
    if (isFromContainerClassPath(context, sci)) return false;

    List<Resource> orderedJars = context.getMetaData().getOrderedWebInfJars();

    // If no ordering, nothing is excluded
    if (context.getMetaData().getOrdering() == null) return false;

    // there is an ordering, but there are no jars resulting from the ordering, everything excluded
    if (orderedJars.isEmpty()) return true;

    if (sciResource == null)
      return false; // not from a jar therefore not from WEB-INF so not excludable

    URI loadingJarURI = sciResource.getURI();
    boolean found = false;
    Iterator<Resource> itor = orderedJars.iterator();
    while (!found && itor.hasNext()) {
      Resource r = itor.next();
      found = r.getURI().equals(loadingJarURI);
    }

    return !found;
  }
コード例 #11
0
  public static void main(String[] args) {
    try {
      Server server = new Server();
      ServerConnector connector = new ServerConnector(server);
      connector.setPort(8080);
      server.addConnector(connector);

      WebAppContext context = new WebAppContext();
      context.setContextPath("/");
      context.setWar("src/test/webapp");
      context.setInitParameter(
          SessionManager.__CheckRemoteSessionEncoding,
          "true"); // Stops Jetty from adding 'jsessionid' URL rewriting into non-local URLs (e.g.
                   // Google OpenId redirects)

      server.setHandler(context);

      server.addLifeCycleListener(
          new AbstractLifeCycle.AbstractLifeCycleListener() {
            @Override
            public void lifeCycleStarted(LifeCycle event) {
              log.warn("Jetty ready to accept requests...");
            }
          });

      server.start();
      server.join();
    } catch (Exception e) {
      throw new RuntimeException("Error launching Jetty", e);
    }
  }
コード例 #12
0
  @Override
  public void run() {

    System.out.println(
        "/n>>> About to execute: " + Runner.class.getName() + ".run() to clean up before JV");
    if (webapp.isStarted()) {
      try {
        webapp.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (connector.isStarted()) {
      try {
        connector.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (server.isStarted()) {
      try {
        server.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    System.out.println(">>> Finished execution: " + Runner.class.getName() + ".run()");
  }
コード例 #13
0
ファイル: Start.java プロジェクト: StefanLindner/core
  public static void main(String[] args) throws Exception {
    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.setConnectors(new Connector[] {connector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      while (System.in.available() == 0) {
        Thread.sleep(5000);
      }
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
コード例 #14
0
ファイル: VRaptorServer.java プロジェクト: brunopenha/mamute
 private static WebAppContext loadContext(String webappDirLocation, String webXmlLocation) {
   WebAppContext context = new WebAppContext();
   context.setContextPath(getContext());
   context.setDescriptor(webXmlLocation);
   context.setResourceBase(webappDirLocation);
   context.setParentLoaderPriority(true);
   return context;
 }
コード例 #15
0
ファイル: HttpServer.java プロジェクト: alanfgates/hive
 /** Create the web context for the application of specified name */
 WebAppContext createWebAppContext(Builder b) {
   WebAppContext ctx = new WebAppContext();
   setContextAttributes(ctx.getServletContext(), b.contextAttrs);
   ctx.setDisplayName(b.name);
   ctx.setContextPath("/");
   ctx.setWar(appDir + "/" + b.name);
   return ctx;
 }
コード例 #16
0
  private void doStart() {
    if (!available(port)) throw new IllegalStateException("port: " + port + " already in use!");

    deleteSessionData();

    System.out.println("Starting JFinal " + Const.JFINAL_VERSION);
    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);
    webApp = new WebAppContext();
    webApp.setThrowUnavailableOnStartupException(true); // 在启动过程中允许抛出异常终止启动并退出 JVM
    webApp.setContextPath(context);
    webApp.setResourceBase(webAppDir); // webApp.setWar(webAppDir);
    webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    webApp.setInitParameter(
        "org.eclipse.jetty.servlet.Default.useFileMappedBuffer",
        "false"); // webApp.setInitParams(Collections.singletonMap("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false"));
    persistSession(webApp);

    server.setHandler(webApp);
    changeClassLoader(webApp);

    // configureScanner
    if (scanIntervalSeconds > 0) {
      Scanner scanner =
          new Scanner(PathKit.getRootClassPath(), scanIntervalSeconds) {
            public void onChange() {
              try {
                System.err.println("\nLoading changes ......");
                webApp.stop();
                JFinalClassLoader loader = new JFinalClassLoader(webApp, getClassPath());
                webApp.setClassLoader(loader);
                webApp.start();
                System.err.println("Loading complete.");
              } catch (Exception e) {
                System.err.println(
                    "Error reconfiguring/restarting webapp after change in watched files");
                LogKit.error(e.getMessage(), e);
              }
            }
          };
      System.out.println("Starting scanner at interval of " + scanIntervalSeconds + " seconds.");
      scanner.start();
    }

    try {
      System.out.println("Starting web server on port: " + port);
      server.start();
      System.out.println("Starting Complete. Welcome To The JFinal World :)");
      server.join();
    } catch (Exception e) {
      LogKit.error(e.getMessage(), e);
      System.exit(100);
    }
    return;
  }
 @Override
 public WebAppContext buildContext() {
   WebAppContext context = new WebAppContext("src/test/webapp", "/test");
   /*
    * Sets the classloading model for the context to avoid an strange "ClassNotFoundException: org.slf4j.Logger"
    */
   context.setParentLoaderPriority(true);
   return context;
 }
コード例 #18
0
ファイル: WebServer.java プロジェクト: Pavithrak/practice
 public void runServer() throws Exception {
   server = new Server(8060);
   WebAppContext webapp = new WebAppContext();
   webapp.setContextPath("/");
   webapp.setWar("/home/pavithra/Documents/kavitha/RS/dest/recruit.war");
   server.setHandler(webapp);
   server.start();
   server.join();
 }
コード例 #19
0
  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    WebAppContext context = new WebAppContext();
    context.setDescriptor("src/main/webapp/WEB-INF/web.xml");
    context.setResourceBase("src/main/webapp/");
    context.setContextPath("/");
    context.setParentLoaderPriority(true);
    server.setHandler(context);
    server.start();
  }
コード例 #20
0
 @Override
 public void deconfigure(WebAppContext context) throws Exception {
   context.removeAttribute(CLASS_INHERITANCE_MAP);
   context.removeAttribute(CONTAINER_INITIALIZERS);
   ServletContainerInitializersStarter starter =
       (ServletContainerInitializersStarter) context.getAttribute(CONTAINER_INITIALIZER_STARTER);
   if (starter != null) {
     context.removeBean(starter);
     context.removeAttribute(CONTAINER_INITIALIZER_STARTER);
   }
 }
コード例 #21
0
ファイル: JettyFactory.java プロジェクト: qljlld/aglieEAP
  /** 设置除jstl-*.jar外其他含tld文件的jar包的名称. jar名称不需要版本号,如sitemesh, shiro-web */
  public static void setTldJarNames(Server server, String... jarNames) {
    WebAppContext context = (WebAppContext) server.getHandler();
    List<String> jarNameExprssions =
        Lists.newArrayList(".*/jstl-[^/]*\\.jar$", ".*/.*taglibs[^/]*\\.jar$");
    for (String jarName : jarNames) {
      jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$");
    }

    context.setAttribute(
        "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
        StringUtils.join(jarNameExprssions, '|'));
  }
コード例 #22
0
  /**
   * Scan jars in WEB-INF/lib
   *
   * @param context
   * @param parser
   * @throws Exception
   */
  public void parseWebInfLib(final WebAppContext context, final AnnotationParser parser)
      throws Exception {
    List<FragmentDescriptor> frags = context.getMetaData().getFragments();

    // email from Rajiv Mordani jsrs 315 7 April 2010
    // jars that do not have a web-fragment.xml are still considered fragments
    // they have to participate in the ordering
    ArrayList<URI> webInfUris = new ArrayList<URI>();

    List<Resource> jars = context.getMetaData().getOrderedWebInfJars();

    // No ordering just use the jars in any order
    if (jars == null || jars.isEmpty()) jars = context.getMetaData().getWebInfJars();

    _webInfLibStats = new CounterStatistic();

    for (Resource r : jars) {
      // for each jar, we decide which set of annotations we need to parse for
      final Set<Handler> handlers = new HashSet<Handler>();

      FragmentDescriptor f = getFragmentFromJar(r, frags);

      // if its from a fragment jar that is metadata complete, we should skip scanning for
      // @webservlet etc
      // but yet we still need to do the scanning for the classes on behalf of  the
      // servletcontainerinitializers
      // if a jar has no web-fragment.xml we scan it (because it is not excluded by the ordering)
      // or if it has a fragment we scan it if it is not metadata complete
      if (f == null
          || !isMetaDataComplete(f)
          || _classInheritanceHandler != null
          || !_containerInitializerAnnotationHandlers.isEmpty()) {
        // register the classinheritance handler if there is one
        if (_classInheritanceHandler != null) handlers.add(_classInheritanceHandler);

        // register the handlers for the @HandlesTypes values that are themselves annotations if
        // there are any
        handlers.addAll(_containerInitializerAnnotationHandlers);

        // only register the discoverable annotation handlers if this fragment is not metadata
        // complete, or has no fragment descriptor
        if (f == null || !isMetaDataComplete(f)) handlers.addAll(_discoverableAnnotationHandlers);

        if (_parserTasks != null) {
          ParserTask task = new ParserTask(parser, handlers, r, _webAppClassNameResolver);
          _parserTasks.add(task);
          _webInfLibStats.increment();
          if (LOG.isDebugEnabled()) task.setStatistic(new TimeStatistic());
        }
      }
    }
  }
コード例 #23
0
  public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setResourceBase("webapp");
    webAppContext.setDescriptor("webapp/WEB-INF/web.xml");
    webAppContext.setContextPath("/");
    // server.setHandler(webAppContext);
    server.setHandler(new HelloWorld());

    server.start();
    server.join();
  }
コード例 #24
0
ファイル: TestServer.java プロジェクト: eohlson/gwt-board
  public TestServer(Integer runningPort) {
    server = new Server(runningPort);

    ContextHandlerCollection contexts = new ContextHandlerCollection();

    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setWar("./src/main/webapp");
    webAppContext.setContextPath("/");

    contexts.setHandlers(new Handler[] {webAppContext});

    setHandler(contexts);
  }
コード例 #25
0
ファイル: Launcher.java プロジェクト: turbosystem/portal
  public static void main(String[] args) throws Exception {
    Locale.setDefault(Locale.ENGLISH);

    Server server = new Server(8899);
    WebAppContext context = new WebAppContext("src/main/webapp", "/");

    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
      // Fix for Windows, so Jetty doesn't lock files
      context.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
    }
    server.setHandler(context);
    server.start();
  }
コード例 #26
0
  public void start() throws Exception {
    server = new Server();

    WebAppContext wac = new WebAppContext();
    wac.setContextPath(contextPath);
    wac.setWar(warPath);
    server.setHandler(wac);

    SelectChannelConnector scc = new SelectChannelConnector();
    scc.setPort(port);
    server.addConnector(scc);
    server.start();
  }
コード例 #27
0
  /** @throws Exception */
  public void testSessionRenewal() throws Exception {
    String contextPath = "";
    String servletMapping = "/server";
    int maxInactive = 1;
    int scavengePeriod = 3;
    _server = createServer(0, maxInactive, scavengePeriod, SessionCache.NEVER_EVICT);
    WebAppContext context = _server.addWebAppContext(".", contextPath);
    context.setParentLoaderPriority(true);
    context.addServlet(TestServlet.class, servletMapping);
    TestHttpSessionIdListener testListener = new TestHttpSessionIdListener();
    context.addEventListener(testListener);

    HttpClient client = new HttpClient();
    try {
      _server.start();
      int port = _server.getPort();

      client.start();

      // make a request to create a session
      ContentResponse response =
          client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
      assertEquals(HttpServletResponse.SC_OK, response.getStatus());

      String sessionCookie = response.getHeaders().get("Set-Cookie");
      assertTrue(sessionCookie != null);
      assertFalse(testListener.isCalled());

      // make a request to change the sessionid
      Request request =
          client.newRequest(
              "http://localhost:" + port + contextPath + servletMapping + "?action=renew");
      request.header("Cookie", sessionCookie);
      ContentResponse renewResponse = request.send();

      assertEquals(HttpServletResponse.SC_OK, renewResponse.getStatus());
      String renewSessionCookie = renewResponse.getHeaders().get("Set-Cookie");
      assertNotNull(renewSessionCookie);
      assertNotSame(sessionCookie, renewSessionCookie);
      assertTrue(testListener.isCalled());

      assertTrue(
          verifyChange(
              context,
              AbstractTestServer.extractSessionId(sessionCookie),
              AbstractTestServer.extractSessionId(renewSessionCookie)));
    } finally {
      client.stop();
      _server.stop();
    }
  }
コード例 #28
0
  public static void main(String[] args) throws Exception {
    System.out.println("Starting Frontend...");
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setResourceBase("webapp");
    webAppContext.setDescriptor("webapp/WEB-INF/web.xml");

    Server server = new Server(8080);
    server.setHandler(webAppContext);

    server.start();
    System.out.println("Started Frontend.");
    server.join();
  }
コード例 #29
0
 /**
  * Work out how long we should wait for the async scanning to occur.
  *
  * @param context
  * @return
  */
 protected int getMaxScanWait(WebAppContext context) {
   // try context attribute to get max time in sec to wait for scan completion
   Object o = context.getAttribute(MAX_SCAN_WAIT);
   if (o != null && o instanceof Number) {
     return ((Number) o).intValue();
   }
   // try server attribute to get max time in sec to wait for scan completion
   o = context.getServer().getAttribute(MAX_SCAN_WAIT);
   if (o != null && o instanceof Number) {
     return ((Number) o).intValue();
   }
   // try system property to get max time in sec to wait for scan completion
   return Integer.getInteger(MAX_SCAN_WAIT, DEFAULT_MAX_SCAN_WAIT).intValue();
 }
コード例 #30
0
ファイル: JettyLauncher.java プロジェクト: sara62/gitbucket
  public static void main(String[] args) throws Exception {
    String host = null;
    int port = 8080;
    String contextPath = "/";
    boolean forceHttps = false;

    for (String arg : args) {
      if (arg.startsWith("--") && arg.contains("=")) {
        String[] dim = arg.split("=");
        if (dim.length >= 2) {
          if (dim[0].equals("--host")) {
            host = dim[1];
          } else if (dim[0].equals("--port")) {
            port = Integer.parseInt(dim[1]);
          } else if (dim[0].equals("--prefix")) {
            contextPath = dim[1];
          } else if (dim[0].equals("--https") && (dim[1].equals("1") || dim[1].equals("true"))) {
            forceHttps = true;
          } else if (dim[0].equals("--gitbucket.home")) {
            System.setProperty("gitbucket.home", dim[1]);
          }
        }
      }
    }

    Server server = new Server();

    HttpsSupportConnector connector = new HttpsSupportConnector(forceHttps);
    if (host != null) {
      connector.setHost(host);
    }
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(port);
    server.addConnector(connector);

    WebAppContext context = new WebAppContext();
    ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
    URL location = domain.getCodeSource().getLocation();

    context.setContextPath(contextPath);
    context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
    context.setServer(server);
    context.setWar(location.toExternalForm());

    server.setHandler(context);
    server.start();
    server.join();
  }