Results 1 to 6 of 6
  1. #1
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    46
    Rep Power
    0

    Default Query about wrapper class

    Hi All,

    I am trying to understand the use of wrapper class. I am using filter example and here is a sample code

    Filter Class
    Java Code:
    public class XssFilter implements Filter {
         public void doFilter(ServletRequest request,
    			ServletResponse response, FilterChain chain)
    			throws IOException, ServletException {		
    		chain.doFilter(new XssRequestWrapper((HttpServletRequest)request), 
    				response);		
    	}	
    }
    Wrapper Class
    Java Code:
    public final class XssRequestWrapper extends HttpServletRequestWrapper {
         public String[] getParameterValues(String paramString) {
              //do something
         }
         
         public String getParameter(String paramString) {
              //do something
         }
    
         public String getHeader(String paramString) {
              //do something
         }
    }
    If we have mapping for '/*' to call this filter then how it works. Will it call all three get methods in wrapper class or we have to expilicty call one we have to use?

    Thanks
    Last edited by anjibman; 12-11-2012 at 09:29 PM.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Query about wrapper class

    From your code above we don't know whether it call one, two or three methods you defined above. Because we can only see that you create a new instance of XssRequestWrapper which extends HttpServletRequestWrapper. Unless we know what both of this class do then we cannot tell anything. But because you might have to code there you can see what is happening there. Take a look starting from the XssRequestWrapper constructor.

  3. #3
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    46
    Rep Power
    0

    Default Re: Query about wrapper class

    When I debug the program what I saw was getHeader() and getParameter() methods are automatically called without being called explicitly in a code.
    So I am trying to understand why this happen. I don't have any thing extra in XssRequestWrapper constructor rather than a single line to call super(request).
    Can anyone elaborate why this happening?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Query about wrapper class

    I don't have any idea because I don't know what is in that classes. What part of library if these classes? If it is an open source library then you'd better check to see the source code.
    Last edited by wsaryada; 12-12-2012 at 02:35 PM.

  5. #5
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    46
    Rep Power
    0

    Default Re: Query about wrapper class

    No this is similar to this example

  6. #6
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Query about wrapper class

    Quote Originally Posted by anjibman View Post
    When I debug the program what I saw was getHeader() and getParameter() methods are automatically called without being called explicitly in a code.
    So I am trying to understand why this happen. I don't have any thing extra in XssRequestWrapper constructor rather than a single line to call super(request).
    Can anyone elaborate why this happening?
    Basically, the Filter that you create will be executed before your application read the http headers or the http parameters. As you can see when you call the doChain() method in the filter you wrap the servlet request with the XssRequestWrapper. This mean that to actual HttpServletRequest read by your application is wrapped in XssRequestWrapper. So the call to HttpServletRequest.getParameter() in your application will actually call the XssRequestWrapper.getParameter().

Similar Threads

  1. Simple jdbc wrapper showing query timings on a web page
    By rnentjes in forum Reviews / Advertising
    Replies: 1
    Last Post: 06-21-2012, 05:43 AM
  2. Need help with java wrapper class.
    By zeal3 in forum New To Java
    Replies: 1
    Last Post: 10-07-2009, 06:59 AM
  3. Yet another Wrapper Class confused guy.
    By JAdeline in forum New To Java
    Replies: 2
    Last Post: 08-15-2008, 04:04 AM
  4. Wrapper Class
    By haiforhussain in forum New To Java
    Replies: 6
    Last Post: 06-24-2008, 08:08 AM
  5. problem in wrapper class
    By binoympappachen in forum New To Java
    Replies: 4
    Last Post: 12-13-2007, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •