How can I fetch the output in json format from DAM parent node to certain level | Community
Skip to main content
Adobe Employee
September 3, 2020
Solved

How can I fetch the output in json format from DAM parent node to certain level

  • September 3, 2020
  • 1 reply
  • 1293 views

I have requirement to get all the assets and its properties in .json format at certain level by URl as /content/dam/abc/a.1.json

I am able to get data using httpclient library by get call ,Is there any other way to fetch the data in json format as I don't want to pass username and password in get call

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nupur_Jain

Hi @ashishg1547773 

 

You can also use SlingRequestProcessor Library. It requires AEM system user to make a request similar to HTTP request. The system user must have access to path where you are making a request.

 

You can take a look at the sample code:

 

String assetUrl = assetPath + ".1.json"; HttpServletRequest request = requestResponseFactory.createRequest("GET", assetUrl); request.setAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME, WCMMode.DISABLED); ByteArrayOutputStream out = new ByteArrayOutputStream(); HttpServletResponse response = requestResponseFactory.createResponse(out); try { requestProcessor.processRequest(request, response, resourceResolver); String jsonString = out.toString(HQConstants.UTF_8_ENCODING); } catch (ServletException | IOException e) { }

 

Here, you need resourceResolver which must be of system user with right access rights. The above makes same request as HTTP request and as your requirment, does not need credentials.

 

Hope it helps!

Thanks!

Nupur 

1 reply

Nupur_Jain
Adobe Employee
Nupur_JainAdobe EmployeeAccepted solution
Adobe Employee
September 15, 2020

Hi @ashishg1547773 

 

You can also use SlingRequestProcessor Library. It requires AEM system user to make a request similar to HTTP request. The system user must have access to path where you are making a request.

 

You can take a look at the sample code:

 

String assetUrl = assetPath + ".1.json"; HttpServletRequest request = requestResponseFactory.createRequest("GET", assetUrl); request.setAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME, WCMMode.DISABLED); ByteArrayOutputStream out = new ByteArrayOutputStream(); HttpServletResponse response = requestResponseFactory.createResponse(out); try { requestProcessor.processRequest(request, response, resourceResolver); String jsonString = out.toString(HQConstants.UTF_8_ENCODING); } catch (ServletException | IOException e) { }

 

Here, you need resourceResolver which must be of system user with right access rights. The above makes same request as HTTP request and as your requirment, does not need credentials.

 

Hope it helps!

Thanks!

Nupur