[xwiki-devs] Accessing the ExecutionContext from a Servlet
Hi devs, I'd need to access an instance of ExecutionContext from a Servlet within XWiki in order to perform XWiki operations from there (query, storage etc.). So far I tried to follow the same approach as the one I found in the XWikiRestetServlet : - XWikiRestletServlet.java http://bit.ly/TDcoQz - Utils.java http://bit.ly/UfNWa6 i.e. something like this: ComponentManager componentManager = (ComponentManager) getServletContext().getAttribute("org.xwiki.component.manager.ComponentManager"); Execution execution = componentManager.getInstance(Execution.class); ExecutionContext ec = execution.getContext(); XWikiContext xwikiContext = (XWikiContext) ec.getProperty("xwikicontext"); XWiki xwiki = xwikiContext.getWiki(); Unfortunately, while a proper Execution object is obtained indeed, the returned ExecutionContext remains desperately null. Do you see any configuration or annotation that may be missing ? Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ? Regards, Stéphane -- Ubimix - Give a new life to your content! http://ubimix.com Twitter: @ubimix
[...]
Unfortunately, while a proper Execution object is obtained indeed, the returned ExecutionContext remains desperately null. Do you see any configuration or annotation that may be missing ?
Ok, the XWikiContext needs to be initialized obviously; configuring an XWikiContextInitializationFilter in XWiki's web.xml makes it, the same way it does for the RestServlet and others.
Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ?
By digging into the xwiki-platform code, I found that a QueryManager can be accessed as follows, but I was wondering if there's a more easy way to know about the components exposed by the ComponentManager at hand ? componentManager.getInstance(QueryManager.class) Cheers Stéphane
On Fri, Aug 31, 2012 at 6:18 PM, Stéphane Laurière <slauriere@gmail.com> wrote:
[...]
Unfortunately, while a proper Execution object is obtained indeed, the returned ExecutionContext remains desperately null. Do you see any configuration or annotation that may be missing ?
Ok, the XWikiContext needs to be initialized obviously; configuring an XWikiContextInitializationFilter in XWiki's web.xml makes it, the same way it does for the RestServlet and others.
Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ?
By digging into the xwiki-platform code, I found that a QueryManager can be accessed as follows, but I was wondering if there's a more easy way to know about the components exposed by the ComponentManager at hand ?
componentManager.getInstance(QueryManager.class)
You mean knowing what's available without actually initializing it and getting an instance ?
Cheers
Stéphane
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
[...]
Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ?
By digging into the xwiki-platform code, I found that a QueryManager can be accessed as follows, but I was wondering if there's a more easy way to know about the components exposed by the ComponentManager at hand ?
componentManager.getInstance(QueryManager.class)
You mean knowing what's available without actually initializing it and getting an instance ?
That would be even better, but my basic need would be to know which component instances I can get for doing basic operations (discovery need). I just added a note about the QueryManager there : <http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HQueryingthedatamodel> A programmatic access to the potentially available component instances would help, that's all - or is there another way to discover all XWiki components ? In a second step, I guess we could describe the major ones and their use on the wiki. But a runtime list of all of them would be a good start for the developer to read their API. Btw is there a standard URL for accessing the complete and latest stable XWiki API ? Some links on the WritingComponents wiki page lead to http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core-context/apidocs/org... which seems outdated while on the other hand, there is http://maven.xwiki.org/site/docs/xwiki-javadoc-4.1.x/ but which URL to use for not having to update the wiki links everytime a new XWiki API is released ? Cheers Stéphane
[...]
Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ?
By digging into the xwiki-platform code, I found that a QueryManager can be accessed as follows, but I was wondering if there's a more easy way to know about the components exposed by the ComponentManager at hand ?
componentManager.getInstance(QueryManager.class)
You mean knowing what's available without actually initializing it and getting an instance ?
Actually yes, that's what I have in mind. Is there such a thing ? Or is it not meaningful ? Thank you! Stéphane
On Fri, Aug 31, 2012 at 7:11 PM, Stéphane Laurière <slauriere@gmail.com> wrote:
[...]
Another option I guess would be to lookup dedicated components for performing the queries and storage directly without going through an XWikiContext instance, but then what would be the proper way to discover all the components that are available from the ComponentManager (esp. query / storage) ?
By digging into the xwiki-platform code, I found that a QueryManager can be accessed as follows, but I was wondering if there's a more easy way to know about the components exposed by the ComponentManager at hand ?
componentManager.getInstance(QueryManager.class)
You mean knowing what's available without actually initializing it and getting an instance ?
Actually yes, that's what I have in mind. Is there such a thing ? Or is it not meaningful ?
If you know the role you can use ComponentManager#getComponentDescriptorList(Type role).
Thank you!
Stéphane
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
participants (2)
-
Stéphane Laurière -
Thomas Mortagne