Tomcat8.5源码分析-StandardWrapper
来源:互联网 发布:学美工设计要什么基础 编辑:程序博客网 时间:2024/06/06 02:11
StandardWrapper
wrapper的定义
wrapper原本在java中指的是一个包装类,在tomcat中是一个接口,StandardwrapperWrapper 代表一个 Servlet,它负责管理一个 Servlet,包括的 Servlet 的装载、初始化、执行以及资源回收。它的父容器一般是Context,Wrapper 是最底层的容器,它没有子容器了,所以调用它的 addChild 将会抛illegalargumentexception。Wrapper 的实现类是 StandardWrapper,StandardWrapper 还实现了拥有一个 Servlet 初始化信息的 ServletConfig,由此看出 StandardWrapper 将直接和 Servlet 的各种信息打交道。
在StandardContext启动时,读取web.xml配置文件,配置Context之后,紧接着启动Context的一些附属组件,除此以外还加载了那些标记为”load on start”的那些wrapper。
源码分析
public synchronized void load() throws ServletException { instance = loadServlet();/*创建servelt实例*/ if (!instanceInitialized) { initServlet(instance);/*对servlet进行初始化*/ } if (isJspServlet) { StringBuilder oname = new StringBuilder(getDomain()); oname.append(":type=JspMonitor"); oname.append(getWebModuleKeyProperties()); oname.append(",name="); oname.append(getName()); oname.append(getJ2EEKeyProperties()); try { jspMonitorON = new ObjectName(oname.toString()); Registry.getRegistry(null, null) .registerComponent(instance, jspMonitorON, null); } catch( Exception ex ) { log.info("Error registering JSP monitoring with jmx " + instance); } } }
先用loadServlet()这个方法进行初始化,如果没有初始化,在用initServlet方法进行初始化,事实上,在loadServlet方法里也调用了initServlet这个方法。
然后看看它是怎么初始化Servlet的:
private synchronized void initServlet(Servlet servlet) throws ServletException { if (instanceInitialized && !singleThreadModel) return; // Call the initialization method of this servlet try { if( Globals.IS_SECURITY_ENABLED) { boolean success = false; try { Object[] args = new Object[] { facade }; SecurityUtil.doAsPrivilege("init", servlet, classType, args); success = true; } finally { if (!success) { // destroy() will not be called, thus clear the reference now SecurityUtil.remove(servlet); } } } else { servlet.init(facade); } instanceInitialized = true; } catch (UnavailableException f) { unavailable(f); throw f; } catch (ServletException f) { // If the servlet wanted to be unavailable it would have // said so, so do not call unavailable(null). throw f; } catch (Throwable f) { ExceptionUtils.handleThrowable(f); getServletContext().log("StandardWrapper.Throwable", f ); // If the servlet wanted to be unavailable it would have // said so, so do not call unavailable(null). throw new ServletException (sm.getString("standardWrapper.initException", getName()), f); } }
可以看到,他调用了securityUtil这个类里面的方法,这里不展开讨论。
至此,web应用加载的分析告一段落。
阅读全文
0 0
- Tomcat8.5源码分析-StandardWrapper
- Tomcat8.5源码分析-StandardHost
- Tomcat8.5源码分析-HostConfig
- Tomcat8.5源码分析-StandardContext
- Tomcat8.5源码分析-ContextConfig
- tomcat8关键性源码分析
- Tomcat8源码分析(一)
- Tomcat8源码分析(二)
- Tomcat8源码分析(三)
- Tomcat8源码分析(四)
- tomcat8源码分析(一):导入eclipse
- tomcat8源码导入
- Eclipse运行Tomcat8源码
- Tomcat8.0.0源码研读
- tomcat8 源码 导入eclipse
- tomcat(11)org.apache.catalina.core.StandardWrapper源码剖析
- Tomcat8.5.11源码导入Myeclipse
- tomcat8.5.15源码编译运行
- Java集合 介绍二
- 论文格式
- 图解VIM常用操作
- 802.11协议帧格式、WiFi破解
- HashMap实现原理及源码分析
- Tomcat8.5源码分析-StandardWrapper
- pyCharm最新2017激活码
- OSG 文件读取机制 类图
- UVA1476——Error Curves (三分求极值)
- Vue读取本地文件
- Java8
- uva 11584
- mysql 使用select插入多条数据,insert into (1,2,3,4,)select(1,2,3,4)
- Redis 有序集合