RequestResponseFactory and FakeRequest
Hi,
We use the RequestResponseFactory to retrieve content from AEM inside an OSGi bundle:
The service is obtained through:
@Reference
private RequestResponseFactory requestResponseFactory;
And used like this:
final HttpServletRequest servletRequest = requestResponseFactory.createRequest("GET", path);
WCMMode.DISABLED.toRequest(servletRequest);
final ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream();
final HttpServletResponse servletResponse = requestResponseFactory.createResponse(responseOutputStream);
servletResponse.getWriter().flush();
byte[] content = responseOutputStream.toByteArray();
Most methods of the FakeRequest class return null; e.g. getHeader, getServerName.
FakeRequest seems to cause errors that normal requests don't, e.g.:
15.03.2018 11:22:30.322 *ERROR* [pool-5-thread-2] com.day.cq.wcm.tags.IncludeTag Error while executing script view.jsp
org.apache.sling.api.scripting.ScriptEvaluationException:
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463)
at com.day.cq.wcm.tags.IncludeTag.includeScript(IncludeTag.java:176)
...
Caused by: java.lang.UnsupportedOperationException: null
at com.day.cq.contentsync.impl.handler.util.FakeRequest$FakeHttpSession.getAttribute(FakeRequest.java:64)
at org.apache.sling.scripting.jsp.jasper.runtime.PageContextImpl.doFindAttribute(PageContextImpl.java:470)
at org.apache.sling.scripting.jsp.jasper.runtime.PageContextImpl.findAttribute(PageContextImpl.java:455)
at org.apache.jsp.apps.lgi_002dforms.components.forms.honeypot.honeypot_jsp._jspService(honeypot_jsp.java:122)
where honeypot_jsp.java:122 is:
currentNode = (javax.jcr.Node) _jspx_page_context.findAttribute("currentNode");
which is compiled from this line in the JSP:
<cq:defineObjects />
We use the RequestResponseFactory with the SlingRequestProcessor for ContentSync handler and a customer service that uploads pages to an FTP server. Should we use RequestResponseFactory for these or is there a better method? How can we work around the issues described above?
Linda