Getting NullPointerException when trying to get the component report json output from Java | Community
Skip to main content
New Participant
February 2, 2017
Solved

Getting NullPointerException when trying to get the component report json output from Java

  • February 2, 2017
  • 10 replies
  • 3977 views

I create a component report and access it by http://localhost:4502/etc/reports/my-component-report.html. I can also get json output by http://localhost:4502/etc/reports/my-component-report/jcr:content/report.data.json.

I try to get this json output in Java and then to generate the excel file. However, I get the NullPointerException, see errors below:

GET /bin/excelreportservlet HTTP/1.1] com.day.cq.reporting.servlets.DataServlet Could not create report for report '/etc/reports/ryad-test-component-SECTION/jcr:content/report'
GET /bin/excelreportservlet HTTP/1.1] com.day.cq.reporting.servlets.DataServlet Stacktrace:
java.lang.NullPointerException: null
    at com.day.cq.reporting.impl.cache.CacheImpl$CacheKey.toString(CacheImpl.java:77)
    at com.day.cq.reporting.impl.cache.CacheImpl$CacheKey.hashCode(CacheImpl.java:64)
    at org.apache.commons.collections.map.AbstractHashedMap.hash(AbstractHashedMap.java:373)
    at org.apache.commons.collections.map.AbstractHashedMap.getEntry(AbstractHashedMap.java:433)
    at org.apache.commons.collections.map.LRUMap.get(LRUMap.java:174)
    at com.day.cq.reporting.impl.cache.CacheImpl.get(CacheImpl.java:242)

My code:

HttpServletRequest req = requestResponseFactory.createRequest("GET","/etc/reports/my-component-report/jcr:content/report.data.json");
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse resp = requestResponseFactory.createResponse(out);
Writer writer = response.getWriter();
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String jsonString = out.toString();

Above code works fine when the URL is "/etc/reports/my-component-report.-1.json".

Does anyone know how to get report json (/etc/reports/my-component-report/jcr:content/report.data.json) output in Java?

Thanks in advance for any information.

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 smacdonald2008

I found the OOTB to be not as good as writing your own service and driving the look and feel of the report through a custom service. I never had any issues writing a custom Java class that created reports of JCR data, 

10 replies

BigT168Author
New Participant
February 21, 2017

Thanks.

The customers are fine with the report output or they don't care the OOTB look and feel, just want to get the report as excel file. 

Anyway, looks like no other choice in this case.

 

Thanks again.

smacdonald2008
smacdonald2008Accepted solution
New Participant
February 17, 2017

I found the OOTB to be not as good as writing your own service and driving the look and feel of the report through a custom service. I never had any issues writing a custom Java class that created reports of JCR data, 

BigT168Author
New Participant
February 17, 2017

Thank you. I saw the code, eventually, I have to use the Jave Excel API to generate the excel from Json, 

The report json is out of box feature from adobe. Try to reuse what out there instead writing own code. Unfortunately it can't get the json in Java code. 

smacdonald2008
New Participant
February 16, 2017

Another option that you can look at using - I have done this for many custom tools that need to pull out JCR data out of AEM and then put into a spreadsheet for reporting purposes is to write a custom tool that queries data using JCR SQL2. Then use a Java Excel API to dynamically build the report and write out the data. We have an artilce of this. This works very nicely, 

https://helpx.adobe.com/experience-manager/using/java-swing-applications.html

BigT168Author
New Participant
February 16, 2017

smacdonald2008 wrote...

The Java logic works for this node? 

/etc/reports/my-component-report.-1.json

In the other location - is there any content at that location? 

 

Yes, it works for this path: /etc/reports/my-component-report.-1.json.

No other content, only the report. If I put the whole URL in browser, it works. Only when trying to access this using Java code, it is failed.

Thanks.

BigT168Author
New Participant
February 16, 2017

sandeepm744005 wrote...

Try passing this path - 

 

/etc/reports/my-component-report/_jcr_content/report.data.json

 

Thanks for response, however, I try it, this URL gives me the same NullPointerException and stop at the same place.

sandeepm744005
New Participant
February 3, 2017

Try passing this path - 

 

/etc/reports/my-component-report/_jcr_content/report.data.json

smacdonald2008
New Participant
February 2, 2017

The Java logic works for this node? 

/etc/reports/my-component-report.-1.json

In the other location - is there any content at that location? 

BigT168Author
New Participant
February 2, 2017

Not related to DTM. It is the AEM default reporting. https://docs.adobe.com/docs/en/aem/6-1/administer/operations/reporting.html.

 

Thanks.

jantzen_b
Employee
February 2, 2017

Hi,

Is this a question regarding Adobe's Dynamic Tag Managment solution? If so, can you clarify where you are getting this error? If the question was not around DTM, please let me know which solution the question matches best and I'll move the thread to the appropriate forum.

Cheers,

Jantzen