-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Jose,
On 1/15/15 3:27 AM, Jose María Zaragoza wrote: > 2015-01-14 22:03 GMT+01:00 Christopher Schultz > <ch...@christopherschultz.net>: Jose, > > On 1/14/15 3:54 PM, Jose María Zaragoza wrote: >>>> 2015-01-14 20:05 GMT+01:00 Christopher Schultz >>>> <ch...@christopherschultz.net>: Jose, >>>> >>>> On 1/14/15 8:27 AM, Jose María Zaragoza wrote: >>>>>>> 2015-01-14 12:46 GMT+01:00 André Warnier >>>>>>> <a...@ice-sa.com>: >>>>>>>> Jose María Zaragoza wrote: >>>>>>>>> >>>>>>>>> Hello: >>>>>>>>> >>>>>>>>> I would like to create a web filter to forward >>>>>>>>> some requests to another webserver, >>>>>>>>> >>>>>>>>> The filter receives an >>>>>>>>> "application/x-www-form-urlencoded" request , >>>>>>>>> inspects the value of a parameter and chooses to >>>>>>>>> forward to another remote webserver ( as a proxy ) >>>>>>> >>>>>>> >>>>>>> Thanks >>>>>>> >>>>>>> I agree with you . I'll try to use an Apache httpd >>>>>>> front-end >>>>>>> >>>>>>> Anyway, I've seen that if I execute >>>>>>> >>>>>>> Map<String, String[]> parameter = >>>>>>> ((HttpServletRequest) request).getParameterMap(); >>>>>>> >>>>>>> , then request.getInputStream is empty >>>>>>> >>>>>>> >>>>>>> But if I execute >>>>>>> >>>>>>> Map<String, String[]> parameter = >>>>>>> ((HttpServletRequest) request).getParameterMap(); >>>>>>> chain.doFilter(request, response); >>>>>>> >>>>>>> , the next filter in the chain receives the body ( as >>>>>>> I expect it ) >>>>>>> >>>>>>> I don't understand this behaviour >>>> >>>> I think that might be a bug... calling >>>> HttpServletRequest.getParameter* should cause the request >>>> entity to be parsed, as long as the content type is >>>> application/x-www-form-urlencoded. I think getParameterMap >>>> counts, but I'd have to review the spec & javadoc (where some >>>> fun spec requirements are hidden!). >>>> >>>> Anyhow, when you call HttpServletRequest.getParameter*, the >>>> container *must* consume the request, according to the spec. >>>> >>>> >>>>> Thanks. >>>> >>>>> In my case, all requests to be forwarded are POST requests >>>>> ( and content type is application/x-www-form-urlencoded ) >>>>> According to your reply, if I've got a chain of filters and >>>>> the first one calls getParameterMap , do the next filters >>>>> lose the content of the payload ? > > Correct. Once the request entity has been read (which happens when > you call request.getParameter*), it's no longer available to the > application. > >>>>> I tested to call several times to getParameterMap method on >>>>> the same webfilter and it always returned the right values. >>>>> Looks like getParameterMap doesn't consume() payload, but >>>>> ... if I call getInputStream() after getParameterMap() , >>>>> the stream is empty >>>> >>>>> I'm using Tomcat 7.0.50 and I cannot understand the logic >>>>> of this > > Interesting. I find that surprising... I'll look into that. > > >> Some things are sure: > >> - getParameterMap() consumes the payload ( at least in POST >> application/x-www-form-urlencoded requests ) > >> - consecutives calls to request.getParameterMap() ( same filter >> or the next one ) always return the data. > >> So, looks like getParameterMap() implements some kind of cache I >> guess this is specific for servlet spec implementation in Tomcat >> , so it wouldn't be portable The first time HttpServletRequest.getParameter* is called, the container is required to parse the request. Losing the parameters after that would be a hideous bug. If you call getParameterMap() followed by getParameter(String), you'd expect that the second call would return the parameter value, wouldn't you? This is not some Tomcat-specific extension, but required by the spec. At this point, you've gotten way off your own topic. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: GPGTools - http://gpgtools.org iQIcBAEBCAAGBQJUt9M0AAoJEBzwKT+lPKRYwEcQAK3ep5USPlxtzHiFyZJWhmWk miRKX2FQsFv2/ZqX4xXnLBK+Sa2h6MpLlCazI12vFMBOrhS0crQDrwpHg+YBFZIK nFdObJ56Zst/NR9T5kxFX/3WqOXusAiZBTTBoKStndEvwONKPB9WUfPrQiLReFHH m9iCvLKBLrMqchCqpCwjdW+MCcVeyiElISrAS0eX4XzGWUojkox8/ItKbAdtaU/N /7j/S8aAp/TDyGIDDPsCTSX3uHSiReS87fswqtqIaHG4L9YreU4GEGN87UBgHhiX NeCM82gYVCtv2Pm0QZ5vmYEnuWc81AuPSiBxMhtB6pIxdtDgDEi5o9vuVGhXrIC+ tNV6Wj5nMBQlj6iXGUxFmx7w3M5AIKu5I6GVzrBiiSz3a5Ar5vVJMYTK+dOtP37W T+NjXegGKoyNYcgIaVWrPIJ/5+eCRRi1DRRIQh6IJZA99Na4TLhG14ASnm6FwWBx nQrkYKj/ru0LMdLU421W/wgxjD2Tzs3musLQTUKKdoxjN53em68JXybXh8KzRXHb eEWEHNGKXMD/8EGiRcfdX2/elvfQHL2l6QBxKqmtOkdjHNuNGbCu8rKG/Ny3mnw9 h+cNnOXnrgrUBBP/GF9aJWRJg/VyiMs0szqO0+cwVZSITsANjZ0nKLeJsptAy1Qk do3EqgdKjSornm5Z2INP =I68j -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org