wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter Chain. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Filter Chain." Watch "Filter Chain." New topic
Author

Filter Chain.

joko mujoko
Ranch Hand

Joined: May 30, 2006
Posts: 30
Hi All rancher, I Have doubt about filter chain. To chain the filter is different with Deployment Descriptor url. How is filter chain work? I mean can we figure out the sequence of chain?
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
From Servlet 2.4 Spec SRV.6.2.4:



The order the container uses in building the chain of filters to be applied for a particular request URI is as follows:

1. First, the <url-pattern> matching filter mappings in the same order that these elements appear in the deployment descriptor.

2. Next, the <servlet-name> matching filter mappings in the same order that
these elements appear in the deployment descriptor.

This requirement means that the container, when receiving an incoming
request, processes the request as follows:

� Identifies the target Web resource according to the rules of �Specification of Mappings� on page 86.

� If there are filters matched by servlet name and the Web resource has a
<servlet-name>, the container builds the chain of filters matching in the order declared in the deployment descriptor. The last filter in this chain corresponds to the last <servlet-name> matching filter and is the filter that invokes the target Web resource.

� If there are filters using <url-pattern> matching and the <url-pattern>
matches the request URI according to the rules of Section SRV.11.2, �Specification of Mappings�, the container builds the chain of <url-pattern> matched filters in the same order as declared in the deployment descriptor. The last filter in this chain is the last <url-pattern> matching filter in the deployment descriptor for this request URI. The last filter in this chain is the filter that invokes the first filter in the <servlet-name> matching chain, or invokes the target Web
resource if there are none.


SCJP 1.4, SCWCD 1.4
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Also see this thread.
joko mujoko
Ranch Hand

Joined: May 30, 2006
Posts: 30
Thanks for the reply Reshma Pai
and Owen, there's still confusing in this part

• If there are filters using <url-pattern> matching and the <url-pattern>
matches the request URI according to the rules of Section SRV.11.2, “Specification of Mappings”, the container builds the chain of <url-pattern> matched filters in the same order as declared in the deployment descriptor. The last filter in this chain is the last <url-pattern> matching filter in the deployment descriptor for this request URI. The last filter in this chain is the filter that invokes the first filter in the <servlet-name> matching chain, or invokes the target Web
resource if there are none.



in HFSJ book,( filter part in sharpen pencil)(sorry i dont bring the book at this moment)is not like my opinion . Where there are some URL match with the filter. It is write 2, 1, 5 but my opinion is 1,2,5. Also in another number

joko
sitting in the dark side
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
I am unable get what your question is, i will try and explain the
sharpen pencil section below, emphasizing on second request path for i guess the confusion lies when servlet is a component in filter chain.


The container always construts the filter chain with the filters mentioned in url-pattern first, the last filter in this chain constructed with url-pattern invokes the servlet(the servlet can also be chained and the chain order is as per their declaration in deployment descriptor, but they are invoked only after all filter classes (url-pattern) are implemented !!! )

Pls read page num 678 IMPORTANT SECTION.


1.) -----------------------------------
<filter-mapping>
<filter-name>Filter1</filter-name>
<url-pattern>/Recipes/*</url-pattern>
</filter-mapping>
---------------------------------------


2.) -----------------------------------
<filter-mapping>
<filter-name>Filter2</filter-name>
<servlet-name>/Recipes/HopList.do</servlet-name>
</filter-mapping>
---------------------------------------


3.) -----------------------------------
<filter-mapping>
<filter-name>Filter3</filter-name>
<url-pattern>/Recipes/Add/*</url-pattern>
</filter-mapping>
---------------------------------------

4.) -----------------------------------
<filter-mapping>
<filter-name>Filter4</filter-name>
<servlet-name>/Recipes/Modify/MoRecipes.do</servlet-name>
</filter-mapping>
---------------------------------------

5.) -----------------------------------
<filter-mapping>
<filter-name>Filter5</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
---------------------------------------

Consider this Request Path: /Recipes/HopsReport.do


The url-pattern matching this path is 1.) & 5.)

the servlet-name matching this path is, 2.)

As per the above rule stated, the sequence would be first all filters mentioned in url-pattern and then the serlet-name

So the filter chain sequence is : 1.) 5.) 2.) even though 2.) is declared before 5.) in the descriptor.



Hope that helps,


Regards,
Reshma
joko mujoko
Ranch Hand

Joined: May 30, 2006
Posts: 30
Thanks Reshma, now I closed the tread

Joko
Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
Thanks joko mujoko.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter Chain.
 
Similar Threads
Acegi Configuration
Filter has Exclude url-pattern ?
No bean named '' is defined
Confused about doFilter() - Filters and Wrappers Mock in HFSJ
Interrupting a filter