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(); }
@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")); }
/** Construct a default instance of this class. */ public StandardServer() { super(); ServerFactory.setServer(this); globalNamingResources = new NamingResources(); globalNamingResources.setContainer(this); if (isUseNaming()) { if (namingContextListener == null) { namingContextListener = new NamingContextListener(); addLifecycleListener(namingContextListener); } } }