Pipeline数据流程
2、com.alibaba.citrus.turbine.pipeline.valve. BreakUnlessTargetRedirectedValve.class 3、CheckCsrfTokenValve.class ExceptionRecoveryValve.class ExportControlValve.class GetResourceValve.class HandleExceptionValve.class RequestHandlerValve.class
0、PrepareForTurbineValve.class 1、SetLoggingContextValve.class 2、AnalyzeURLValve.class 3、alimonitor 4、acl 5、带模板(vm.jsp) PerformTemplateScreenValve RenderTemplateValve.class
不带模板(jsx,json,jsonp) PerformActionValve.class PerformScreenValve.class
最后清理上下文
./gembone/target/gembone.war/WEB-INF/web.xml ./gembone.war/WEB-INF/web.xml ./gembone_source/bundle/war/src/webroot/WEB-INF/web.xml ./gembone_source/bundle/war/target/gembone.bundle.war-1.0-SNAPSHOT/WEB-INF/web.xml ./gembone_source/deploy/target/gembone.war/WEB-INF/web.xml
TryCatchFinally {
try = Pipeline [
[1/4] com.alibaba.citrus.turbine.pipeline.valve.SetLoggingContextValve#59529c2c:SetLoggingContextValve
[2/4] com.alibaba.citrus.turbine.pipeline.valve.AnalyzeURLValve#3e8b3a84:AnalyzeURLValve
[3/4] com.alibaba.alimonitor.jmonitor.plugin.webx3.JmonitorWebxUrlValve@41f67a4a
[4/4] LoopValve [
Pipeline [
[1/2] ChooseValve {
whenConditions = [
[1/2] com.alibaba.citrus.turbine.pipeline.condition.TargetExtensionCondition#1ee61327:TargetExtensionCondition
[2/2] com.alibaba.citrus.turbine.pipeline.condition.TargetExtensionCondition#4963ed5a:TargetExtensionCondition
]
whenBlocks = [
[1/2] Pipeline [
[1/3] com.alibaba.citrus.turbine.pipeline.valve.PerformActionValve#12f3754a:PerformActionValve
[2/3] com.alibaba.citrus.turbine.pipeline.valve.PerformTemplateScreenValve#2d9956fe:PerformTemplateScreenValve
[3/3] com.alibaba.citrus.turbine.pipeline.valve.RenderTemplateValve#2e1e5515:RenderTemplateValve
]
[2/2] Pipeline [
[1/2] com.alibaba.citrus.turbine.pipeline.valve.PerformActionValve#3f73d55a:PerformActionValve
[2/2] com.alibaba.citrus.turbine.pipeline.valve.PerformScreenValve#4dbc2841:PerformScreenValve
]
]
otherwiseBlock = Pipeline [
[1/1] ExitValve
]
}
[2/2] BreakValve[levels=0]
]
]
]
catch = Pipeline [
[1/3] com.alibaba.citrus.turbine.pipeline.valve.HandleExceptionValve#1c2e0ede:HandleExceptionValve
[2/3] com.alibaba.citrus.turbine.pipeline.valve.PerformTemplateScreenValve#13d21f46:PerformTemplateScreenValve
[3/3] com.alibaba.citrus.turbine.pipeline.valve.RenderTemplateValve#480336d4:RenderTemplateValve
]
finally = Pipeline [
[1/1] com.alibaba.alimonitor.jmonitor.plugin.webx3.JmonitorWebxUrlFinallyValve@1cd6b21b
]
}
pipeline的作用
首先,我们要知道pipeline是干什么的。pipeline他是对每一次请求url进行检验。如果通过这些ji则容许请求继续往下进行,否则跑出错误。
pipeline的启动流程
web工程会从web.xml中开始启动。web.xml中通过这个类将/WEB-INF/webx-*.xml都加载进来了。而这个目录中配置了很多web应用,例如,webx-icase.xml就是其中一个web应用。 web-icase.xml中将pipeline.xml作为一个组件加载进来了。
pipeline的源代码
pipeline的模块是可以定制的。如果你要增加一个模块,只需要将你的定制的模块加载进来就可以了。这也是webx的一个优势。 下面是pipeline的源代码:
<beans:beans>
<services:pipeline xmlns="http://www.alibaba.com/schema/services/pipeline/valves">
<!--
初始化turbine
rundata,并在pipelineContext中设置可能会用到的对象(如rundata、utils),以便valve取得。
-->
<prepareForTurbine/>
<try-catch-finally>
<try>
<!-- 设置日志系统的上下文,支持把当前请求的详情打印在日志中。 -->
<setLoggingContext/>
<!-- 分析URL,取得target。 -->
<analyzeURL/>
<!-- alimonitor for uri of webx3 -->
<valve class="com.alibaba.alimonitor.jmonitor.plugin.webx3.JmonitorWebxUrlValve"/>
<!-- checkChinaCsrfToken/ -->
<!-- ACL:引入 初始化
<valve class="com.alibaba.acl.permission.webx3.pipeline.AclContextValve" p:action="init" />-->
<loop>
<choose>
<when>
<!-- 执行带模板的screen,默认有layout。 -->
<pl-conditions:target-extension-condition extension="vm,jsp"/>
<!-- ACL:在ActionValve之前添加对应的Action鉴权Valve <valve class="com.alibaba.acl.permission.webx3.pipeline.ActionPermissionValve" /> -->
<performAction/>
<!-- ACL:在Screen Valve之前添加对应的Screen鉴权Valve <valve class="com.alibaba.acl.permission.webx3.pipeline.ScreenPermissionValve" /> -->
<performTemplateScreen/>
<renderTemplate/>
</when>
<when>
<!-- 执行不带模板的screen,默认无layout。 -->
<pl-conditions:target-extension-condition extension="jsx,json,jsonp"/>
<performAction/>
<performScreen/>
</when>
<otherwise>
<!-- 将控制交还给servlet engine。 -->
<exit/>
</otherwise>
</choose>
<!-- 假如rundata.setRedirectTarget()被设置,则循环,否则退出循环。 -->
<breakUnlessTargetRedirected/>
</loop>
</try>
<catch>
<handleException defaultPage="exception.vm"/>
<performTemplateScreen/>
<renderTemplate/>
</catch>
<finally>
<!-- 添加清理上下文的Valve
<valve class="com.alibaba.acl.permission.webx3.pipeline.AclContextValve" p:action="clean" />-->
<valve class="com.alibaba.alimonitor.jmonitor.plugin.webx3.JmonitorWebxUrlFinallyValve"/>
</finally>
</try-catch-finally>
</services:pipeline>
</beans:beans>
pipeline的执行过程
从pipeline的源代码中可以看出,pipeline的执行流程是这样子的。 1、准备turbine,将一些初始数据,如turbineRunData, 一些初始的util方法 2、初始化日志环境 3、分析URL 4、启动alimonitor 5、csrfToken检验 6、启动acl检验 7、执行循环体,如果是带模板的url请求,则执行模板渲染;如果不是带模板的请求,则执行action的渲染
pipeline各个子模块的功能
从上面的分析可以看出,pipeline大致包含初始化数据模块(PrepareForTurbineValve)、日志系统模块(SetLoggingContextValve)、url校验模块(AnalyzeURLValve)、alimonitor监控模块、acl权限控制模块、页面渲染模块(performAction、performTemplateScreen、renderTemplate)、action渲染模块(performAction/performScreen),实际上,除了上面这些模块,还有一些exception处理模块。