WEBX Framework: Valve Detailed

Source: Internet
Author: User

Valve is used to control the execution process of the request. It uses the design pattern of the responsibility chain (like a struts interceptor). Valve means valves that control the flow of water (network requests).


Custom valves.

public class Myvalve implements Valve {public    void Invoke (Pipelinecontext pipelinecontext) throws Exception {        Sy STEM.OUT.PRINTLN ("Valve started.");        Pipelinecontext.invokenext (); Call the post        -valves System.out.println ("valve ended.");}    <services:pipeline xmlns= "http://www.alibaba.com/schema/services/pipeline/valves" >...<valve class= " Com.alibaba.myapp.pipeline.MyValve "/>...</services:pipeline>


Call a valve. A valve can be obtained by autowired.

@Autowiredprivate Pipeline mypipeline;public void Invokepipeline () {    Pipelineinvocationhandle invocation = Mypipeline.newinvocation ();    Invocation.invoke ();}


A valve can call another pipeline. Any one of the pipeline calls can be interrupted.

Pipelinecontext.breakpipeline (0); Level=0, interrupts the current pipelinepipelinecontext.breakpipeline (1); Level=1, interrupt upper level Pipelinepipelinecontext.breakpipeline ("label"); Interrupts to the upper pipeline//of the specified label are equivalent to: Pipelinecontext.breakpipeline (Pipelinecontext.findlabel ("label")); Pipelinecontext.breakpipeline (Pipeline.top_label); Terminate all Pipelines


Built-in valve.


Loop

<loop loopcountername= "Count" maxloopcount= "ten" ><valve/><break-if test= "..."/></loop>< While maxloopcount= "ten" ><conditions:condition class= "..."/><valve/></while><if>< Conditions:condition class= "..."/><valve/></if><choose><when test= "1 = = 2" ><valve/ ></when><when><conditions:condition class= "..."/><valve/></when><otherwise ><valve/></otherwise></choose> use <exit/> in loops use <break-if test= "Count &gt; 2 "/><break-if tolabel=" My_loop "><conditions:condition class=" ... "/></break-if>< Break-unless test= "Count &lt;= 2"/><try-catch-finally><try><valve/></try><catch Exceptionname= "MyException" ><valve/></catch><finally><valve/></finally></ The try-catch-finally> condition supports JEXL and the custom condition class. <if><conditions:jexl-condition expr= "Loopcount == 2 "/><break/></if> equivalent: <if test=" Loopcount = = 2 "><break/></if><all-of>< Condition1/><condition2/><condition3/></all-of><any-of><condition1/>< Condition2/><condition3/></any-of><none-of><condition1/><condition2/>< Condition3/></none-of>


Here's a look at common valves.


Analyzeurl. Parses a URL to get target. It has a homepage parameter that acts as the default page.


Choose Equivalent to a switch statement in Java. Conditions can be specified by two properties, Target-extension-condition or target-condition. The following is an example of a choose statement.

<choose>  <when>    <pl-conditions:target-extension-condition extension= "null, VM, JSP"/>    ...  </when>  <when>    <pl-conditions:target-extension-condition extension= "Do"/>    ...  </when>    <otherwise>  ... </otherwise></choose>


Performaction. Executes the action to process the form. The action in WEBX is not the same as in other frames, only the form is processed here. Other frames may also render pages in action.


Performtemplatescreen. Its role is to find the corresponding screen code and execute it. If Target is xxx/yyy/zzz then the framework will look for Screen.xxx.yyy.Zzz, Screen.xxx.yyy.Default, Screen.xxx.Default, and screen in turn. Default, and call it's execute (context,httpservletrequest) method. Where do you find these classes? You can specify the root package in the module-loader/search-packages in Webx.xml.


Rendertemplate. Render the template. If Target is xxx/yyy/zzz then the framework will try to find/templates/screen/xxx/yyy/zzz,/templates/screen/xxx/yyy/default,/templates/ Screen/xxx/default,/templates/screen/default. If no template is found, a 404 error will be reported. Once the screen template is found, the framework also tries to find Layout:/templates/layout/xxx/yyy/zzz,/templates/layout/xxx/yyy/default, and so on.


Breakunlesstargetredirected. Jump out of the loop condition. If an internal redirect occurs, jump out of the loop.

WEBX Framework: Valve Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.