Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why would you extend HttpServletRequestWrapper

 
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading through the source code of JForum.

I'm going through net.jforum.context.web.WebRequestContext.

The class extends HttpServletRequestWrapper.

My questions are,

1) What would be the purpose of extending HttpServletRequestWrapper ?

2) Why would you need HttpServletRequestWrapper in the first place ?

and last, Why would you need object request parameters where you can just use request attributes ?

 
Rancher
Posts: 43026
76
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

That's a good question. From the javadocs: Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.. If there are things you find yourself frequently doing in a web app with respect to the methods of (Http)ServletRequest, you can instead extend HttpServletRequestWrapper to put those functionalities in a single place and be assured they will have been done by the time you get a HttpServletRequest in your servlet.

Looking at that particular example, the two main areas seem some support for multi-part requests (i.e., file uploads, which HttpServletRequest makes awkward to use without the help of a library like Apache Commons FileUpload) and support for MODULE and ACTION parameters (which is part of JForum's way of routing incoming requests to Java code for handling them; that ties in with the modulesMapping.properties and urlPattern.properties files). There are also some other useful extensions, e.g. the getRemoteAddr method knows about the "x-forwarded-for" header convention - something the standard implementation doesn't.
 
Adam Hun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf Dittmer. Now I understand this better
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic