• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Can we modify body of HttpServletRequest within filter

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...I have this requirement to modify the body(body contains an xml) coming within HttpServletRequest based on value of a header..Like if Header1 comes with vaue of Value1 within header then set a new attribute within xml coming in body and pass it along to servlet down the line. Is this doable if so can i do this within servlet filter? Or this manipulation of request within filters is not allowed?

Thanks
Kranthi
 
Saloon Keeper
Posts: 7389
170
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can do this in a filter using an HttpServletRequestWrapper. But are you sure you need to? Can't you attach the new data as a request attribute?
 
Sheriff
Posts: 22665
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree. While it's both possible and allowed, it should not be desired.
 
Saloon Keeper
Posts: 612
14
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the best way to do what he wants is instead of adding the new data the xml, he should add that new data as a new request attribute?
 
Tim Moores
Saloon Keeper
Posts: 7389
170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We don't know if it's the best way because we don't know enough about what needs to be accomplished. But using a request attribute rather than a wrapper is generally preferable, IMO.
 
reply
    Bookmark Topic Watch Topic
  • New Topic