New issue 618 by mccu...@gmail.com: Make guice-servlet more adaptable
http://code.google.com/p/google-guice/issues/detail?id=618
We're using guice-servlet in a multi-injector scenario where we want to
chain the different filter/servlet pipelines under a single instance of a
subclass of GuiceFilter. To get this working without co-locating our custom
filter under the same package as GuiceFilter we need to make a couple of
visibility changes (including removing final from an injected field).
The attached patch contains the necessary changes, comments welcome :)
Attachments:
GUICE_SERVLET_CODE_VISIBILITY.patch 1.6 KB
Can you describe a little more about what the end goal is?
Basically we have multiple injectors (each one with servlet modules) and
every injector should participate in filtering/serving up content. So any
incoming request should be passed onto each injector pipeline in turn,
finally delegating to the static web.xml (ie. much like the single injector
case, but abstracted over multiple injectors).
So 1) we want to (re)set the injected pipeline in the GuiceFilter subclass
to use our chained implementation
... and 2) we want to provide our own implementation of FilterPipeline, so
we need access to the interface
This is the cleanest way we've found to use guice-servlet in a
multi-injector scenario.
Comment #3 on issue 618 by sberlin: Make guice-servlet more adaptable
http://code.google.com/p/google-guice/issues/detail?id=618
Isaac, I think you made some changes relating to this. Can you help Stuart
out here & figure out the best way to do this (which may mean applying the
patch)?
Instead of changing visibility, can you instead create a composite Filter
that chains the individually created GuiceFilters together?
new ChainedFilter(
injector1.getInstance(GuiceFilter.class),
...
injectorN.getInstance(GuiceFilter.class));
Unfortunately that won't work for our use case, which involves dynamic
injectors that can be added/removed during the lifetime of the application.
We also want to consider all the injected pipelines before finally falling
back to the static filter chain.
Btw, with the recent changes to trunk we now only require two trivial
changes to the servlet extension:
1) make the FilterPipeline interface public
2) make the GuiceFilter(FilterPipeline) constructor protected
with these simple changes we can customise the pipeline to properly handle
our dynamic environment.
This issue really needs to be fixed. As comment 5 states, with the October
2011 changes, making FilterPipeline public and the
GuiceFilter(FilterPipeline) constructor visible (ideally public, but
protected is workable as well) is sufficient.
The JVM-scope staticness (actually, classloader-scope staticness) of
GuiceFilter is a real blight on the library. The code is in place to not
rely on it accept for backwards compatibility (i.e., dynamic
filterpipelines are supported; the constructor is just not visible). Please
make it visible.
Almost a year and still open? Do I need to fork the whole Guice Project?
A year has passed, and nothing happened... Is Guice a dead project!?