• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Filter Chaning Query..!

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,

Can any one tell me the Filter ordering Sequence Fundamental. I did not understand It. I did not understand the Question and Answer Mentioned on Page 695 of hfsj.

Here's the Question :

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

<filter-mapping>
<filter-name>Filter2</filter-name>
<servlet-name>/Recipes/HopsList.do</servlet-name>
</filter-mapping>


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


<filter-mapping>
<filter-name>Filter4</filter-name>
<url-pattern>/Recipes/Modify/ModRecipes.do</url-pattern>
</filter-mapping>


<filter-mapping>
<filter-name>Filter5</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


Request Path


1)/Recipes/HopsReport.do
2)/Recipes/HopsList.do
3)/Recipes/Modify/ModRecipes.do
4)/HopsList.do
5)/Recipes/Add/AddRecipes.do

Filter Sequence

1)1,5
2)1,5,2
3)1,5,4
4)5
5)1,3,5

Can Any Body Please Explain me in Detail the Sequencing on this Filters for all 5 request Paths?

Regards,
Nilesh
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nilesh,
concept of order in which filters are invoked is clear in HFJS.
order of filters is based on two conditions :
first, container will consider filters in the order they are declared in DD.
second, container will put the filters that are declared with url pattern tag first into queue. then it will consider filters for specific match.
in the problem mentioned above, when container receive request for /Recipes/HopsReport.do, container will consider all filters whose url-patterns match with the requested resource. i.e. fillter 1 and filter 5. when container traverse through DD, it encounter filter 1 first. so filter 1 will be executed first.
consider, /Recipes/HopsList.do for this request, 3 filters do have match. filter 1, filter 2 and filter 5.
container will traverse through DD for matching url pattern and it finds filter 1 and filter 5. so these 2 are added into queue. againg container checks for specific match by comparing servlet name tag. it finds specific match with filter 2. filter 2 will be added to queue.
hence, the order in which filters are executed is filter 1, filter 5 and filter 2.

hope it will be clear now.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to make things simple, remember this -

filters are executed before the servlets
or to be more precise,
filters with <url-patterns> in their mapping are executed before those with a <servlet-name> in the mapping.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a little confused here. Is Filter Mapping mechanism different than the servlet mapping ?

Once it finds all the filters matching the url-pattern first, shouldn't it go by the exact match first ( the longest directory mapping) instead of ordering in the DD?
In /Recipes/Modify/ModRecipes.do,
it finds Filters 1, 5 and 4.
Because 4 is the exact match, that should be called first and then 1 and then 5.
So the ordering should be 4,1,5 instead of 1,5,4

Any thoughts? or is it yet another notorious Sun discrepencies?
 
Are we home yet? Wait, did we forget the tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic