Hi,
I migrated my PermanentRedirect from web.xml to warp-servlet but it
now fails to run because:
1) Previously I had one PermanentRedirect instance per redirect. For
example: I had one instance to redirect from "/dog/*" to "/cat",
another one from "/fish/*" to "/dolphin", etc.
Each servlet init() would get different "source" and "target"
parameters and it would work fine.
2) Under the new mechanism, warp-servlet is using Injector to get an
instance of PermanentRedirect. As far as I understand, this means I no
longer have multiple instances of PermanentRedirect.
The more I think about this problem, the more I dislike the existing
implementation because it doesn't respect init() and destroy() for
request-scoped servlets, and it violates the principal of least-
surprise for non-guice servlets.
I don't understand how one can use binding annotations in this case. I
mean, I think I know how binding annotations work but it isn't clear
how this helps me in this case. Can you please give a short example?
On Jul 25, 7:57 pm, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> I deliberately did not make a per-servlet init and destroy because this
> violates the servlet lifecycle.
You might be referring to the fact that init() and destroy() are
supposed to be invoked once per servlet lifetime, across all threads,
but that's only because architecturally-speaking the container
instantiates one servlet and shares it between all requests. Nothing
prevents us from introducing an architecture where you have multiple
servlet instances. In that case you should be able to call init() and
destroy() once per instance over its lifetime without violating the
specification.
This is not how binding annotations work. Check out the example source
code for warp-servlet to see an example:
Line #31 - Usage of Key.get()
Line #53 - binding to annotation (in this case, @Named)
You can repeat the pair of lines 31 & 53 for as many different
annotations as you like with the same implementation class. Which
produces *different* singletons.
If the Guice user guide doesn't help you with binding annotations I
recommend Robbie's book.
Dhanji.
Gili