Hi Caleb,
On Nov 7, 2012, at 2:41 PM, Caleb James DeLisle <calebdelisle(a)lavabit.com> wrote:
Hi,
I'd like to register servlets in the component manager and have them called by their
hint.
The oldcore struts servlet would be @Named("bin") and the rest servlet would be
@Named("rest")
Reasons to want to do this:
* There are things which are currently impossible without a servlet, things like REST,
GWT and WebDav.
REST and WebDAV for example can be done without needing a new Servlet by using a tighter
integration. I don't know enough about GWT to know if it's possible or not but I
guess it is too (at the expense or writing a bit more code since you'll need to call
some GWT APIs to do serialization/deserialization).
* If somebody has servlet code and they want to make
it run in XWiki, this is a real answer for them whereas "rewrite your app using XWiki
actions" isn't.
Indeed, and we've been waiting for Servlet 3.0 so far. Last time we checked it was
still to early to use Servlet 3.0 (see threads on markmail).
* Even if we had an Actions system which made it
*possible* to implement REST, GWT, and WebDav entry points, we would have to rewrite the
universe since all external libraries use Servlet.
* Web.xml is an eyesore, it's full of content which is the concern only of a
particular module, this could (mostly) be fixed by using injected servlets.
Indeed and Servlet 3.0 seems a good answer.
Now you're right that Servlet 3.0 doesn't support dynamic unregistration of
Servlets (only addition) so if we want to bring in servlets in an extension that's not
possible. This is also why I prefer the tight integration approach which doesn't have
this problem (i.e. do away with Servlets).
The big reason not to like it is because it could
undermine the proposal for Actions.
The JIRA issue for actions
http://jira.xwiki.org/browse/XWIKI-4713 was opened on January
1 of 2010.
It is stalled because nobody really knows how to make an abstraction which represents
Servlets or Portlets without any lost features.
I started the Action module and I didn't finish simply for lack of time. There's
no blocker. I wanted to finish the URL module before working on it again but I didn't
get the time to finish it either.
If we make it easier for servlets to be used, we might
begin down a slippery slope toward everything being done using servlets and then we lose
portlet compatibility.
But the alternative as I see it is to block progress in this direction and hope that
somebody steps up to implement Actions which are fully compatible with portlets and
servlets.
My take on Servlets within XWiki in general:
* We should not use Servlets when there are other ways of integrating external tools. When
possible a tighter integration should be chosen since it allows to use our development
practices with component injection and makes it simpler for deployment (removes the burden
to have to modify web.xml).
* Another reason for having only 1 entry point (or a minimal number of entry points) is
that defining more entry points is a pain for maintenance as we've been experiencing
over and over for the past years. The problem is that a new entry point means that you
need to duplicate all initialization of XWiki Context/Execution context for each incoming
request and this is tricky and all our entry points were doing it wrongly at some point
(case in point, Andreas just fixed 2 bugs yesterday where some threads were not cloning
the xwiki context). Yes we should be able to factor all this init in a common place (which
we almost have but in practice it doesn't seem to really happen for some reason).
Regarding your proposal:
* It seems a bit of hack to call a Servlet by doing a new on it. It goes against the
concept of Servlets actually which is supposed to be handled by the Container. More
generally what you propose is what OSGi is doing too:
-
http://www.peterfriese.de/osgi-servlets-a-happy-marriage/
-
http://felix.apache.org/site/apache-felix-http-service.html
The real questions for me are:
1/ Could you explain what's your actual use case so that we could discuss
alternatives, if any?
2/ Do we really want to support adding/removing servlets at runtime?
If the answer to 2/ is yes then your proposal is the only one I could see working indeed.
Regarding @Named("bin"), I think it would be good to review all our existing
URLs and verify it'll work. For example ATM we also have "skin" and
"skins" AFAIR which are currently handled by the same Servlet as "bin"
and thus we'd need to find a solution for this too + we need to review the GWT, WebDAV
URLs too.
It would also be nice for the xwiki URL module to be able to handle different URL formats
based on the "servlet/service" instead of the scheme being fixed for all which
is currently the case.
Thanks
-Vincent
WDYT?
Are there reasons not to do this which I missed?
Caleb