xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

GuiceFilter/ServletModule does not support filters that wrap the request or response #648

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The GuiceFilter class stores the HttpServletRequest and HttpServletResponse 
objects in a threadlocal variable (localContext) when the GuiceFilter instance 
is invoked at the start of request processing.

The InternalServletModule class then defines provider methods to support 
"@Inject HttpServletRequest" and "@Inject HttpServletResponse" by fetching data 
from GuiceFilter.localContext.

However it is possible (and in fact quite common) for filters to create wrapper 
objects for HttpServletRequest and HttpServletResponse and pass these down to 
later filters + servlet.

Classes that let Guice inject the request and response objects currently always 
get the original objects not the wrapped ones, because GuiceFilter.localContext 
is never updated. 

At the very least, this is surprising and should be well documented in 
GuiceFilter and in ServletModule. However IMO it would be nicer for the 
FilterPipeline implementation to update GuiceFilter.localContext when an 
invoked filter wraps the request or response.

Original issue reported on code.google.com by simon.ki...@airnz.co.nz on 19 Aug 2011 at 1:32

GoogleCodeExporter commented 9 years ago
It's a very serious bug, I'm using few filters that well, actually filter the 
response, change it as needed, but with GuiceFilter it doesn't seem to work. I 
really want to have my filters (that don't need any injections) in web.xml

Original comment by Krzyszto...@gmail.com on 25 Aug 2011 at 8:40

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 27 Sep 2011 at 5:01