• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Container rules for ordering filters

 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

Could anyone tell me the difference between <url pattern> tag used by the container for filter chaining and that for request chaining.I mean container rules for ordering filters using DD differ those for request a little more insight.

Thankx,

Chaitanya.
 
srinath anand
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could not understand your question, can you clarify it a little bit ?
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand it correctly, there is nothing called Request Chaining. When a servlet is requested, the container uses the servlet mapping to pick the BEST(the one with the longest matching path/pattern) url-pattern.

However, the rules of filter mapping are a little different. The container uses the order in the deployment descriptor, <url-pattern>, and <servlet-mapping> to determine ALL filters that needs to be invoked. (there can be more than 1). Consequently, you have a chain of filters.
 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

However, the rules of filter mapping are a little different. The container uses the order in the deployment descriptor, <url-pattern>, and <servlet-mapping> to determine ALL filters that needs to be invoked. (there can be more than 1). Consequently, you have a chain of filters.

This is perfect.How do rules of filter mapping differ.From HFS I could not understand pg no 680 how the answers were given on pg no 695.

Appreciate guys,

SCJP (92%)
SCWCD (in progress)
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given: (in the same order)
1. <url-pattern>/Recipes/*</url-pattern>
2. <servlet-name>/Recipes/HopsList.do</servlet-name>
3. <url-pattern>/Recipes/Add/*</url-pattern>
4. <servlet-name>/Recipes/Modify/ModRecipes.do</servlet-name>
5. <url-pattern>/*</url-pattern>

Request Path:
1. /Recipes/HopsReport.do
Go down the list, only looking for <url-pattern> and determine if it matches the pattern or servlet name. You will get Filter1 and Filter5. Now go through the same list, top to bottom, to determine if any servlet names match. None do.

Try the rest.
 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Nitish,

Appreciate your time and effort man.

I can get #1,#4 and #5 but there is a little discrepancy for #2 and #3.

The answers given in the book as Filter Sequence are pg no 695
#2 given is 1,5,2 and
#3 given is 1,5,4.

But I would say Filter Sequence for,
#2 should have been 1,2 and
#3 should have been 1,4.

There is no need for 5 in either of the cases as they both have a perfect match in the DD.

Pls. clarify,

SCJP (92%)
SCWCD (in progress)
 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

Pls answer this question about filters and their calling sequence.
Apprecaite.
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding...
<url-pattern>/*</url-pattern>

Servlet(or filter) mapping rules are the same. Exact, Directory or Extension. "/*" is a classic example of Directory mapping, because it starts with a "/" and ends in a "*". Filter5 is basically mapped to everything in the web app directory. One can use this scenario in logging 'ALL' requests to a web resource.

I think now you should get the same answer, as HFS suggests.
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chaitanya ,

------------------------------------------------------------------------
There is no need for 5 in either of the cases as they both have a perfect match in the DD.
------------------------------------------------------------------------

Filters, unlike Servlets, are not about "perfect/exact" matches. Based upon request path, one can have more than 1 Filter in the chain.

~Cheers
 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx Nitish. Now I gotcha.Good thankx for the reply.Its clear now.Answers are correct too.

Appreciate your time and effort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic