java - Read HTTPServletRequest's POST body AND then call getParameter in Tomcat -
i in situation application needs inspect content/data/body/payload of post request without changing results of subsequent getparameter calls.
reading body inputstream:
the body can read using inputstream request.getinputstream
or bufferedreader request.getreader
.
reading post parameters:
post requests typically include request parameters in body of request. these can retrieved using getparameter
.
the problem:
the first getparameter
call internally parses inputstream , inserts parameters parameter hashmap. requires inputstream still contain contents parsing. 1 cannot inspect content , still have working getparameter call.
proposed (but not sufficient) solution
create request wrapper caches inputstream , returns cache getinputstream.
i've seen solution suggested on web, doesn't work, because getparameter
doesn't call getinputstream
, refers original inputbuffer buried in request object. i've tried it, both within servlet , using filter
the solution can think of involves rewriting getparameter parse cached inputstream manually. feels bad idea.
does have alternative works? (this tomcat 5.5) feels should common use-case; can't believe how difficult is.
(that's rather old tomcat, i'm assuming upgrading more modern 1 isn't option.)
what want require intercepting construction of concrete httpservletresponse object wrapping underlying inputstream. wrapping inputstream in push-back input stream (or equivalent) necessary.
tomcat 5.5 old can't think how accomplished 'normally', perhaps write filter uses reflection reach in , swap inputstream object inside concrete request object.
Comments
Post a Comment