You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Andreas Schaefer <sc...@me.com> on 2017/10/02 16:56:31 UTC

Using MockSlingHttpServletRequest for in-Sling rendering causes issues with the Export Servlet

Hi

When I use the MockSlingHttpServletRequest to render a page with the Export Servlet
then I will get an Unsupported Operation Exception when the Export Servlet tries
to obtain the Reader from the request.

private void addScriptBindings(SlingScriptHelper scriptHelper, SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws IOException {
    SimpleBindings bindings = new SimpleBindings();
    bindings.put(SLING, scriptHelper);
    bindings.put(RESOURCE, request.getResource());
    bindings.put(SlingModelsScriptEngineFactory.RESOLVER, request.getResource().getResourceResolver());
    bindings.put(REQUEST, request);
    bindings.put(RESPONSE, response);
    bindings.put(READER, request.getReader());
    bindings.put(OUT, response.getWriter());
    bindings.put(LOG, logger);

    scriptEngineFactory.invokeBindingsValuesProviders(bindingsValuesProvidersByContext, bindings);

    SlingBindings slingBindings = new SlingBindings();
    slingBindings.putAll(bindings);

    request.setAttribute(SlingBindings.class.getName(), slingBindings);

}
I created a ticket for that:

https://issues.apache.org/jira/browse/SLING-7174 <https://issues.apache.org/jira/browse/SLING-7174>

That said I would suggest to separate the testing implementation from the usage to render page in-sling
as the purpose did and probably will clash in the future.

Cheers - Andy Schaefer