webapp.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,683 行 · 第 1/5 页
JAVA
2,683 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.server.webapp;import com.caucho.amber.manager.AmberContainer;import com.caucho.config.ConfigException;import com.caucho.config.j2ee.PersistenceContextRefConfig;import com.caucho.config.SchemaBean;import com.caucho.config.types.*;import com.caucho.i18n.CharacterEncoding;import com.caucho.jsp.JspServlet;import com.caucho.jsp.cfg.JspConfig;import com.caucho.jsp.cfg.JspPropertyGroup;import com.caucho.jsp.cfg.JspTaglib;import com.caucho.jsp.el.JspApplicationContextImpl;import com.caucho.lifecycle.Lifecycle;import com.caucho.loader.Environment;import com.caucho.loader.EnvironmentBean;import com.caucho.loader.EnvironmentClassLoader;import com.caucho.loader.EnvironmentLocal;import com.caucho.make.AlwaysModified;import com.caucho.make.DependencyContainer;import com.caucho.management.server.HostMXBean;import com.caucho.naming.Jndi;import com.caucho.server.cache.AbstractCache;import com.caucho.server.cluster.Cluster;import com.caucho.server.cluster.Server;import com.caucho.server.deploy.DeployContainer;import com.caucho.server.deploy.DeployGenerator;import com.caucho.server.deploy.EnvironmentDeployInstance;import com.caucho.server.dispatch.*;import com.caucho.server.host.Host;import com.caucho.server.log.AbstractAccessLog;import com.caucho.server.log.AccessLog;import com.caucho.server.resin.Resin;import com.caucho.server.rewrite.RewriteDispatch;import com.caucho.server.security.*;import com.caucho.server.session.SessionManager;import com.caucho.server.util.CauchoSystem;//import com.caucho.soa.client.WebServiceClient;import com.caucho.transaction.TransactionManagerImpl;import com.caucho.util.Alarm;import com.caucho.util.L10N;import com.caucho.util.LruCache;import com.caucho.vfs.Dependency;import com.caucho.vfs.Encoding;import com.caucho.vfs.Path;import com.caucho.vfs.Vfs;import com.caucho.webbeans.el.WebBeansELResolver;import com.caucho.webbeans.manager.*;import com.caucho.webbeans.component.*;import com.caucho.java.WorkDir;import com.caucho.jsf.cfg.JsfPropertyGroup;import javax.annotation.PostConstruct;import javax.management.ObjectName;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.servlet.*;import javax.servlet.http.*;import javax.webbeans.*;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Locale;import java.util.logging.Level;import java.util.logging.Logger;/** * Resin's webApp implementation. */public class WebApp extends ServletContextImpl implements Dependency, EnvironmentBean, SchemaBean, DispatchBuilder, EnvironmentDeployInstance, java.io.Serializable{ private static final String DEFAULT_VERSION = "2.5"; private static final L10N L = new L10N(WebApp.class); private static final Logger log = Logger.getLogger(WebApp.class.getName()); private static final int JSP_NONE = 0; private static final int JSP_1 = 1; private static final int JSP_2 = 2; private static EnvironmentLocal<AbstractAccessLog> _accessLogLocal = new EnvironmentLocal<AbstractAccessLog>("caucho.server.access-log"); private static EnvironmentLocal<WebApp> _appLocal = new EnvironmentLocal<WebApp>("caucho.application"); private static ThreadLocal<ServletRequest> _requestThreadLocal = new ThreadLocal<ServletRequest>(); static String []_classLoaderHackPackages; private ClassLoader _parentClassLoader; // The environment class loader private EnvironmentClassLoader _classLoader; // The parent private WebAppContainer _parent; // web-app versioning private String _version; private WebApp _oldWebApp; private long _oldWebAppExpireTime; // The webApp entry private WebAppController _controller; // The webApp directory. private final Path _appDir; // The context path private String _contextPath = ""; // A description private String _description = ""; private String _servletVersion; private boolean _isDynamicDeploy; private boolean _isDisableCrossContext; // Any war-generators. private ArrayList<DeployGenerator> _appGenerators = new ArrayList<DeployGenerator>(); // Any web-app-default for children private ArrayList<WebAppConfig> _webAppDefaultList = new ArrayList<WebAppConfig>(); // The servlet manager private ServletManager _servletManager; // The servlet mapper private ServletMapper _servletMapper; // True the mapper should be strict private boolean _isStrictMapping; // True if the servlet init-param is allowed to use EL private boolean _servletAllowEL = false; // The filter manager private FilterManager _filterManager; // The filter mapper private FilterMapper _filterMapper; // The filter mapper private FilterMapper _loginFilterMapper; // The include filter mapper private FilterMapper _includeFilterMapper; // The forward filter mapper private FilterMapper _forwardFilterMapper; // The error filter mapper private FilterMapper _errorFilterMapper; // True if includes are allowed to wrap a filter (forbidden by servlet spec) private boolean _dispatchWrapsFilters; // Transaction manager private TransactionManagerImpl _tm; // The session manager private SessionManager _sessionManager; // True if the session manager is inherited private boolean _isInheritSession; private String _characterEncoding; // The cache private AbstractCache _cache; private LruCache<String,FilterChainEntry> _filterChainCache = new LruCache<String,FilterChainEntry>(256); private UrlMap<CacheMapping> _cacheMappingMap = new UrlMap<CacheMapping>(); private final Object _dispatcherCacheLock = new Object(); private LruCache<String,RequestDispatcherImpl> _dispatcherCache; // login configuration factory for lazy start private Login _loginFactory; private AbstractLogin _login; // Old login manager for compat private AbstractLogin _loginManager; // The security constraints private ConstraintManager _constraintManager; // True for SSL secure. private boolean _isSecure; // Error pages. private ErrorPageManager _errorPageManager; // Any configuration exception private Throwable _configException; // dispatch mapping private RewriteDispatch _requestRewriteDispatch; private RewriteDispatch _includeRewriteDispatch; private RewriteDispatch _forwardRewriteDispatch; private LruCache<String,String> _realPathCache = new LruCache<String,String>(1024); // real-path mapping private RewriteRealPath _rewriteRealPath; // mime mapping private HashMap<String,String> _mimeMapping = new HashMap<String,String>(); // locale mapping private HashMap<String,String> _localeMapping = new HashMap<String,String>(); // List of all the listeners. private ArrayList<Listener> _listeners = new ArrayList<Listener>(); // List of the ServletContextListeners from the configuration file private ArrayList<ServletContextListener> _webAppListeners = new ArrayList<ServletContextListener>(); // List of the ServletContextAttributeListeners from the configuration file private ArrayList<ServletContextAttributeListener> _attributeListeners = new ArrayList<ServletContextAttributeListener>(); // List of the ServletRequestListeners from the configuration file private ArrayList<ServletRequestListener> _requestListeners = new ArrayList<ServletRequestListener>(); private ServletRequestListener []_requestListenerArray = new ServletRequestListener[0]; // List of the ServletRequestAttributeListeners from the configuration file private ArrayList<ServletRequestAttributeListener> _requestAttributeListeners = new ArrayList<ServletRequestAttributeListener>(); private ServletRequestAttributeListener []_requestAttributeListenerArray = new ServletRequestAttributeListener[0]; private ArrayList<Validator> _resourceValidators = new ArrayList<Validator>(); private DependencyContainer _invocationDependency; private AbstractAccessLog _accessLog; private Path _tempDir; private boolean _cookieHttpOnly; // special private int _jspState; private JspPropertyGroup _jsp; private JsfPropertyGroup _jsf; private ArrayList<JspTaglib> _taglibList; private JspApplicationContextImpl _jspApplicationContext; private HashMap<String,Object> _extensions = new HashMap<String,Object>(); private MultipartForm _multipartForm; private ArrayList<String> _regexp; private boolean _isStatisticsEnabled; private long _shutdownWaitTime = 15000L; private long _activeWaitTime = 15000L; private long _idleTime = 2 * 3600 * 1000L; private final Object _countLock = new Object(); private final Lifecycle _lifecycle; private int _requestCount; private long _lastRequestTime = Alarm.getCurrentTime(); // // statistics // private long _status500CountTotal; private long _status500LastTime; /** * Creates the webApp with its environment loader. */ public WebApp(Path rootDirectory) { this(new WebAppController("/", "/", rootDirectory, null)); } /** * Creates the webApp with its environment loader. */ WebApp(WebAppController controller) { String contextPath = controller.getContextPath(); setContextPathId(contextPath); _controller = controller; _appDir = controller.getRootDirectory(); try { _classLoader = EnvironmentClassLoader.create(controller.getParentClassLoader(), "web-app:" + getURL()); // the JSP servlet needs to initialize the JspFactory JspServlet.initStatic(); _classLoader.addParentPriorityPackages(_classLoaderHackPackages); // _classLoader.setId("web-app:" + getURL()); _appLocal.set(this, _classLoader); setParent(controller.getContainer()); Vfs.setPwd(_appDir, _classLoader); WorkDir.setLocalWorkDir(_appDir.lookup("WEB-INF/work"), _classLoader); // map.put("app", _appVar); _servletManager = new ServletManager(); _servletMapper = new ServletMapper(); _servletMapper.setServletContext(this); _servletMapper.setServletManager(_servletManager); _filterManager = new FilterManager(); _filterMapper = new FilterMapper(); _filterMapper.setServletContext(this); _filterMapper.setFilterManager(_filterManager); _loginFilterMapper = new FilterMapper(); _loginFilterMapper.setServletContext(this); _loginFilterMapper.setFilterManager(_filterManager); _includeFilterMapper = new FilterMapper(); _includeFilterMapper.setServletContext(this); _includeFilterMapper.setFilterManager(_filterManager); _forwardFilterMapper = new FilterMapper(); _forwardFilterMapper.setServletContext(this); _forwardFilterMapper.setFilterManager(_filterManager); _errorFilterMapper = new FilterMapper(); _errorFilterMapper.setServletContext(this); _errorFilterMapper.setFilterManager(_filterManager); _constraintManager = new ConstraintManager(); _errorPageManager = new ErrorPageManager(this); if (getParent() != null) _errorPageManager.setParent(getParent().getErrorPageManager()); _invocationDependency = new DependencyContainer(); _invocationDependency.add(this); _jspApplicationContext = new JspApplicationContextImpl(this); // validation if (CauchoSystem.isTesting()) { } else if (_appDir.equals(CauchoSystem.getResinHome())) { throw new ConfigException(L.l("web-app root-directory can not be the same as resin.home\n{0}", _appDir)); } else if (_parent != null && _appDir.equals(_parent.getRootDirectory())) { throw new ConfigException(L.l("web-app root-directory can not be the same as the host root-directory\n{0}", _appDir)); } } catch (Throwable e) { setConfigException(e); } finally { _lifecycle = new Lifecycle(log, toString(), Level.INFO); } } /** * Sets the parent container. */ public void setParent(WebAppContainer parent) { _parent = parent; if (parent == null) return; } /** * Set true for a dynamically deployed server. */ public void setDynamicDeploy(boolean isDynamicDeploy) { _isDynamicDeploy = isDynamicDeploy; } /** * Set true for a dynamically deployed server. */ public boolean isDynamicDeploy() { return _isDynamicDeploy; } /** * Gets the parent container. */ public WebAppContainer getParent() { return _parent; } /** * Returns the local webApp. */ public static WebApp getLocal() { return getCurrent(); } /** * Returns the local webApp. */ public static WebApp getCurrent() { return _appLocal.get(); } /** * Gets the dispatch server. */ public DispatchServer getDispatchServer() { if (_parent != null) return _parent.getDispatchServer(); else return null; } /** * Gets the dispatch server. */ public Server getServer() { if (_parent != null && _parent.getDispatchServer() instanceof Server) return (Server) _parent.getDispatchServer(); else return null; } /** * The id is the context path. */ public void setId(String id) { } /** * The id is the context path. */ private void setContextPathId(String id) { if (! id.equals("") && ! id.startsWith("/")) id = "/" + id; if (id.endsWith("/")) id = id.substring(0, id.length() - 1); setContextPath(id); } /** * Gets the environment class loader. */ public ClassLoader getClassLoader() { return _classLoader; } /** * Sets the environment class loader. */ public void setEnvironmentClassLoader(EnvironmentClassLoader loader) { throw new IllegalStateException(); } /** * Gets the environment class loader. */ public EnvironmentClassLoader getEnvironmentClassLoader() { return _classLoader; } /** * Sets the redeploy-mode of the controller */ public void setRedeployMode(String mode) { if (_controller != null) _controller.setRedeployMode(mode); } /** * Returns the relax schema. */ public String getSchema() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?