Win a copy of Fixing your Scrum this week in the Agile 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic