Hi all,

I am currently considering the microsling scripting helper class
discussed earlier and would like to gather some feedback on the contents
on this helper as well as other toplevel variables set on the response.

Currently the SlingScriptResolver provides the following variables:

    request - The HttpServletRequest
    response - The HttpServletResponse
    requestContext - The SlingRequestContext
    resource - The Resource, same as requestContext.getResource()
    script_path - The path of the script being executed

Furthermore, the ScriptHelper will be provided as the global variable
"sling" and provide the following:

    getRequest() - The HttpServletRequest
    getResponse() - The HttpServletResponse
    include(String path) - shortcut for
getRequest().getRequestDispatcher(path).include(...)

I would like to propose that we change this, in that we only provide
four global variables:

    request - The HttpServletRequest, shortcut for sling.getRequest()
    response - The HttpServletResponse, shortcut for sling.getResponse()
    sling - The ScriptHelper
    out - The PrintWriter, shortcut for sling.getResponse().getWriter()
    
The "sling" variable is the ScriptHelper providing access to the
request, response and hence the SlingRequestContext and thus (almost)
everything else available to normal Servlets being called. The request,
response and out variables are provided as a convenience to easily
access the request and response as well as the output writer using the
same well-known variables as available to JSP scripts.

Please note the "out" variable: This is set through the ScriptHelper
class which wraps the response to provide a on-demand writer, thus the
actual output channel writer is only acquired when something is written.
Therefore, the response variables also is set from the ScriptHelper
response wrapper to ensure to use the same response objects.

WDYT ?

Regards
Felix

Reply via email to