• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Can we modify body of HttpServletRequest within filter  RSS feed

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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: 5412
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 21719
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. While it's both possible and allowed, it should not be desired.
 
Ranch Hand
Posts: 380
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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: 5412
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
I AM MIGHTY! Especially when I hold this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!