wicket学习之WicketFilter(一)
程序员文章站
2022-07-15 15:14:21
...
深入WicketFilter源码学习,两个步骤,首先引用API中WicketFilter的描述,对WicketFilter做一个简单的介绍;接着从代码层面着手,剖析WicketFIlter。WicketFilter中init方法用来初始化应用资源,doFilter代理doGet方法,处理实际的Wicket请求。本篇文章主要对WicketFilter的init方法进行了深入了解。
API中wicketFilter的解释:
WicketFilter 用来处理wicket请求。
使用WicketFilter处理请求的优势:可以对Wicket 请求有选择性的处理。比如,wicket请求image资源,WicketFiler可以选择不处理。
属性说明:
FILTER_MAPPING_PARAM:给出定制web.xml的路径
init(FilterConfig filterConfig)
init(FilterConfig) goes through a series of steps of steps to initialise:
1. Sets up ignore paths //initIgnorePaths(filterConfig);
值的格式:/images/products/,/documents/pdf/
处理的时候去掉了开头的/
然后将值保存在 Set<String> ignorePaths中
2. Records class loaders
指定类加载器,加载web.xml文件。
3. Finds the filter's path - filterPath
通过处理web.xml文件,获得filterPath
关键方法:getFilterPath(filterConfig.getFilterName(), is)
4. Sets up the IWebApplicationFactory and WebApplication for this filter, including it's initialisation.
Creates the web application factory instance.
通过初始化参数applicationFactoryClassName指定定制的applicationFactory
否则创建默认:ContextParamWebApplicationFactory()
通过指定applicationClassName参数,创建Class.forName(applicationClassName, false, loader).newInstance()
// Store instance of this application object in servlet context to
// make integration with outside world easier
String contextKey = "wicket:" + filterConfig.getFilterName();
filterConfig.getServletContext().setAttribute(contextKey, webApplication);
// set the application thread local in case initialization code uses it
Application.set(webApplication);
// Call internal init method of web application for default
// initialization
webApplication.internalInit();
webApplication.init();(默认的WebApplication中init方法是没有提供实现的)
下面是webApplication.init()的一段说明,供参考
/**
* Initialize; if you need the wicket servlet for initialization, e.g. because you want to read
* an initParameter from web.xml or you want to read a resource from the servlet's context path,
* you can override this method and provide custom initialization. This method is called right
* after this application class is constructed, and the wicket servlet is set. <strong>Use this
* method for any application setup instead of the constructor.</strong>
*/
重点:
1、you can override this method and provide custom initialization
2、将app的一些setup放在init方法中
5. Initialise WebApplication request listeners.
调用org.apache.wicket.Initializer的init()
org.apache.wicket.extendsions.Initializer的init()
6. Log start of Application
记录应用开始
7. Detect if running in a Portlet context and if so intialise the WicketFilterPortletContext
portlet应用初始化
本篇对WicketFIlter的介绍,到此就结束了。
本人对WicketFilter有几个不是很清楚的地方:
1、wicket commponent的呈现,
2、wicketFilter对请求的具体处理过程,
3、Wicket作为一个事件驱动型框架,里面注册了一系列的监听器,目前还没做深入了解。
有兴趣的朋友,可以一起交流。
我的QQ:497724941
API中wicketFilter的解释:
WicketFilter 用来处理wicket请求。
使用WicketFilter处理请求的优势:可以对Wicket 请求有选择性的处理。比如,wicket请求image资源,WicketFiler可以选择不处理。
属性说明:
FILTER_MAPPING_PARAM:给出定制web.xml的路径
init(FilterConfig filterConfig)
init(FilterConfig) goes through a series of steps of steps to initialise:
1. Sets up ignore paths //initIgnorePaths(filterConfig);
值的格式:/images/products/,/documents/pdf/
处理的时候去掉了开头的/
然后将值保存在 Set<String> ignorePaths中
2. Records class loaders
指定类加载器,加载web.xml文件。
3. Finds the filter's path - filterPath
通过处理web.xml文件,获得filterPath
关键方法:getFilterPath(filterConfig.getFilterName(), is)
4. Sets up the IWebApplicationFactory and WebApplication for this filter, including it's initialisation.
Creates the web application factory instance.
通过初始化参数applicationFactoryClassName指定定制的applicationFactory
否则创建默认:ContextParamWebApplicationFactory()
通过指定applicationClassName参数,创建Class.forName(applicationClassName, false, loader).newInstance()
// Store instance of this application object in servlet context to
// make integration with outside world easier
String contextKey = "wicket:" + filterConfig.getFilterName();
filterConfig.getServletContext().setAttribute(contextKey, webApplication);
// set the application thread local in case initialization code uses it
Application.set(webApplication);
// Call internal init method of web application for default
// initialization
webApplication.internalInit();
webApplication.init();(默认的WebApplication中init方法是没有提供实现的)
下面是webApplication.init()的一段说明,供参考
/**
* Initialize; if you need the wicket servlet for initialization, e.g. because you want to read
* an initParameter from web.xml or you want to read a resource from the servlet's context path,
* you can override this method and provide custom initialization. This method is called right
* after this application class is constructed, and the wicket servlet is set. <strong>Use this
* method for any application setup instead of the constructor.</strong>
*/
重点:
1、you can override this method and provide custom initialization
2、将app的一些setup放在init方法中
5. Initialise WebApplication request listeners.
调用org.apache.wicket.Initializer的init()
org.apache.wicket.extendsions.Initializer的init()
6. Log start of Application
记录应用开始
7. Detect if running in a Portlet context and if so intialise the WicketFilterPortletContext
portlet应用初始化
本篇对WicketFIlter的介绍,到此就结束了。
本人对WicketFilter有几个不是很清楚的地方:
1、wicket commponent的呈现,
2、wicketFilter对请求的具体处理过程,
3、Wicket作为一个事件驱动型框架,里面注册了一系列的监听器,目前还没做深入了解。
有兴趣的朋友,可以一起交流。
我的QQ:497724941