/** * Creates a single webapp configuration to be run in Tomcat. * * @param contextName the context name without leading slash, for example, "openmrs" * @param port the port at which to run tomcat. */ public TomcatManager(String contextName, int port) { // create server container = new Embedded(); container.setCatalinaHome("tomcat"); // create context Context rootContext = container.createContext("/" + contextName, contextName); rootContext.setReloadable(true); // create host Host localHost = container.createHost("localhost", "webapps"); localHost.addChild(rootContext); // create engine Engine engine = container.createEngine(); engine.setName("Catalina"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); container.addEngine(engine); // create http connector Connector httpConnector = container.createConnector((InetAddress) null, port, false); container.addConnector(httpConnector); }
private void initServer() throws Exception { // point catalina at the provided home directory server = new Embedded(); server.setCatalinaHome(catalinaHome.getAbsolutePath()); Engine engine = server.createEngine(); engine.setName("embedded"); server.addEngine(engine); host = server.createHost("localhost", new File(catalinaHome, "webapps").getAbsolutePath()); engine.addChild(host); engine.setDefaultHost(host.getName()); // bind to an available port httpConnector = new EmbeddedConnector(); server.addConnector(httpConnector); // disable session persistence on restart sessions = new MemoryStore(); sessionManager = new PersistentManager(); sessionManager.setDistributable(false); sessionManager.setSaveOnRestart(false); sessionManager.setStore(sessions); Context root = server.createContext("", new File(catalinaHome, "conf").getAbsolutePath()); root.setManager(sessionManager); host.addChild(root); }
private void addInstanceIdToEngineName() { int instanceId = containerCounter.incrementAndGet(); if (instanceId > 0) { Engine engine = this.tomcat.getEngine(); engine.setName(engine.getName() + "-" + instanceId); } }
public static void setupContainer(String warName, String jvmRoute, Manager mgr) { Engine engine = new MockEngine(); engine.setName(JVM_ROUTE_CACHE_NAME); engine.setJvmRoute(jvmRoute); Host host = new MockHost(); host.setName("localhost"); engine.addChild(host); StandardContext context = new StandardContext(); context.setName(warName); context.setDomain(jvmRoute); host.addChild(context); context.setManager(mgr); }
/** 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; }
public EmbeddedTomcat(String contextPath, int port, String jvmRoute) throws MalformedURLException { this.contextPath = contextPath; this.port = port; // create server container = new Embedded(); container.setCatalinaHome(catalinaHome); // Not really necessasry, but let's still do it... container.setRealm(new MemoryRealm()); // create webapp loader WebappLoader loader = new WebappLoader(this.getClass().getClassLoader()); if (classesDir != null) { loader.addRepository(new File(classesDir).toURI().toURL().toString()); } rootContext = container.createContext("", webappDir); rootContext.setLoader(loader); rootContext.setReloadable(true); // Otherwise we get NPE when instantiating servlets rootContext.setIgnoreAnnotations(true); // create host Host localHost = container.createHost("127.0.0.1", new File("").getAbsolutePath()); localHost.addChild(rootContext); localHost.setDeployOnStartup(true); // create engine engine = container.createEngine(); engine.setName("localEngine"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); engine.setJvmRoute(jvmRoute); engine.setService(new StandardService()); container.addEngine(engine); // create http connector Connector httpConnector = container.createConnector((InetAddress) null, port, false); container.addConnector(httpConnector); container.setAwait(true); // Create the JVMRoute valve for session failover ValveBase valve = new JvmRouteBinderValve(); ((StandardEngine) engine).addValve(valve); }