Container Module
![]() | Provides an abstraction of a Container (request, response, session) |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Table of contents
Description
The notion of Container complements the notion of Environment by adding the notions of Request, Response and Session.
Similarly to the Environment, the idea is to allow using XWiki libraries that require a Container to be executed transparently in various environments such as a Servlet environment, a Portlet environment and more. Currently, only a Servlet implementation is provided.
To get access to the Container implementation, you'd use the following in your code:
@Inject
private Container container;
See the javadoc for more details on the available APIs of that entry point, but the main goal is to allow accessing to the current Request, Response, and Session.
XWiki 17.0.0+ A lot of new APIs (inspired from Servlet APIs) have been added to Request, Response, and Session in order to reduce the need to cast them to their more specific form (generally the Servlet one).
If the generic API is not enough, and you need direct access to the jakarta.servlet (or javax.servlet in XWiki < 17) APIs, you can cast:
- org.xwiki.container.Request to org.xwiki.container.servlet.ServletRequest
- org.xwiki.container.Response to org.xwiki.container.servlet.ServletResponse
- org.xwiki.container.Session to org.xwiki.container.servlet.ServletSession
Session events
It's possible to receive, in a listener, events when a session is created and when it's destroyed:
- XWiki <17.0.0 org.xwiki.container.servlet.events.SessionCreatedEvent and org.xwiki.container.servlet.events.SessionDestroyedEvent
- XWiki 17.0.0+ SessionCreatedEvent and SessionDestroyedEvent are deprecated (like any javax.servlet.* based API) so it's recommended to use org.xwiki.container.servlet.events.HttpSessionCreatedEvent and org.xwiki.container.servlet.events.HttpSessionDestroyedEvent
Container Initialization
It's up to the environment in which the XWiki code runs to initialize the Container component. For the Servlet Container we provide, this is done in XWikiServletContextListener which is a Servlet Listener that needs to be registered in your web.xml as follows:
<listener>
<listener-class>org.xwiki.container.servlet.XWikiServletContextListener</listener-class>
</listener>