Expand my Community achievements bar.

Who Me Too'd this topic

Avatar

Level 2
I have need to build a JSON representation of the content hierarchy represented in AEM.

I'm trying to use the SlingRequestProcessor to return the rendered JSON of a target page as a string I can use to insert into a larger JSON object.

I'm finding that the SlingRequestProcessor works as intended when retrieving the HTML representation of a page, but does not return anything when requesting a JSON response for the same page:

This example returns the HTML of the page correctly:

SlingRequestProcessor requestProcessor = sling.getService(SlingRequestProcessor.class); RequestResponseFactory requestResponseFactory = sling.getService(RequestResponseFactory.class); HttpServletRequest servrequest = requestResponseFactory.createRequest("GET", "/content/geometrixx-media/en/entertainment.html"); ByteArrayOutputStream servout = new ByteArrayOutputStream(); HttpServletResponse servresponse = requestResponseFactory.createResponse(servout); requestProcessor.processRequest(servrequest, servresponse, resourceResolver); String servhtml = servout.toString();

 

But the following example returns only an empty string:

 

SlingRequestProcessor requestProcessor = sling.getService(SlingRequestProcessor.class); RequestResponseFactory requestResponseFactory = sling.getService(RequestResponseFactory.class); HttpServletRequest servrequest = requestResponseFactory.createRequest("GET", "/content/geometrixx-media/en/entertainment.json"); ByteArrayOutputStream servout = new ByteArrayOutputStream(); HttpServletResponse servresponse = requestResponseFactory.createResponse(servout); requestProcessor.processRequest(servrequest, servresponse, resourceResolver); String servhtml = servout.toString();

 

I used the geometrixx site as an example, but in my real use-case the target page has a json.jsp in its component that creates a custom JSON response when accessed (eg. /content/geometrixx-media/en/entertainment/jcr:content.json)

I'm not sure why the above does not work for a JSON response.

Who Me Too'd this topic