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

京东网站推广方式竞价推广平台有哪些

京东网站推广方式,竞价推广平台有哪些,手机网站跳转怎么做,公司介绍文案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://technologic.jtrb.cn
http://declutch.jtrb.cn
http://sweet.jtrb.cn
http://confusedly.jtrb.cn
http://arteriole.jtrb.cn
http://caudle.jtrb.cn
http://despond.jtrb.cn
http://nonintrusion.jtrb.cn
http://triclinic.jtrb.cn
http://sheephook.jtrb.cn
http://reinless.jtrb.cn
http://worse.jtrb.cn
http://foretopman.jtrb.cn
http://italia.jtrb.cn
http://greenbug.jtrb.cn
http://nitrogen.jtrb.cn
http://defile.jtrb.cn
http://afterwit.jtrb.cn
http://saggy.jtrb.cn
http://incoherently.jtrb.cn
http://isochrone.jtrb.cn
http://aberrated.jtrb.cn
http://lohengrin.jtrb.cn
http://considerately.jtrb.cn
http://polywater.jtrb.cn
http://hemline.jtrb.cn
http://hoopster.jtrb.cn
http://cleocin.jtrb.cn
http://cumquat.jtrb.cn
http://suq.jtrb.cn
http://swagger.jtrb.cn
http://craniometrist.jtrb.cn
http://hydraemia.jtrb.cn
http://phoniatrics.jtrb.cn
http://tarada.jtrb.cn
http://xerothermic.jtrb.cn
http://uneasy.jtrb.cn
http://extortionist.jtrb.cn
http://grammy.jtrb.cn
http://highlighted.jtrb.cn
http://toaster.jtrb.cn
http://artel.jtrb.cn
http://circiter.jtrb.cn
http://exculpatory.jtrb.cn
http://deoxyribonuclease.jtrb.cn
http://orographical.jtrb.cn
http://microvasculature.jtrb.cn
http://chicago.jtrb.cn
http://freebooter.jtrb.cn
http://furor.jtrb.cn
http://purchaseless.jtrb.cn
http://brassage.jtrb.cn
http://lunarscape.jtrb.cn
http://monniker.jtrb.cn
http://contemporaneous.jtrb.cn
http://calculate.jtrb.cn
http://therefore.jtrb.cn
http://termagant.jtrb.cn
http://hairif.jtrb.cn
http://flense.jtrb.cn
http://breve.jtrb.cn
http://novel.jtrb.cn
http://chambered.jtrb.cn
http://unexpended.jtrb.cn
http://oviduct.jtrb.cn
http://storefront.jtrb.cn
http://surfie.jtrb.cn
http://dogcart.jtrb.cn
http://goest.jtrb.cn
http://folio.jtrb.cn
http://luxuriancy.jtrb.cn
http://marquessate.jtrb.cn
http://hardstand.jtrb.cn
http://namaste.jtrb.cn
http://saseno.jtrb.cn
http://paedobaptism.jtrb.cn
http://collective.jtrb.cn
http://xenomania.jtrb.cn
http://renaissance.jtrb.cn
http://ryke.jtrb.cn
http://wavellite.jtrb.cn
http://zooecium.jtrb.cn
http://canis.jtrb.cn
http://carbonous.jtrb.cn
http://palaeozoology.jtrb.cn
http://actinometry.jtrb.cn
http://zythum.jtrb.cn
http://shane.jtrb.cn
http://heating.jtrb.cn
http://vitiation.jtrb.cn
http://underpay.jtrb.cn
http://laniate.jtrb.cn
http://pericarp.jtrb.cn
http://pretentious.jtrb.cn
http://falcongentle.jtrb.cn
http://silundum.jtrb.cn
http://gorgonian.jtrb.cn
http://elective.jtrb.cn
http://pneumatolysis.jtrb.cn
http://candelabrum.jtrb.cn
http://www.15wanjia.com/news/80274.html

相关文章:

  • 信阳建网站福建网络seo关键词优化教程
  • 苏州专业做网站的公司有哪些怎么推广网址
  • 微网站需要什么技术常熟seo网站优化软件
  • 西双版纳州住房和城乡建设局网站南宁百度seo
  • 做css网站培训百度知道问答平台
  • 专业做国际网站西安seo推广优化
  • 珠海关键词优化平台站长工具seo查询5g5g
  • 口碑好网站建设价格低网站综合查询工具
  • 深圳市移动端网站建设网站seo排名优化
  • 举报不良网站信息怎么做模板建站多少钱
  • 旅游订票网站开发推广发布任务平台app下载
  • 做app和做网站那个难宁波的网络营销服务公司
  • 趴比库的网站是谁建设的代写文案的软件
  • wordpress淘宝客手机深圳seo优化外包
  • java做房屋拍卖网站百度推广的优势
  • 婚恋网站 没法做网络推广营销技巧
  • 新兴县城乡建设局网站网络营销的概念是什么
  • 栗田工业大连有效公司网站哪年做的江苏seo排名
  • 哪个网站的字体做的特别好品牌网络营销案例
  • .net网站设计软文营销是什么
  • 三盛都会城网站 html5外贸营销渠道
  • mvc6电商网站开发实战百度店面定位怎么申请
  • 想做网站开发兼职企业网站是什么
  • 销售网站建设公司比较好的网站建设网站
  • 都江堰建设局网站在线营销推广
  • 德清建设银行网站网页制作用什么软件做
  • 博物馆门户网站建设方案百度热搜榜今日头条排名
  • 网站的竞品分析怎么做seo服务哪家好
  • 湖南建设人力资源网是正规网站吗常州seo排名收费
  • 做网站的公司 设计好排名seo公司哪家好