rootContext.setLoader(loader); rootContext.setReloadable(true); rootContext.setIgnoreAnnotations(true); localHost.addChild(rootContext); localHost.setDeployOnStartup(true); engine.setName("localEngine"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); engine.setJvmRoute(jvmRoute); engine.setService(new StandardService());
private Context findContext() { for (Container child : this.tomcat.getHost().findChildren()) { if (child instanceof Context) { return (Context) child; } } throw new IllegalStateException("The host does not contain a Context"); }
void start() { // '%2F' (slash /) and '%5C' (backslash \) are permitted as path delimiters in URLs System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true"); tomcat = new Tomcat(); // Initialize directories String basedir = tomcatBasedir().getAbsolutePath(); tomcat.setBaseDir(basedir); tomcat.getHost().setAppBase(basedir); tomcat.getHost().setAutoDeploy(false); tomcat.getHost().setCreateDirs(false); tomcat.getHost().setDeployOnStartup(true); new TomcatAccessLog().configure(tomcat, props); TomcatConnectors.configure(tomcat, props); webappContext = new TomcatContexts().configure(tomcat, props); try { tomcat.start(); new TomcatStartupLogs(Loggers.get(getClass())).log(tomcat); } catch (LifecycleException e) { Loggers.get(EmbeddedTomcat.class).error("Fail to start web server", e); Throwables.propagate(e); } }
rootContext.setLoader(loader); rootContext.setReloadable(true); localHost.addChild(rootContext); engine.setName("localEngine"); engine.addChild(localHost); engine.setDefaultHost(localHost.getName()); container.addEngine(engine);
/** * Render a list of the currently active Contexts in our virtual host. * * @param writer Writer to render to * @param smClient StringManager for the client's locale */ protected void list(PrintWriter writer, StringManager smClient) { if (debug >= 1) { log(sm.getString("hostManagerServlet.list", engine.getName())); } writer.println(smClient.getString("hostManagerServlet.listed", engine.getName())); Container[] hosts = engine.findChildren(); for (int i = 0; i < hosts.length; i++) { Host host = (Host) hosts[i]; String name = host.getName(); String[] aliases = host.findAliases(); writer.println(smClient.getString("hostManagerServlet.listitem", name, StringUtils.join(aliases))); } }
Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", Escape.htmlElementContent(cn.getDisplayName()))); return; if (context.getName().equals(this.context.getName())) { writer.println(smClient.getString("managerServlet.noSelf")); return; context.reload(); writer.println(smClient.getString("managerServlet.reloaded", cn.getDisplayName())); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t); writer.println(smClient.getString("managerServlet.exception",
private void writeDeployResult(PrintWriter writer, StringManager smClient, String name, String displayPath) { Context deployed = (Context) host.findChild(name); if (deployed != null && deployed.getConfigured() && deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployed", displayPath)); } else if (deployed!=null && !deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployedButNotStarted", displayPath)); } else { // Something failed writer.println(smClient.getString( "managerServlet.deployFailed", displayPath)); } }
Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", Escape.htmlElementContent(displayPath))); return; if (context.getName().equals(this.context.getName())) { writer.println(smClient.getString("managerServlet.noSelf")); return; context.stop(); writer.println(smClient.getString( "managerServlet.stopped", displayPath)); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log("ManagerServlet.stop[" + displayPath + "]", t); writer.println(smClient.getString("managerServlet.exception",
Context context = (Context) host.findChild(cn.getName()); if (context == null) { writer.println(smClient.getString("managerServlet.noContext", Escape.htmlElementContent(displayPath))); return; context.start(); if (context.getState().isAvailable()) writer.println(smClient.getString("managerServlet.started", displayPath)); else writer.println(smClient.getString("managerServlet.startFailed", displayPath)); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); getServletContext().log(sm.getString("managerServlet.startFailed", displayPath), t);
/** * Register context. */ private void registerContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } Host host = (Host)context.getParent(); WebResourceRoot resources = context.getResources(); String[] welcomeFiles = context.findWelcomeFiles(); mapper.addContextVersion(host.getName(), host, contextPath, context.getWebappVersion(), context, welcomeFiles, resources); for (Container container : context.findChildren()) { registerWrapper((Wrapper) container); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerContext", contextPath, service)); } }
/** * Register host. */ private void registerHost(Host host) { String[] aliases = host.findAliases(); mapper.addHost(host.getName(), aliases, host); for (Container container : host.findChildren()) { registerContext((Context) container); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerHost", host.getName(), domain, connector)); } }
/** * Unregister host. */ private void unregisterHost(Host host) { String hostname = host.getName(); mapper.removeHost(hostname); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterHost", hostname, domain, service)); } }
private void reload(DeployedApplication app) { if(log.isInfoEnabled()) log.info(sm.getString("hostConfig.reload", app.name)); Context context = (Context) host.findChild(app.name); if (context.getState().isAvailable()) { // Reload catches and logs exceptions context.reload(); } else { // If the context was not started (for example an error // in web.xml) we'll still get to try to start try { context.start(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); } } }
private void undeploy(DeployedApplication app) { if (log.isInfoEnabled()) log.info(sm.getString("hostConfig.undeploy", app.name)); Container context = host.findChild(app.name); try { host.removeChild(context); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.warn(sm.getString ("hostConfig.context.remove", app.name), t); } deployed.remove(app.name); }
/** * Deploy a web application for the specified user if they have such an * application in the defined directory within their home directory. * * @param user Username owning the application to be deployed * @param home Home directory of this user */ private void deploy(String user, String home) { // Does this user have a web application to be deployed? String contextPath = "/~" + user; if (host.findChild(contextPath) != null) return; File app = new File(home, directoryName); if (!app.exists() || !app.isDirectory()) return; host.getLogger().info(sm.getString("userConfig.deploy", user)); // Deploy the web application for this user try { Class<?> clazz = Class.forName(contextClass); Context context = (Context) clazz.getConstructor().newInstance(); context.setPath(contextPath); context.setDocBase(app.toString()); clazz = Class.forName(configClass); LifecycleListener listener = (LifecycleListener) clazz.getConstructor().newInstance(); context.addLifecycleListener(listener); host.addChild(context); } catch (Exception e) { host.getLogger().error(sm.getString("userConfig.error", user), e); } }
private void findDefaultHost() { Engine engine = service.getContainer(); String defaultHost = engine.getDefaultHost(); boolean found = false; if (defaultHost != null && defaultHost.length() > 0) { Container[] containers = engine.findChildren(); for (Container container : containers) { Host host = (Host) container; if (defaultHost.equalsIgnoreCase(host.getName())) { found = true; break; } String[] aliases = host.findAliases(); for (String alias : aliases) { if (defaultHost.equalsIgnoreCase(alias)) { found = true; break; } } } } if (found) { mapper.setDefaultHostName(defaultHost); } else { log.error(sm.getString("mapperListener.unknownDefaultHost", defaultHost, service)); } }
@Override public void setWrapper(Wrapper wrapper) { Valve valve = createValve(); if (wrapper != null) { host = (Host) wrapper.getParent().getParent(); Engine engine = (Engine) host.getParent(); Service service = engine.getService(); connectors = service.findConnectors(); try { deployerOName = new ObjectName(host.getParent().getName() + ":type=Deployer,host=" + host.getName()); } catch (MalformedObjectNameException e) { logger.trace("", e); } host.getPipeline().addValve(valve); mbeanServer = ManagementFactory.getPlatformMBeanServer(); } else if (host != null) { host.getPipeline().removeValve(valve); } }
listener.fireOnError(errorEvent); } catch (Throwable t2) { ExceptionUtils.handleThrowable(t2); log.warn(sm.getString("asyncContextImpl.onErrorError", listener.getClass().getName()), t2); Host host = (Host) context.getParent(); Valve stdHostValve = host.getPipeline().getBasic(); if (stdHostValve instanceof StandardHostValve) { ((StandardHostValve) stdHostValve).throwable(request,
protected Session getSessionForNameAndId(ContextName cn, String id, StringManager smClient) throws IOException { if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) { String path = null; if (cn != null) { path = cn.getPath(); } throw new IllegalArgumentException(smClient.getString( "managerServlet.invalidPath", RequestUtil.filter(path))); } Context ctxt = (Context) host.findChild(cn.getName()); if (null == ctxt) { throw new IllegalArgumentException(smClient.getString( "managerServlet.noContext", RequestUtil.filter(cn.getDisplayName()))); } Session session = ctxt.getManager().findSession(id); return session; }