• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When to use HttpRequestWrapper?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When would it be appropriate to use a HttpRequestWrapper?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My favorite example is in using a wrapper to trim all of the request parameter values. It's easy for a user to accidently hit the space bar at the end of an entered number. This wrapper saves a lot of frustration!
 
Salvador Cecilio
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm didn't know you could modify parameters.

I'm looking at the API of the HttpRequestWrapper and would use the getParameter() method to access the parameter.

The question I have is how do you modify the parameter values when data has been submitted via querystring or posted.
 
Marshal
Posts: 28235
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just override the getParameter() method like this:
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a couple other methods that retrieve parameters that need to be covered as well, but that's the jist of it. I also like to hold a lazy map of the parameters in my wrapper so they only get trimmed once (and actually never get trimmed if you never ask for any parameters).
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Salvador Cecilio:
Hmmm didn't know you could modify parameters.

I'm looking at the API of the HttpRequestWrapper and would use the getParameter() method to access the parameter.

The question I have is how do you modify the parameter values when data has been submitted via querystring or posted.



As Paul shows, you don't actually change the parameters but by wrapping the request you make your application see the kind of values you want it to see. When the app asks the request for a parameter, it doesn't know that the request is wrapped and giving it a special, new-and-improved version of the original parameter.

Wrapping the request is like gold-plating costume jewelry. You're not changing the original product (only coating it), yet you fool everyone into thinking the product is better than it really is!
 
Salvador Cecilio
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:


As Paul shows, you don't actually change the parameters but by wrapping the request you make your application see the kind of values you want it to see. When the app asks the request for a parameter, it doesn't know that the request is wrapped and giving it a special, new-and-improved version of the original parameter.

Wrapping the request is like gold-plating costume jewelry. You're not changing the original product (only coating it), yet you fool everyone into thinking the product is better than it really is!




Yeah, that makes a lot more sense, and I thought I knew my decorator patterns.
 
reply
    Bookmark Topic Watch Topic
  • New Topic