This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes filter-mapping doubt?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "filter-mapping doubt??" Watch "filter-mapping doubt??" New topic
Author

filter-mapping doubt??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Hi Ranchers,

I have the following doubt regarding filter-mapping

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


<filet-mapping>
<filter-name>Filter2</filter-name>
<url-pattern>/Recipes/HopsList.do</url-pattern>
</filter-mapping>


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


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


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

And the Request Path

/Recipes/HopsReport.do - The filter order is 1,5 - Makes sense

/Recipes/HopsList.do - The filter order is 1,5,2 - Confued on this. I'd say 2,1,5

Can anyone comment on the above Please!

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


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
S Kapoor
Greenhorn

Joined: Mar 31, 2006
Posts: 20
Filter mappings dont work like servlet mappings in that there is no order of preference for matches. The no1 is recipes/* and that is a match. Thats all it cares about. It is earlier in the DD and hence it is earlier in the filter invocation order.


SCJP, SCJWS, SCWCD
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
For /Recipes/HopsList.do it should be Filter1, Filter2 and then Filter5. The filters are chosen in order they are defined in Deployment Descriptor.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Ali,

But in the HFSJ book, it is given as 1,5,2. Is that an errata in the book itself??
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Similarily, for the /Recipes/Modify/ModRecipes.do, the options are given as 1,5,4...shouldn't that be 1,4,5?? Anyone please help me on this!
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
I don't have HFSJ so can't say anything about that. You should try to code yourself and check the results
[ February 08, 2007: Message edited by: Ali Gohar ]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Can anyone please confimr my doubt???
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
jothi, remember these two rules -

the container sees your filters as a set of two groups -
1. those having a <url-pattern> and
2. those having a <servlet-name>

the filters in group 1 are executed before those in group 2.
in both the groups the order of execution is the order in which they appear in the D.D

if you apply these rules to the HFSJ problem on page 695, the answers
1,5,2 and 1,4,5 are ( for cases 2 and 3 respectively )quite valid.

let me know if this is not sufficient.
niranjan8712@gmail.com
niranjan_8712@yahoo.com

hth


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Niranjan,

Can you please elaborate on this for me. I'm still not getting it. I appreciate your effort!
Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
Originally posted by Jothi Shankar Kumar Sankararaj:
Hi Ranchers,

I have the following doubt regarding filter-mapping

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


<filet-mapping>
<filter-name>Filter2</filter-name>
<url-pattern>/Recipes/HopsList.do</url-pattern>
</filter-mapping>


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


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


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

And the Request Path

/Recipes/HopsReport.do - The filter order is 1,5 - Makes sense

/Recipes/HopsList.do - The filter order is 1,5,2 - Confued on this. I'd say 2,1,5

Can anyone comment on the above Please!

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




Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Michael,

I really did understand your explanation. So as per what you said, first url-pattern is matched and the filters invoked in the order in which they are configured in the DD. Then it looks for filter-name that matches the url pattern and it invokes them as well in the order in which they are configured in the DD.

Thanks and I got it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter-mapping doubt??
 
Similar Threads
Doubt in HFSJ sharpen pencil page 695
order of filter mapping
unable to understand filter execution sequence
HFSJ filter-sequence doubt
Filter Q in HF Book