This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Filter chaining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Filter chaining " Watch "Filter chaining " New topic
Author

Filter chaining

Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Hi

Please explain Filter chaining mechanism. On which basis the filters are chained or on what basis the filters are organised in a chain sequence. HFSJ filter chaining whould be a great example to explain. Why the Filter5 is being called at 2nd number in 2nd and 3rd request path

Thanks


"Know where to find the solution and how to use it - that's the secret of success."
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
if you have more than one filter matching the requested url pattern in your web.xml then these will be invoked in order as these are defined in DD.

One more thing to add here is that if some filter is defined using <servlet-name> in it then it will be invoked lastly and if these are also multiple matching the same request url then same rule will be applied as above.
[ March 19, 2007: Message edited by: Ali Gohar ]
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Does <url-pattern> play any role in deciding filter sequence in chain.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think that Ali's previous post answers your question, doesn't it ?


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

[i]Servlet Specification[i]

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.
[ March 19, 2007: Message edited by: Satou kurinosuke ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Filter chaining