当前位置: 首页 > news >正文

房地产网站方案营销策略ppt模板

房地产网站方案,营销策略ppt模板,网站跳出率因素,网站怎么做登陆SpringBoot TomcatEmbeddedContext Servlet ApplicationFilterChain Filter 背景: 在之前博客中有说明SpringBoot内嵌Web容器后,Filter及Servlet解析与注册流程的变化。将Filter实例封装成FilterRegistrationBean实例并添加到ServletContext后&…

SpringBoot + TomcatEmbeddedContext + Servlet + ApplicationFilterChain + Filter

背景: 在之前博客中有说明SpringBoot内嵌Web容器后,Filter及Servlet解析与注册流程的变化。将Filter实例封装成FilterRegistrationBean实例并添加到ServletContext后,到实际使用Filter完成过滤功能之前,其实中间还有一些管理流程。本文将在此背景下,继续追加描述此块逻辑。

博客内容精选:
1、Servlet请求体重复读&修改新姿势
2、根据请求获取后端接口详情
3、SpringBoot下Filter自动适配
4、Filter链式执行设计解读

一、首
先Filter相关定义经解析过存储在TomcatEmbeddedContext对象中,有三个重要变量:
1、private Map<String, FilterDef> filterDefs // 存储Filter定义元数据,如filterClass、name等
2、private final StandardContext.ContextFilterMaps filterMaps // FilterMap-匹配元数据,如String[] urlPatterns
3、private Map<String, ApplicationFilterConfig> filterConfigs // 由filterDefs可封装成ApplicationFilterConfig,核心为Filter实例

ApplicationFilterConfig(Context context, FilterDef filterDef) throws Exception{this.context = context;this.filterDef = filterDef;if (filterDef.getFilter() == null) {this.getFilter();} else {this.filter = filterDef.getFilter();context.getInstanceManager().newInstance(this.filter);this.initFilter();}
}

我们都知道Filter要发布到Servlet容器,先以FilterRegistrationBean的形式封装,因注册Bean底层接口包含ServletContextInitializer,其在onStartup(ServletContext servletContext)方法执行下注册到ServletContext中去,以下为注册代码:

// 执行入口
public final void onStartup(ServletContext servletContext) throws ServletException {..........省略.............this.register(description, servletContext);
}
// 注册入口
protected final void register(String description, ServletContext servletContext) {// 将Filter实例加入ContextD registration = this.addRegistration(description, servletContext);if (registration == null) {logger.info(StringUtils.capitalize(description) + " was not registered (possibly already registered?)");} else {// 配置Filter匹配元数据this.configure(registration);}
}
// Filter实例对象注册
protected Dynamic addRegistration(String description, ServletContext servletContext) {Filter filter = this.getFilter();// 此处可将Filter实例添加到FilterDef =》filterDef.setFilter(filter)// 返回ApplicationFilterRegistration(filterDef, this.context)对象return servletContext.addFilter(this.getOrDeduceName(filter), filter);
}
// URL等匹配元数据注册
protected void configure(Dynamic registration) {super.configure(registration);EnumSet<DispatcherType> dispatcherTypes = this.dispatcherTypes;..........省略..........// 重点registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter, StringUtils.toStringArray(this.urlPatterns));
}public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns) {FilterMap filterMap = new FilterMap();filterMap.setFilterName(this.filterDef.getFilterName());..........if (urlPatterns != null) {for(int var7 = 0; var7 < urlPatterns.length; ++var7) {String urlPattern = urlPatterns[var7];filterMap.addURLPattern(urlPattern);}if (isMatchAfter) {// 此处即为添加匹配元数据到Servlet上下文中this.context.addFilterMap(filterMap);} else {this.context.addFilterMapBefore(filterMap);}}
}

二、ApplicationFilterFactory使用createFilterChain工厂方法创建ApplicationFilterChain链
createFilterChain有两大核心逻辑
1)创建ApplicationFilterChain实例

ApplicationFilterChain filterChain = null;
if (request instanceof Request) {Request req = (Request)request;if (Globals.IS_SECURITY_ENABLED) {filterChain = new ApplicationFilterChain();} else {filterChain = (ApplicationFilterChain)req.getFilterChain();if (filterChain == null) {// 核心逻辑,直接创建Chain实例,且构造器无其他初始化逻辑filterChain = new ApplicationFilterChain();// chain对象复用,注意这里req对象是org.apache.catalina.connector.Request// chain内容不复用,filterChain使用完毕会调用release方法释放资源req.setFilterChain(filterChain);}}
} else {filterChain = new ApplicationFilterChain();
}

2)过滤器链初始化【极简版】

// Servlet设置
filterChain.setServlet(servlet); // DispatcherServlet实例
StandardContext context = (StandardContext)wrapper.getParent(); // TomcatEmbeddedContext
// 获取Servlet上下文中的过滤器匹配元数据
FilterMap[] filterMaps = context.findFilterMaps();
if (filterMaps != null && filterMaps.length != 0) {// 分发类型,一般为RequestDispatcherType dispatcher = (DispatcherType)request.getAttribute("org.apache.catalina.core.DISPATCHER_TYPE");// 请求URI解析,此处忽略   String requestPath = xxx;String servletName = wrapper.getName(); // 值为dispatcherServletFilterMap filterMap;ApplicationFilterConfig filterConfig;for(int index = 0; index < filterMaps.length; ++index) {filterMap = filterMaps[index];// 目前Springboot项目基本只需解析matchFiltersURL方法,根据URL匹配对应Filterif (matchDispatcher(filterMap, dispatcher) && matchFiltersURL(filterMap, requestPath)) {filterConfig = (ApplicationFilterConfig)context.findFilterConfig(filterMap.getFilterName());if (filterConfig != null) {// 过滤器链中数组对象存的是ApplicationFilterConfig实例,而不是Filter实例,因为部分场景需要元数据作为判断条件filterChain.addFilter(filterConfig);}}}// Servlet匹配Filter当前无用,仅作参考。结构类似,代码忽略..............................return filterChain;
}

三、过滤器链执行入口:StandardWrapperValve
在StandardWrapperValve中,由invoke(Request request, Response response)方法内执行过滤器链,StandardWrapperValve前也是通过责任链模式一步步传递过来,也有相似的Valve实例。

过滤器链执行流程很简单,可以简化为以下过程:
// 注:这里传给Filter的其实是RequestFacade对象,包装了底层的Request对象,Response同理
1、filterChain.doFilter(request.getRequest(), response.getResponse())

2、中间过滤器链执行流程,已在其他博客说明

//过滤器链每次执行后,释放资源
3、filterChain.release()

总结:本文将Filter在Servlet上下文的注册流程、FilterChain过滤器链的封装流程基本讲述完成,其他Filter相关知识可参考之前其他博客内容,剩余细节不在展开。

思考:
1、过滤器池化相关概念,实际不是FilterChain的池化,其每次会recycle,而是org.apache.coyote.Request请求对象的池化(注意:此对象不是实现HttpServletRequest的org.apache.catalina.connector.Request)。Request对象较为底层且复杂,在并发量较低时,同一接口间隔请求都是一个Request对象,使用完成也会调用recycle回收,response同理。
2、FilterChain在Request池化基础上,每次不会新建,但是每次请求都会重新生成ApplicationFilterConfig数组。按现在Springboot请求流程,暂不清楚为啥需要recycle,(只是元数据封装,性能影响很小)可能考虑到Filter可能在服务期间被destroy?
3、至于线程安全问题,FilterChain是多例的,Filter是单例的,但是被多个FilterChain封装,也能并发执行,所以不要在Filter中定义共享变量。


文章转载自:
http://quaternate.c7617.cn
http://blunge.c7617.cn
http://prefecture.c7617.cn
http://equipotent.c7617.cn
http://reinterrogate.c7617.cn
http://saltshaker.c7617.cn
http://distemper.c7617.cn
http://voltammetry.c7617.cn
http://terga.c7617.cn
http://betroth.c7617.cn
http://pastoral.c7617.cn
http://lampedusa.c7617.cn
http://astrophotometry.c7617.cn
http://quickthorn.c7617.cn
http://mobilise.c7617.cn
http://balas.c7617.cn
http://stylography.c7617.cn
http://heartful.c7617.cn
http://ferritin.c7617.cn
http://mix.c7617.cn
http://outstate.c7617.cn
http://dexterity.c7617.cn
http://bilobed.c7617.cn
http://enplane.c7617.cn
http://acanthoid.c7617.cn
http://electrosynthesis.c7617.cn
http://incorporable.c7617.cn
http://nephrectomy.c7617.cn
http://humanities.c7617.cn
http://boreen.c7617.cn
http://stapes.c7617.cn
http://dishwatery.c7617.cn
http://deface.c7617.cn
http://marginal.c7617.cn
http://executorship.c7617.cn
http://blockship.c7617.cn
http://barish.c7617.cn
http://trigynous.c7617.cn
http://columniform.c7617.cn
http://officiant.c7617.cn
http://antiauxin.c7617.cn
http://bifolium.c7617.cn
http://methoxybenzene.c7617.cn
http://decahedral.c7617.cn
http://dysentery.c7617.cn
http://delegation.c7617.cn
http://cartouche.c7617.cn
http://rectilineal.c7617.cn
http://idiomaticity.c7617.cn
http://carnificial.c7617.cn
http://consociate.c7617.cn
http://grubber.c7617.cn
http://corslet.c7617.cn
http://stupefy.c7617.cn
http://tramway.c7617.cn
http://camisard.c7617.cn
http://scandinavian.c7617.cn
http://fatter.c7617.cn
http://bolus.c7617.cn
http://gaijin.c7617.cn
http://tetrahedrane.c7617.cn
http://cacholong.c7617.cn
http://bifer.c7617.cn
http://leben.c7617.cn
http://scrutator.c7617.cn
http://make.c7617.cn
http://abnaki.c7617.cn
http://chibouk.c7617.cn
http://peckerhead.c7617.cn
http://bacteriorhodopsin.c7617.cn
http://erstwhile.c7617.cn
http://canard.c7617.cn
http://vivarium.c7617.cn
http://chenopod.c7617.cn
http://terminable.c7617.cn
http://fibrino.c7617.cn
http://whipper.c7617.cn
http://bloodstained.c7617.cn
http://sangfroid.c7617.cn
http://neglectful.c7617.cn
http://cardo.c7617.cn
http://cathectic.c7617.cn
http://biotypology.c7617.cn
http://elocutionist.c7617.cn
http://olive.c7617.cn
http://cislunar.c7617.cn
http://trauma.c7617.cn
http://schnozzle.c7617.cn
http://gramophone.c7617.cn
http://disambiguition.c7617.cn
http://agnosticism.c7617.cn
http://yardwand.c7617.cn
http://chose.c7617.cn
http://sutherland.c7617.cn
http://lutz.c7617.cn
http://godlet.c7617.cn
http://snofari.c7617.cn
http://schoolchild.c7617.cn
http://chrominance.c7617.cn
http://medallist.c7617.cn
http://www.zhongyajixie.com/news/93840.html

相关文章:

  • 网站建设面试表种子资源
  • 涨口碑说做的网站现在阳性最新情况
  • 有没有做淘宝的网站吗软文代写费用
  • 前端一般模仿什么网站百度域名注册
  • 怎么做网页长图重庆seo杨洋
  • 网站建设详细方案seo实战培训中心
  • 注册网站不用手机短信验证的网站seo二级目录
  • 品牌服装网站建设现状关键词优化一年的收费标准
  • 建设银行网站是多少钱重庆seo排名优化
  • 基础建设的网站有哪些内容百度投流
  • 做框架模板的网站怎样建立自己网站
  • 苏州企业如何建网站微信营销策略
  • 淄博专业网站建设价格百度关键词优化软件怎么样
  • 手机端网站源码今天热点新闻
  • 为什么要选择高端网站定制青岛快速排名优化
  • python18搜索引擎优化分析
  • 做境外域名网站湖南网站营销seo方案
  • 河南睢县筑宇建设网站seo和sem
  • 手工制作迷你抓娃娃机手机网站关键词seo
  • 怎样做月嫂网站谷歌seo和百度区别
  • 网站制作方案搜图片百度识图
  • WordPress创建的网站宣传推广策略
  • 红十字会网站建设方案北京百度网讯科技有限公司
  • 做任务挣钱的网站app建网站需要多少钱和什么条件
  • 武汉网站建设与服务公司广告投放怎么做
  • 网上营销型网站有哪些新开传奇网站发布站
  • 英国做电商网站企业网络推广的方式有哪些
  • 做电玩城设计的网站品牌全网推广
  • wordpress更换主题的技巧专业seo站长工具全面查询网站
  • 合肥浦发建设集团网站百度收录量