wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Regarding filter invocation 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 "Regarding filter invocation" Watch "Regarding filter invocation" New topic
Author

Regarding filter invocation

Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

Filters are invoked in the order of their registration BUT is it not wrong to
say that filter are called in the order they appear in th DD ( bec' filters with <url-pattern>
are invoked before filter with <servlet-name>) ?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1647
    
  25

Hi Simran,

It is a bit more subtle: if there are let's say two filters defined on the same servlet: then they will be invoked in the same order of how they are ordered in the deployment descriptor (web.xml). But that requirement comes after the fact of <url-pattern> before <servlet-name>

See the servlet spec explanation:
SRV.6.2.4 Configuration of Filters in a Web Application
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.

Regards,
Frits
Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

Exactly.

But the problem is I found a the foll Q in M.Green-


Filters are called in the order they appear in the DD.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Simran, that option in Marcus' exam is ambiguous. Filters are called in the order they appear in web.xml but its like a two time pass. First filters are invoked based on url-pattern and then servlet-name. So for the real exam the statement would be false...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding filter invocation
 
Similar Threads
filter-mapping order
filter mapping
Deployment Descriptor web.xml
Container rules for ordering filters
Filter Sequence issue