📄 webappcontext.java
字号:
{ if (_resourceAliases == null) return null; return _resourceAliases; } /* ------------------------------------------------------------ */ public void setResourceAliases(Map map) { _resourceAliases = map; } /* ------------------------------------------------------------ */ public String getResourceAlias(String alias) { if (_resourceAliases == null) return null; return (String)_resourceAliases.get(alias); } /* ------------------------------------------------------------ */ public String removeResourceAlias(String alias) { if (_resourceAliases == null) return null; return (String)_resourceAliases.remove(alias); } /* ------------------------------------------------------------ */ /* (non-Javadoc) * @see org.mortbay.jetty.handler.ContextHandler#setClassLoader(java.lang.ClassLoader) */ public void setClassLoader(ClassLoader classLoader) { super.setClassLoader(classLoader); if (classLoader!=null && classLoader instanceof WebAppClassLoader) ((WebAppClassLoader)classLoader).setName(getDisplayName()); } /* ------------------------------------------------------------ */ public Resource getResource(String uriInContext) throws MalformedURLException { IOException ioe= null; Resource resource= null; int loop=0; while (uriInContext!=null && loop++<100) { try { resource= super.getResource(uriInContext); if (resource != null && resource.exists()) return resource; uriInContext = getResourceAlias(uriInContext); } catch (IOException e) { Log.ignore(e); if (ioe==null) ioe= e; } } if (ioe != null && ioe instanceof MalformedURLException) throw (MalformedURLException)ioe; return resource; } /* ------------------------------------------------------------ */ /** * @see org.mortbay.jetty.handler.ContextHandler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) */ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { if (_unavailable) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else super.handle(target, request, response, dispatch); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.thread.AbstractLifeCycle#doStart() */ protected void doStart() throws Exception { try { // Setup configurations loadConfigurations(); for (int i=0;i<_configurations.length;i++) _configurations[i].setWebAppContext(this); // Configure classloader _ownClassLoader=false; if (getClassLoader()==null) { WebAppClassLoader classLoader = new WebAppClassLoader(this); setClassLoader(classLoader); _ownClassLoader=true; } if (Log.isDebugEnabled()) { ClassLoader loader = getClassLoader(); Log.debug("Thread Context class loader is: " + loader); loader=loader.getParent(); while(loader!=null) { Log.debug("Parent class loader is: " + loader); loader=loader.getParent(); } } for (int i=0;i<_configurations.length;i++) _configurations[i].configureClassLoader(); getTempDirectory(); if (_tmpDir!=null && !_isExistingTmpDir && !isTempWorkDirectory()) { File sentinel = new File(_tmpDir, ".active"); if(!sentinel.exists()) sentinel.mkdir(); } super.doStart(); if (isLogUrlOnStart()) dumpUrl(); } catch (Exception e) { //start up of the webapp context failed, make sure it is not started Log.warn("Failed startup of context "+this, e); _unavailableException=e; _unavailable = true; } } /* ------------------------------------------------------------ */ /* * Dumps the current web app name and URL to the log */ public void dumpUrl() { Connector[] connectors = getServer().getConnectors(); for (int i=0;i<connectors.length;i++) { String connectorName = connectors[i].getName(); String displayName = getDisplayName(); if (displayName == null) displayName = "WebApp@"+connectors.hashCode(); Log.info(displayName + " at http://" + connectorName + getContextPath()); } } /* ------------------------------------------------------------ */ /* * @see org.mortbay.thread.AbstractLifeCycle#doStop() */ protected void doStop() throws Exception { super.doStop(); try { // Configure classloader for (int i=_configurations.length;i-->0;) _configurations[i].deconfigureWebApp(); _configurations=null; // restore security handler if (_securityHandler.getHandler()==null) { _sessionHandler.setHandler(_securityHandler); _securityHandler.setHandler(_servletHandler); } // delete temp directory if we had to create it or if it isn't called work if (_tmpDir!=null && !_isExistingTmpDir && !isTempWorkDirectory()) //_tmpDir!=null && !"work".equals(_tmpDir.getName())) { IO.delete(_tmpDir); _tmpDir=null; } } finally { if (_ownClassLoader) setClassLoader(null); _unavailable = false; _unavailableException=null; } } /* ------------------------------------------------------------ */ /** * @return Returns the configurations. */ public String[] getConfigurationClasses() { return _configurationClasses; } /* ------------------------------------------------------------ */ /** * @return Returns the configurations. */ public Configuration[] getConfigurations() { return _configurations; } /* ------------------------------------------------------------ */ /** * The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml * @return Returns the defaultsDescriptor. */ public String getDefaultsDescriptor() { return _defaultsDescriptor; } /* ------------------------------------------------------------ */ /** * The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml * @return Returns the Override Descriptor. */ public String getOverrideDescriptor() { return _overrideDescriptor; } /* ------------------------------------------------------------ */ /** * @return Returns the permissions. */ public PermissionCollection getPermissions() { return _permissions; } /* ------------------------------------------------------------ */ /** * @return Returns the serverClasses. */ public String[] getServerClasses() { return _serverClasses; } /* ------------------------------------------------------------ */ /** * @return Returns the systemClasses. */ public String[] getSystemClasses() { return _systemClasses; } /* ------------------------------------------------------------ */ /** * Get a temporary directory in which to unpack the war etc etc. * The algorithm for determining this is to check these alternatives * in the order shown: * * <p>A. Try to use an explicit directory specifically for this webapp:</p> * <ol> * <li> * Iff an explicit directory is set for this webapp, use it. Do NOT set * delete on exit. * </li> * <li> * Iff javax.servlet.context.tempdir context attribute is set for * this webapp && exists && writeable, then use it. Do NOT set delete on exit. * </li> * </ol> * * <p>B. Create a directory based on global settings. The new directory * will be called "Jetty_"+host+"_"+port+"__"+context+"_"+virtualhost * Work out where to create this directory: * <ol> * <li> * Iff $(jetty.home)/work exists create the directory there. Do NOT * set delete on exit. Do NOT delete contents if dir already exists. * </li> * <li> * Iff WEB-INF/work exists create the directory there. Do NOT set * delete on exit. Do NOT delete contents if dir already exists. * </li> * <li> * Else create dir in $(java.io.tmpdir). Set delete on exit. Delete * contents if dir already exists. * </li> * </ol> * * @return */ public File getTempDirectory() { if (_tmpDir!=null && _tmpDir.isDirectory() && _tmpDir.canWrite()) return _tmpDir; // Initialize temporary directory // // I'm afraid that this is very much black magic. // but if you can think of better.... Object t = getAttribute(ServletHandler.__J_S_CONTEXT_TEMPDIR); if (t!=null && (t instanceof File)) { _tmpDir=(File)t; if (_tmpDir.isDirectory() && _tmpDir.canWrite()) return _tmpDir; } if (t!=null && (t instanceof String)) { try { _tmpDir=new File((String)t); if (_tmpDir.isDirectory() && _tmpDir.canWrite()) { if(Log.isDebugEnabled())Log.debug("Converted to File "+_tmpDir+" for "+this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -