|
Orion Filter Tutorial, Lesson 6, A Chain of Filters
In this part of the tutorial, we will look at how to set up a chain of Filters.
1 Introduction
In this part of the tutorial, we will look at how to set up a chain of Filters.
A chain of Filters is a number of Filters that will be invoked in a certain order before the response is handled to the client.
The invocation order is the same as the ordering of the filter-mapping entries in web.xml for a certain URL.
Take a look at the example given in listing 1 below:
... <filter-mapping> <filter-name>prePost</filter-name> <url-pattern>/filter3.*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>prePost</filter-name> <url-pattern>/filter3.*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>prePost</filter-name> <url-pattern>/filter3.*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>prePost</filter-name> <url-pattern>/filter3.*</url-pattern> </filter-mapping> ...
|
Listing 1: Example web.xml filer-mapping entries
As the filter-mapping entries in Listing 1 above is mapped to the same resource, these will act as a chain of Filters. When a request is made to a resource matching the url-pattern stated, the Filters will be invoked one after the other, starting with the first configured entry and ending with the last configured entry. So if the resource was the same JSP page as we used in lesson 3, the output would look like in Listing 2 below:
<HR>PRE<HR><HR>PRE<HR><HR>PRE<HR><HR>PRE<HR><HTML> <HEAD> <TITLE>Lesson 3</TITLE> </HEAD> <BODY> <P>This is a pure testpage</p> </BODY> </HTML><HR>POST<HR><HR>POST<HR><HR>POST<HR><HR>POST<HR>
|
Listing 2: Example output
In the case of Filters mapped to Servlet-names, these are invoked after that the Filters mapped to url-patterns has been invoked. Just as with url-pattern based filter-mapping entries, the invocation order is based upon the order which the filter-mappings are configured in.
If a certain resource is mapped to Filters with both servlet-names and url-pattners, the Filters mapped with url-patterns are invoked first. The last url-pattern mapped Filter will then invoke the first Servlet-name mapped Filter. The Last Servlet-name mapped Filter will then invoke the resource.
Of course, the developer can always choose to discontinue the chain of Filters and redirect or handle the response itself at any time.
Copyright ©
2003 IronFlare AB
|