@BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { port1 = findFreePort(); embedded = new Embedded(); String path = new File(".").getAbsolutePath(); embedded.setCatalinaHome(path); Engine engine = embedded.createEngine(); engine.setDefaultHost("127.0.0.1"); Host host = embedded.createHost("127.0.0.1", path); engine.addChild(host); Context c = embedded.createContext("/", path); c.setReloadable(false); Wrapper w = c.createWrapper(); w.addMapping("/*"); w.setServletClass(org.apache.catalina.servlets.WebdavServlet.class.getName()); w.addInitParameter("readonly", "false"); w.addInitParameter("listings", "true"); w.setLoadOnStartup(0); c.addChild(w); host.addChild(c); Connector connector = embedded.createConnector("127.0.0.1", port1, Http11NioProtocol.class.getName()); connector.setContainer(host); embedded.addEngine(engine); embedded.addConnector(connector); embedded.start(); }
@Override public void construct() { tomcat = new Tomcat(); Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setURIEncoding("UTF-8"); connector.setPort(5000); tomcat.getService().addConnector(connector); tomcat.setConnector(connector); try { Context ctx; if (new File(Configuration.WEBROOT_PATH).exists()) { L.i("Static web client found."); ctx = tomcat.addContext("", Configuration.WEBROOT_PATH); ctx.addWelcomeFile("index.html"); Wrapper wrapper = tomcat.addServlet(ctx, "DefaultServlet", new DefaultServlet()); wrapper.setAsyncSupported(true); wrapper.addInitParameter("listings", "false"); wrapper.addMapping("/"); wrapper.setLoadOnStartup(1); } else { L.w("No static web client found, web interface will not be available."); ctx = tomcat.addContext("/", "/tmp"); } configureMimeMappings(ctx); addSessionFilter(ctx); addCharacterEncodingFilter(ctx); Wrapper wrapper = tomcat.addServlet(ctx, "JerseyServlet", new ServletContainer()); wrapper.setAsyncSupported(true); wrapper.addInitParameter("javax.ws.rs.Application", JerseyApplication.class.getName()); wrapper.addMapping("/api/*"); wrapper.setLoadOnStartup(1); tomcat.start(); } catch (Exception e) { L.e("Failed to start RestApiModule.", e); } }