📄 catalinacontainer.java
字号:
al.setResolveHosts(alp4); } boolean alp5 = ContainerConfig.getPropertyValue(engineConfig, "access-log-rotate", false); if (al != null) { al.setRotatable(alp5); } if (al != null) { engine.addValve(al); } embedded.addEngine(engine); return engine; } protected Host createHost(Engine engine, String hostName) throws ContainerException { if (embedded == null) { throw new ContainerException("Cannot create Host without Embedded instance!"); } Host host = embedded.createHost(hostName, CATALINA_HOSTS_HOME); host.setDeployOnStartup(true); host.setAutoDeploy(true); host.setRealm(engine.getRealm()); engine.addChild(host); hosts.put(engine.getName() + hostName, host); return host; } protected Cluster createCluster(ContainerConfig.Container.Property clusterProps, Host host) throws ContainerException { String defaultValveFilter = ".*.gif;.*.js;.*.jpg;.*.htm;.*.html;.*.txt;"; ReplicationValve clusterValve = new ReplicationValve(); clusterValve.setFilter(ContainerConfig.getPropertyValue(clusterProps, "rep-valve-filter", defaultValveFilter)); String mcb = ContainerConfig.getPropertyValue(clusterProps, "mcast-bind-addr", null); String mca = ContainerConfig.getPropertyValue(clusterProps, "mcast-addr", null); int mcp = ContainerConfig.getPropertyValue(clusterProps, "mcast-port", -1); int mcd = ContainerConfig.getPropertyValue(clusterProps, "mcast-freq", 500); int mcf = ContainerConfig.getPropertyValue(clusterProps, "mcast-drop-time", 3000); if (mca == null || mcp == -1) { throw new ContainerException("Cluster configuration requires mcast-addr and mcast-port properties"); } McastService mcast = new McastService(); if (mcb != null) { mcast.setMcastBindAddress(mcb); } mcast.setMcastAddr(mca); mcast.setMcastPort(mcp); mcast.setMcastDropTime(mcd); mcast.setMcastFrequency(mcf); String tla = ContainerConfig.getPropertyValue(clusterProps, "tcp-listen-host", "auto"); int tlp = ContainerConfig.getPropertyValue(clusterProps, "tcp-listen-port", 4001); int tlt = ContainerConfig.getPropertyValue(clusterProps, "tcp-sector-timeout", 100); int tlc = ContainerConfig.getPropertyValue(clusterProps, "tcp-thread-count", 6); //String tls = getPropertyValue(clusterProps, "", ""); if (tlp == -1) { throw new ContainerException("Cluster configuration requires tcp-listen-port property"); } ReplicationListener listener = new ReplicationListener(); listener.setTcpListenAddress(tla); listener.setTcpListenPort(tlp); listener.setTcpSelectorTimeout(tlt); listener.setTcpThreadCount(tlc); //listener.setIsSenderSynchronized(false); ReplicationTransmitter trans = new ReplicationTransmitter(); trans.setReplicationMode(ContainerConfig.getPropertyValue(clusterProps, "replication-mode", "pooled")); String mgrClassName = ContainerConfig.getPropertyValue(clusterProps, "manager-class", "org.apache.catalina.cluster.session.DeltaManager"); //int debug = ContainerConfig.getPropertyValue(clusterProps, "debug", 0); boolean expireSession = ContainerConfig.getPropertyValue(clusterProps, "expire-session", false); boolean useDirty = ContainerConfig.getPropertyValue(clusterProps, "use-dirty", true); SimpleTcpCluster cluster = new SimpleTcpCluster(); cluster.setClusterName(clusterProps.name); cluster.setManagerClassName(mgrClassName); //cluster.setDebug(debug); cluster.setExpireSessionsOnShutdown(expireSession); cluster.setUseDirtyFlag(useDirty); cluster.setClusterReceiver(listener); cluster.setClusterSender(trans); cluster.setMembershipService(mcast); cluster.addValve(clusterValve); cluster.setPrintToScreen(true); // set the cluster to the host host.setCluster(cluster); Debug.logInfo("Catalina Cluster [" + cluster.getClusterName() + "] configured for host - " + host.getName(), module); return cluster; } protected Connector createConnector(ContainerConfig.Container.Property connectorProp) throws ContainerException { if (embedded == null) { throw new ContainerException("Cannot create Connector without Embedded instance!"); } // need some standard properties String protocol = ContainerConfig.getPropertyValue(connectorProp, "protocol", "HTTP/1.1"); String address = ContainerConfig.getPropertyValue(connectorProp, "address", "0.0.0.0"); int port = ContainerConfig.getPropertyValue(connectorProp, "port", 0); boolean secure = ContainerConfig.getPropertyValue(connectorProp, "secure", false); if (protocol.toLowerCase().startsWith("ajp")) { protocol = "ajp"; } else if ("memory".equals(protocol.toLowerCase())) { protocol = "memory"; } else if (secure) { protocol = "https"; } else { protocol = "http"; } Connector connector = null; if (connectorProp.properties != null && connectorProp.properties.size() > 0) { connector = embedded.createConnector(address, port, protocol); try { Iterator i = connectorProp.properties.values().iterator(); while (i.hasNext()) { ContainerConfig.Container.Property prop = (ContainerConfig.Container.Property) i.next(); connector.setProperty(prop.name, prop.value); //connector.setAttribute(prop.name, prop.value); } embedded.addConnector(connector); } catch (Exception e) { throw new ContainerException(e); } } return connector; } protected Context createContext(ComponentConfig.WebappInfo appInfo) throws ContainerException { // webapp settings Map initParameters = appInfo.getInitParameters(); List virtualHosts = appInfo.getVirtualHosts(); Engine engine = (Engine) engines.get(appInfo.server); if (engine == null) { Debug.logWarning("Server with name [" + appInfo.server + "] not found; not mounting [" + appInfo.name + "]", module); return null; } // set the root location (make sure we set the paths correctly) String location = appInfo.componentConfig.getRootLocation() + appInfo.location; location = location.replace('\\', '/'); if (location.endsWith("/")) { location = location.substring(0, location.length() - 1); } // get the mount point String mount = appInfo.mountPoint; if (mount.endsWith("/*")) { mount = mount.substring(0, mount.length() - 2); } // configure persistent sessions Manager sessionMgr = new StandardManager(); // create the web application context StandardContext context = (StandardContext) embedded.createContext(mount, location); context.setJ2EEApplication(J2EE_APP); context.setJ2EEServer(J2EE_SERVER); context.setLoader(embedded.createLoader(ClassLoaderContainer.getClassLoader())); context.setDisplayName(appInfo.name); context.setDocBase(location); context.setAllowLinking(true); context.setReloadable(contextReloadable); context.setDistributable(distribute); context.setCrossContext(crossContext); context.setManager(sessionMgr); context.getServletContext().setAttribute("_serverId", appInfo.server); // create the Default Servlet instance to mount StandardWrapper defaultServlet = new StandardWrapper(); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.setServletName("default"); defaultServlet.setLoadOnStartup(1); defaultServlet.addInitParameter("debug", "0"); defaultServlet.addInitParameter("listing", "true"); defaultServlet.addMapping("/"); context.addChild(defaultServlet); context.addServletMapping("/", "default"); // create the Jasper Servlet instance to mount StandardWrapper jspServlet = new StandardWrapper(); jspServlet.setServletClass("org.apache.jasper.servlet.JspServlet"); jspServlet.setServletName("jsp"); jspServlet.setLoadOnStartup(1); jspServlet.addInitParameter("fork", "false"); jspServlet.addInitParameter("xpoweredBy", "true"); jspServlet.addMapping("*.jsp"); jspServlet.addMapping("*.jspx"); context.addChild(jspServlet); context.addServletMapping("*.jsp", "jsp"); // default mime-type mappings configureMimeTypes(context); // set the init parameters Iterator ip = initParameters.keySet().iterator(); while (ip.hasNext()) { String paramName = (String) ip.next(); context.addParameter(paramName, (String) initParameters.get(paramName)); } if (UtilValidate.isEmpty(virtualHosts)) { Host host = (Host) hosts.get(engine.getName() + "._DEFAULT"); context.setRealm(host.getRealm()); host.addChild(context); context.getMapper().setDefaultHostName(host.getName()); } else { // assume that the first virtual-host will be the default; additional virtual-hosts will be aliases Iterator vhi = virtualHosts.iterator(); String hostName = (String) vhi.next(); boolean newHost = false; Host host = (Host) hosts.get(engine.getName() + "." + hostName); if (host == null) { host = createHost(engine, hostName); newHost = true; } while (vhi.hasNext()) { host.addAlias((String) vhi.next()); } context.setRealm(host.getRealm()); host.addChild(context); context.getMapper().setDefaultHostName(host.getName()); if (newHost) { hosts.put(engine.getName() + "." + hostName, host); } } return context; } protected void loadComponents() throws ContainerException { if (embedded == null) { throw new ContainerException("Cannot load web applications without Embedded instance!"); } // load the applications Collection componentConfigs = ComponentConfig.getAllComponents(); if (componentConfigs != null) { Iterator components = componentConfigs.iterator(); while (components.hasNext()) { ComponentConfig component = (ComponentConfig) components.next(); Iterator appInfos = component.getWebappInfos().iterator(); while (appInfos.hasNext()) { ComponentConfig.WebappInfo appInfo = (ComponentConfig.WebappInfo) appInfos.next(); createContext(appInfo); } } } } public void stop() throws ContainerException { try { embedded.stop(); } catch (LifecycleException e) { // don't throw this; or it will kill the rest of the shutdown process Debug.logError(e, module); } } protected void configureMimeTypes(Context context) throws ContainerException { Map mimeTypes = CatalinaContainer.getMimeTypes(); if (mimeTypes != null && mimeTypes.size() > 0) { Iterator i = mimeTypes.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); context.addMimeMapping((String)entry.getKey(), (String)entry.getValue()); } } } protected static synchronized Map getMimeTypes() throws ContainerException { if (mimeTypes != null && mimeTypes.size() > 0) { return mimeTypes; } if (mimeTypes == null) mimeTypes = new HashMap(); URL xmlUrl = UtilURL.fromResource("mime-type.xml"); // read the document Document mimeTypeDoc = null; try { mimeTypeDoc = UtilXml.readXmlDocument(xmlUrl, true); } catch (SAXException e) { throw new ContainerException("Error reading the mime-type.xml config file: " + xmlUrl, e); } catch (ParserConfigurationException e) { throw new ContainerException("Error reading the mime-type.xml config file: " + xmlUrl, e); } catch (IOException e) { throw new ContainerException("Error reading the mime-type.xml config file: " + xmlUrl, e); } if (mimeTypeDoc == null) { Debug.logError("Null document returned for mime-type.xml", module); return null; } // root element Element root = mimeTypeDoc.getDocumentElement(); // mapppings Iterator elementIter = UtilXml.childElementList(root, "mime-mapping").iterator(); while (elementIter.hasNext()) { Element curElement = (Element) elementIter.next(); String extension = UtilXml.childElementValue(curElement, "extension"); String type = UtilXml.childElementValue(curElement, "mime-type"); mimeTypes.put(extension, type); } return mimeTypes; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -