Hi everyone,
We decided in Introduce new jakarta servlet related APIs to deprecate the current (javax) servlet related APIs.
In this proposal, I would like to discuss new ways to access the HttpServletRequest/Response.
The old ways
First, here are the current main ways to access the HttpServletRequest
(and it’s pretty much the same for the HttpServletResponse
):
- java
- through the
XWikiContext
- through
Container#getRequest()
which is then cast to aServletRequest
- through the
- scripting
- through the
$request
binding - through the
$xcontext.request
binding
- through the
Currently on Script side everything is manipulating servlet APIs, and we don’t have at all the generic concept of Request/Response we have on Java side. To be honest, we don’t really use that generic concept much in Java either (right now, the main use of org.xwiki.container.Request
is to be cast into a org.xwiki.container.servlet.ServletRequest
).
The new ways
Java
For the new servlet specific API I thought that it would be nice to simply (almost directly) inject the HttpServletRequest. In practice, you would use a Provider<HttpServletRequest>
(that would return null if there is no HttpServletRequest
in the current thread).
Script
For the script side, as discussed in the other forum thread, I believe we need to go through a service and not inject new bindings potentially colliding with variables. Here I’m hesitating between various possibilities:
- a servlet specific
$services.servlet.request/response
- generic
$services.container.request/response
like with haveorg.xwiki.container.Container
andorg.xwiki.container.Request
on Java side, and add the more specific
2.1.$services.container.servlet.request/response
2.2. or$services.container.request/response.servlet
Of course, those APIs would return something similar to ScriptXWikiServletRequest
(which add some protection for authors without programming right).
WDYT ? Any other ideas you think would be better ?