On May 18, 2009, at 2:32 PM, Fabio Mancinelli wrote:
I am spending some time on it and currently I am exploring the
following solution: declare every resource as a @Component and use
the component manager for discovering resources (via the lookupList
method). This will solve the problem of modifying the web.xml and
adding a set of resources will be just a matter of dropping a jar in
WEB-INF/lib.
...
I hope to have a working thing by the end of the day
Hi everybody.
I managed to implement what I was proposing.
* Now every JAXRS entity (i.e., resource, provider or exception
mapper) is declared as a component having the role defined by the
XWikiRestComponent interface.
* The component manager is used to lookup all the components
implementing that role for registering them.
* A custom factory is used for instantiating components when JAXRS
requests them. Instantiation, of course, is a lookup using the
component manager.
* Component deallocation is done seamlessly.
Now, in order to extend the REST Api you just need to write a
@Component annotated class that Implements XWikiRestComponent (or
extends XWikiResource in order to have for free all the relevant
variables for interacting with the wiki). The only constraint is that
the hint of the @Component must be the fully qualified name of the
annotated class (this is needed because of the lookup logic).
Of course a META-INF/components.txt listing all the @Component classes
should also be packaged in the jar.
Once you have such a jar, you just throw it in WEB-INF/lib and you
have your resources published (no need to edit web.xml anymore)
Cheers,
Fabio
P.S. : You can see the example here :
http://pastebin.com/m2187c62a