This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doFilter doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doFilter doubt?" Watch "doFilter doubt?" New topic
Author

doFilter doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Guys,

The following piece of code is from the HFSJ book,

public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException{
HttpServletRequest request = (HttpServletRequest) req;
HttpSession session = request.getSession();
Object user = session.getAttribute("user");
if (user!=null){
UserRequest ureq = new UserRequest(request, user);
chain.doFilter(ureq, response); //Line 28
}else{
RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
rd.forward(request, response);
}
}

The questions, Which is true,

Five options were give, and I'm not able to understand the explanation given for the following option,

Line 28 is invalid because request must be passed as the first argument...and they have given the reason for this option as "it is valid for a filter to wrap a request (note that UserRequest must implement ServletRequest)

I'm not able to understand the bold part. Can anyone please explain!


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
You can wrap the request/response object in Filter before passing it on. doFilter takes ServletRequest and ServletResponse as an argument so you will have to extend your request/response wrapper class with these interfaces in order to pass them as arguments in doFilter method.

See Servlet 2.4 Specs page 52 "Wrapping Requests and Responses"
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Ali,

Can you please be a bit elaborate on this??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doFilter doubt?
 
Similar Threads
filter Q from HFSJ
Filters and GZip
chain.doFilter() being called twice.
Stream and writer
accessing a session attribute from a class that implements Filter