⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catalinacontainer.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: CatalinaContainer.java 7208 2006-04-05 21:28:25Z jonesde $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.catalina.container;import java.io.File;import java.io.IOException;import java.net.URL;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.xml.parsers.ParserConfigurationException;import org.ofbiz.base.component.ComponentConfig;import org.ofbiz.base.container.ClassLoaderContainer;import org.ofbiz.base.container.Container;import org.ofbiz.base.container.ContainerConfig;import org.ofbiz.base.container.ContainerException;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilURL;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.entity.GenericDelegator;import org.apache.catalina.Cluster;import org.apache.catalina.Context;import org.apache.catalina.Engine;import org.apache.catalina.Host;import org.apache.catalina.LifecycleException;import org.apache.catalina.Manager;import org.apache.catalina.ServerFactory;import org.apache.catalina.cluster.mcast.McastService;import org.apache.catalina.cluster.tcp.ReplicationListener;import org.apache.catalina.cluster.tcp.ReplicationTransmitter;import org.apache.catalina.cluster.tcp.ReplicationValve;import org.apache.catalina.cluster.tcp.SimpleTcpCluster;import org.apache.catalina.connector.Connector;import org.apache.catalina.core.StandardContext;import org.apache.catalina.core.StandardEngine;import org.apache.catalina.core.StandardServer;import org.apache.catalina.core.StandardWrapper;import org.apache.catalina.realm.MemoryRealm;import org.apache.catalina.session.StandardManager;import org.apache.catalina.startup.Embedded;import org.apache.catalina.util.ServerInfo;import org.apache.catalina.valves.AccessLogValve;import org.apache.catalina.valves.RequestDumperValve;import org.apache.coyote.ProtocolHandler;import org.apache.coyote.http11.Http11Protocol;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.xml.sax.SAXException;/* * --- Access Log Pattern Information - From Tomcat 5 AccessLogValve.java * <p>Patterns for the logged message may include constant text or any of the * following replacement strings, for which the corresponding information * from the specified Response is substituted:</p> * <ul> * <li><b>%a</b> - Remote IP address * <li><b>%A</b> - Local IP address * <li><b>%b</b> - Bytes sent, excluding HTTP headers, or '-' if no bytes *     were sent * <li><b>%B</b> - Bytes sent, excluding HTTP headers * <li><b>%h</b> - Remote host name * <li><b>%H</b> - Request protocol * <li><b>%l</b> - Remote logical username from identd (always returns '-') * <li><b>%m</b> - Request method * <li><b>%p</b> - Local port * <li><b>%q</b> - Query string (prepended with a '?' if it exists, otherwise *     an empty string * <li><b>%r</b> - First line of the request * <li><b>%s</b> - HTTP status code of the response * <li><b>%S</b> - User session ID * <li><b>%t</b> - Date and time, in Common Log Format format * <li><b>%u</b> - Remote user that was authenticated * <li><b>%U</b> - Requested URL path * <li><b>%v</b> - Local server name * <li><b>%D</b> - Time taken to process the request, in millis * <li><b>%T</b> - Time taken to process the request, in seconds * </ul> * <p>In addition, the caller can specify one of the following aliases for * commonly utilized patterns:</p> * <ul> * <li><b>common</b> - <code>%h %l %u %t "%r" %s %b</code> * <li><b>combined</b> - *   <code>%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"</code> * </ul> * * <p> * There is also support to write information from the cookie, incoming * header, the Session or something else in the ServletRequest.<br/> * It is modeled after the apache syntax: * <ul> * <li><code>%{xxx}i</code> for incoming headers * <li><code>%{xxx}c</code> for a specific cookie * <li><code>%{xxx}r</code> xxx is an attribute in the ServletRequest * <li><code>%{xxx}s</code> xxx is an attribute in the HttpSession * </ul> * </p> *//** * CatalinaContainer -  Tomcat 5 * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 7208 $ * @since      3.1 */public class CatalinaContainer implements Container {    public static final String CATALINA_HOSTS_HOME = System.getProperty("ofbiz.home") + "/framework/catalina/hosts";    public static final String J2EE_SERVER = "OFBiz Container 3.1";    public static final String J2EE_APP = "OFBiz";    public static final String module = CatalinaContainer.class.getName();    protected static Map mimeTypes = new HashMap();    protected GenericDelegator delegator = null;    protected Embedded embedded = null;    protected Map clusterConfig = new HashMap();    protected Map engines = new HashMap();    protected Map hosts = new HashMap();    protected boolean contextReloadable = false;    protected boolean crossContext = false;    protected boolean distribute = false;    protected boolean enableDefaultMimeTypes = true;    /**     * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)     */    public void init(String[] args, String configFile) throws ContainerException {        // set catalina_home        System.setProperty("catalina.home", System.getProperty("ofbiz.home") + "/framework/catalina");        // get the container config        ContainerConfig.Container cc = ContainerConfig.getContainer("catalina-container", configFile);        if (cc == null) {            throw new ContainerException("No catalina-container configuration found in container config!");        }        // embedded properties        boolean useNaming = ContainerConfig.getPropertyValue(cc, "use-naming", false);        //int debug = ContainerConfig.getPropertyValue(cc, "debug", 0);        // grab some global context settings        this.delegator = GenericDelegator.getGenericDelegator(ContainerConfig.getPropertyValue(cc, "delegator-name", "default"));        this.contextReloadable = ContainerConfig.getPropertyValue(cc, "apps-context-reloadable", false);        this.crossContext = ContainerConfig.getPropertyValue(cc, "apps-cross-context", true);        this.distribute = ContainerConfig.getPropertyValue(cc, "apps-distributable", true);        // configure JNDI in the StandardServer        StandardServer server = (StandardServer) ServerFactory.getServer();        try {            server.setGlobalNamingContext(new InitialContext());        } catch (NamingException e) {            throw new ContainerException(e);        }        // create the instance of Embedded        embedded = new Embedded();        embedded.setUseNaming(useNaming);        // create the engines        List engineProps = cc.getPropertiesWithValue("engine");        if (engineProps == null && engineProps.size() == 0) {            throw new ContainerException("Cannot load CatalinaContainer; no engines defined!");        }        Iterator ei = engineProps.iterator();        while (ei.hasNext()) {            ContainerConfig.Container.Property engineProp = (ContainerConfig.Container.Property) ei.next();            createEngine(engineProp);        }        // load the web applications        loadComponents();        // create the connectors        List connectorProps = cc.getPropertiesWithValue("connector");        if (connectorProps == null && connectorProps.size() == 0) {            throw new ContainerException("Cannot load CatalinaContainer; no connectors defined!");        }        Iterator ci = connectorProps.iterator();        while (ci.hasNext()) {            ContainerConfig.Container.Property connectorProp = (ContainerConfig.Container.Property) ci.next();            createConnector(connectorProp);        }        try {            embedded.initialize();        } catch (LifecycleException e) {            throw new ContainerException(e);        }    }    public boolean start() throws ContainerException {        // Start the embedded server        try {            embedded.start();        } catch (LifecycleException e) {            throw new ContainerException(e);        }        Connector[] cons = embedded.findConnectors();        for (int i = 0; i < cons.length; i++) {            ProtocolHandler ph = cons[i].getProtocolHandler();            if (ph instanceof Http11Protocol) {                Http11Protocol hph = (Http11Protocol) ph;                Debug.logInfo("Connector " + hph.getProtocol() + " @ " + hph.getPort() + " - " +                    (hph.getSecure() ? "secure" : "not-secure") + " [" + cons[i].getProtocolHandlerClassName() + "] started.", module);            } else {                Debug.logInfo("Connector " + cons[i].getProtocol() + " @ " + cons[i].getPort() + " - " +                    (cons[i].getSecure() ? "secure" : "not-secure") + " [" + cons[i].getProtocolHandlerClassName() + "] started.", module);            }        }        Debug.logInfo("Started " + ServerInfo.getServerInfo(), module);        return true;    }    protected Engine createEngine(ContainerConfig.Container.Property engineConfig) throws ContainerException {        if (embedded == null) {            throw new ContainerException("Cannot create Engine without Embedded instance!");        }        ContainerConfig.Container.Property defaultHostProp = engineConfig.getProperty("default-host");        if (defaultHostProp == null) {            throw new ContainerException("default-host element of server property is required for catalina!");        }        String engineName = engineConfig.name;        String hostName = defaultHostProp.value;        StandardEngine engine = (StandardEngine) embedded.createEngine();        engine.setName(engineName);        engine.setDefaultHost(hostName);        // set the JVM Route property (JK/JK2)        String jvmRoute = ContainerConfig.getPropertyValue(engineConfig, "jvm-route", null);        if (jvmRoute != null) {            engine.setJvmRoute(jvmRoute);        }        // create the default realm -- TODO: make this configurable        String dbConfigPath = "config/catalina-users.xml";        MemoryRealm realm = new MemoryRealm();        realm.setPathname(dbConfigPath);        engine.setRealm(realm);        // cache the engine        engines.put(engine.getName(), engine);        // create a default virtual host; others will be created as needed        Host host = createHost(engine, hostName);        hosts.put(engineName + "._DEFAULT", host);        // configure clustering        List clusterProps = engineConfig.getPropertiesWithValue("cluster");        if (clusterProps != null && clusterProps.size() > 1) {            throw new ContainerException("Only one cluster configuration allowed per engine");        }        if (clusterProps != null && clusterProps.size() > 0) {            ContainerConfig.Container.Property clusterProp = (ContainerConfig.Container.Property) clusterProps.get(0);            createCluster(clusterProp, host);            clusterConfig.put(engineName, clusterProp);        }        // request dumper valve        boolean enableRequestDump = ContainerConfig.getPropertyValue(engineConfig, "enable-request-dump", false);        if (enableRequestDump) {            RequestDumperValve rdv = new RequestDumperValve();            engine.addValve(rdv);        }        // configure the access log valve        String logDir = ContainerConfig.getPropertyValue(engineConfig, "access-log-dir", null);        AccessLogValve al = null;        if (logDir != null) {            al = new AccessLogValve();            if (!logDir.startsWith("/")) {                logDir = System.getProperty("ofbiz.home") + "/" + logDir;            }            File logFile = new File(logDir);            if (!logFile.isDirectory()) {                throw new ContainerException("Log directory [" + logDir + "] is not available; make sure the directory is created");            }            al.setDirectory(logFile.getAbsolutePath());        }        String alp2 = ContainerConfig.getPropertyValue(engineConfig, "access-log-pattern", null);        if (al != null && !UtilValidate.isEmpty(alp2)) {            al.setPattern(alp2);        }        String alp3 = ContainerConfig.getPropertyValue(engineConfig, "access-log-prefix", null);        if (al != null && !UtilValidate.isEmpty(alp3)) {            al.setPrefix(alp3);        }        boolean alp4 = ContainerConfig.getPropertyValue(engineConfig, "access-log-resolve", true);        if (al != null) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -