示例#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();
  }
 private ErrorPage createErrorPage(final ErrorPageModel model) {
   NullArgumentException.validateNotNull(model, "model");
   NullArgumentException.validateNotNull(model.getLocation(), "model#location");
   NullArgumentException.validateNotNull(model.getError(), "model#error");
   final ErrorPage errorPage = new ErrorPage();
   errorPage.setLocation(model.getLocation());
   final Integer errorCode = parseErrorCode(model.getError());
   if (errorCode != null) {
     errorPage.setErrorCode(errorCode);
   } else {
     errorPage.setExceptionType(model.getError());
   }
   return errorPage;
 }
 public void addToContext(Context context) {
   Assert.state(
       this.nativePage != null,
       "Neither Tomcat 7 nor 8 detected so no native error page exists");
   if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage", null)) {
     org.apache.catalina.deploy.ErrorPage errorPage =
         (org.apache.catalina.deploy.ErrorPage) this.nativePage;
     errorPage.setLocation(this.location);
     errorPage.setErrorCode(this.errorCode);
     errorPage.setExceptionType(this.exceptionType);
     context.addErrorPage(errorPage);
   } else {
     callMethod(this.nativePage, "setLocation", this.location, String.class);
     callMethod(this.nativePage, "setErrorCode", this.errorCode, int.class);
     callMethod(this.nativePage, "setExceptionType", this.exceptionType, String.class);
     callMethod(context, "addErrorPage", this.nativePage, this.nativePage.getClass());
   }
 }