Exemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    int port = 7070;
    if (args.length >= 1) {
      port = Integer.parseInt(args[0]);
    }

    // test_case_data/sandbox/ contains HDP 2.2 site xmls which is dev sandbox
    ClasspathUtil.addClasspath(new File("../examples/test_case_data/sandbox").getAbsolutePath());
    System.setProperty(KylinConfig.KYLIN_CONF, "../examples/test_case_data/sandbox");
    System.setProperty("hdp.version", "2.2.0.0-2041"); // mapred-site.xml ref this

    // workaround for job submission from win to linux --
    // https://issues.apache.org/jira/browse/MAPREDUCE-4052
    if (Shell.WINDOWS) {
      {
        Field field = Shell.class.getDeclaredField("WINDOWS");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, false);
      }
      {
        Field field = java.io.File.class.getDeclaredField("pathSeparator");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, ":");
      }
    }

    System.setProperty("spring.profiles.active", "testing");
    String webBase = new File("../webapp/app").getAbsolutePath();
    if (new File(webBase, "WEB-INF").exists() == false) {
      throw new RuntimeException(
          "In order to launch Kylin web app from IDE, please make a symblink from webapp/app/WEB-INF to server/src/main/webapp/WEB-INF");
    }

    Tomcat tomcat = new Tomcat();
    tomcat.setPort(port);
    tomcat.setBaseDir(".");

    // Add AprLifecycleListener
    StandardServer server = (StandardServer) tomcat.getServer();
    AprLifecycleListener listener = new AprLifecycleListener();
    server.addLifecycleListener(listener);

    Context webContext = tomcat.addWebapp("/kylin", webBase);
    ErrorPage notFound = new ErrorPage();
    notFound.setErrorCode(404);
    notFound.setLocation("/index.html");
    webContext.addErrorPage(notFound);
    webContext.addWelcomeFile("index.html");

    // tomcat start
    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 2
0
 /** Is this instance running? */
 public boolean isRunning() {
   return tomcat != null
       && tomcat.getServer().getState().isAvailable()
       && tomcat
           .getServer()
           .getState()
           .getLifecycleEvent()
           .equals(LifecycleState.STARTED.getLifecycleEvent());
 }
Exemplo n.º 3
0
  public static Tomcat startServer(final TomcatConfig tomcatConfig) throws Exception {
    final Tomcat tomcat = new Tomcat();

    Map<String, String> map = tomcatConfig.getProperties();
    for (String key : map.keySet()) {
      System.setProperty(key, map.get(key));
    }

    tomcat.setBaseDir("./target/tomcat");
    tomcat.setSilent(true);
    // um zu verhindern dass sich die jmx namen mit www/info überschneiden
    tomcat.getEngine().setName(tomcatConfig.getName());
    configureHttpConnector(tomcat, tomcatConfig);
    configureHttpsConnector(tomcat, tomcatConfig);
    // jndi wird gestartet, sonst bekommen wir eine hässliche Warnung, weil
    // wir in der HibernateConfig das Property
    // hibernate.session_factory_name setzen
    tomcat.enableNaming();
    String absolutePath = new File(tomcatConfig.getPath()).getAbsolutePath();
    Context context = tomcat.addWebapp("", absolutePath);
    VirtualWebappLoader virtualWebappLoader = new VirtualWebappLoader();
    virtualWebappLoader.setVirtualClasspath("../jlot-web/target/classes");
    context.setLoader(virtualWebappLoader);
    context.setUseHttpOnly(false);
    tomcat.getServer().addLifecycleListener(new TomcatStartupTimeLogger(tomcatConfig.getName()));
    tomcat.start();
    new TomcatRunThread(tomcat).start();
    return tomcat;
  }
Exemplo n.º 4
0
  /**
   * Enables JNDI naming which is disabled by default. Server must implement {@link Lifecycle} in
   * order for the {@link NamingContextListener} to be used.
   */
  public void enableNaming() {
    // Make sure getServer() has been called as that is where naming is
    // disabled
    getServer();
    server.addLifecycleListener(new NamingContextListener());

    System.setProperty("catalina.useNaming", "true");

    String value = "org.apache.naming";
    String oldValue = System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
    if (oldValue != null) {
      if (oldValue.contains(value)) {
        value = oldValue;
      } else {
        value = value + ":" + oldValue;
      }
    }
    System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);

    value = System.getProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY);
    if (value == null) {
      System.setProperty(
          javax.naming.Context.INITIAL_CONTEXT_FACTORY,
          "org.apache.naming.java.javaURLContextFactory");
    }
  }
 // Fireup tomcat and register this servlet
 public static void main(String[] args) throws LifecycleException, SQLException {
   Tomcat tomcat = new Tomcat();
   tomcat.setPort(8080);
   File base = new File(System.getProperty("java.io.tmpdir"));
   Context rootCtx = tomcat.addContext("/", base.getAbsolutePath());
   Tomcat.addServlet(rootCtx, "log", new LogService());
   rootCtx.addServletMapping("/*", "log");
   tomcat.start();
   tomcat.getServer().await();
 }
Exemplo n.º 6
0
  @AfterClass
  public static void cleanup() {
    try {
      if (idpServer.getServer() != null
          && idpServer.getServer().getState() != LifecycleState.DESTROYED) {
        if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
          idpServer.stop();
        }
        idpServer.destroy();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      if (rpServer.getServer() != null
          && rpServer.getServer().getState() != LifecycleState.DESTROYED) {
        if (rpServer.getServer().getState() != LifecycleState.STOPPED) {
          rpServer.stop();
        }
        rpServer.destroy();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 7
0
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();

    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");

    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
      fail("Unable to create appBase for test");
    }

    tomcat = new TomcatWithFastSessionIDs();

    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);

    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
      StandardServer server = (StandardServer) tomcat.getServer();
      AprLifecycleListener listener = new AprLifecycleListener();
      listener.setSSLRandomSeed("/dev/urandom");
      server.addLifecycleListener(listener);
      connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }

    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());

    accessLogEnabled = Boolean.parseBoolean(System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
      AccessLogValve alv = new AccessLogValve();
      alv.setDirectory(getBuildDirectory() + "/logs");
      alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
      tomcat.getHost().getPipeline().addValve(alv);
    }

    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
  }
Exemplo n.º 8
0
 /** Access to the engine, for further customization. */
 public Engine getEngine() {
   if (engine == null) {
     getServer();
     engine = new StandardEngine();
     engine.setName("Tomcat");
     engine.setDefaultHost(hostname);
     if (defaultRealm == null) {
       initSimpleAuth();
     }
     engine.setRealm(defaultRealm);
     service.setContainer(engine);
   }
   return engine;
 }
Exemplo n.º 9
0
 /** Stop this MockServer instance */
 public AbstractRunner<T> stop() {
   if (!isRunning())
     throw new IllegalStateException(
         this.getClass().getSimpleName().replace("Runner", "") + " is not running");
   try {
     serverStopped();
     shutdownThread.stopListening();
     tomcat.stop();
     tomcat.getServer().await();
   } catch (Exception e) {
     throw new RuntimeException(
         "Failed to stop embedded jetty server gracefully, stopping JVM", e);
   }
   return this;
 }
Exemplo n.º 10
0
  /**
   * Get the default http connector. You can set more parameters - the port is already initialized.
   *
   * <p>Alternatively, you can construct a Connector and set any params, then call
   * addConnector(Connector)
   *
   * @return A connector object that can be customized
   */
  public Connector getConnector() {
    getServer();
    if (connector != null) {
      return connector;
    }
    // This will load Apr connector if available,
    // default to nio. I'm having strange problems with apr
    // XXX: jfclere weird... Don't add the AprLifecycleListener then.
    // and for the use case the speed benefit wouldn't matter.

    connector = new Connector("HTTP/1.1");
    // connector = new Connector("org.apache.coyote.http11.Http11Protocol");
    connector.setPort(port);
    service.addConnector(connector);
    return connector;
  }
Exemplo n.º 11
0
  public static void main(String[] args) throws Exception {

    final Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("."); // location where temp dir is created
    tomcat.setPort(8080);

    // configure context
    final File applicationPath = new File("./webapp"); // todo: change to your location
    Context rootContext =
        tomcat.addContext("/", "C:\\Users\\Ali\\git\\finder\\finder\\src\\main\\webapp");
    rootContext.addLifecycleListener(new ContextConfig());

    // JSP and Default Servlet setup, mime type mapping and welcome files
    Tomcat.initWebappDefaults(rootContext);

    // start server
    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 12
0
  public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    // The port that we should run on can be set into an environment variable
    // Look for that variable and default to 8080 if it isn't there.
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
      webPort = "8089";
    }

    tomcat.setPort(Integer.valueOf(webPort));

    tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    System.out.println(
        "configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 13
0
  public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    // The port that we should run on can be set into an environment variable
    // Look for that variable and default to 8080 if it isn't there.
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
      webPort = "8080";
    }

    tomcat.setPort(Integer.valueOf(webPort));
    tomcat.enableNaming();

    Connector connector = new Connector(MinaProtocol.class.getName());
    connector.setPort(8090);
    tomcat.getService().addConnector(connector);

    Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    ((StandardJarScanner) ctx.getJarScanner()).setScanAllDirectories(true);

    tomcat.start();
    tomcat.getServer().await();
  }
Exemplo n.º 14
0
 public void stopServer() throws Exception {
   tomcat.stop();
   tomcat.getServer().await();
   serverStopped();
 }
Exemplo n.º 15
0
 /**
  * Stop the server.
  *
  * @throws LifecycleException
  */
 public void stop() throws LifecycleException {
   getServer();
   server.stop();
 }
Exemplo n.º 16
0
 public void join() throws InterruptedException {
   tomcat.getServer().await();
 }
Exemplo n.º 17
0
 /**
  * Start the server.
  *
  * @throws LifecycleException
  */
 public void start() throws LifecycleException {
   getServer();
   getConnector();
   server.start();
 }
Exemplo n.º 18
0
 /** Destroy the server. This object cannot be used once this method has been called. */
 public void destroy() throws LifecycleException {
   getServer();
   server.destroy();
   // Could null out objects here
 }
Exemplo n.º 19
0
 /** Get the service object. Can be used to add more connectors and few other global settings. */
 public Service getService() {
   getServer();
   return service;
 }