passing header info while using new net.sf.jasperreports.engine.data.JsonDataSource as a datasource

0

Hi,

We are using REST endpoint as datasource for jasper reports.

 

but everywhere using RESTPOINT its mandatory to create an adapter with rest url and header info and use that as datasource.

We dont want to use adpapter , we want to use new  net.sf.jasperreports.engine.data.JsonDataSource constructor 

public JsonDataSource(String location, String selectExpression) throws JRException  as a dataset expression so we formed expression as follow.

new  net.sf.jasperreports.engine.data.JsonDataSource("http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D...","value") , but this particular endpoint expects some header information from requestor ("Accept", "application/json") else it throws bad exception as error, is there any way we can pass header info here?

 

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: new  net.sf.jasperreports.engine.data.JsonDataSource("http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D...","value")
    at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:551)
    at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$18(ReportController.java:526)
    at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:444)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: new  net.sf.jasperreports.engine.data.JsonDataSource("http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D...","value")
    at net.sf.jasperreports.engine.fill.JREvaluator.handleEvaluationException(JREvaluator.java:284)
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:316)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:673)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:641)
    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1169)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:522)
    at net.sf.jasperreports.components.table.fill.FillTableSubreport.evaluateSubreport(FillTableSubreport.java:105)
    at net.sf.jasperreports.components.table.fill.FillTable.evaluate(FillTable.java:133)
    at net.sf.jasperreports.engine.fill.JRFillComponentElement.evaluate(JRFillComponentElement.java:110)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2583)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:813)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:264)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:110)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
    at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:135)
    at java.lang.Thread.run(Thread.java:748)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D....
    at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:139)
    at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:51)
    at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:196)
    at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:195)
    at net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:172)
    at net.sf.jasperreports.engine.util.JsonUtil.parseJson(JsonUtil.java:172)
    at net.sf.jasperreports.engine.data.JsonDataSource.<init>(JsonDataSource.java:143)
    at net.sf.jasperreports.engine.data.JsonDataSource.<init>(JsonDataSource.java:138)
    at net.sf.jasperreports.engine.data.JsonDataSource.<init>(JsonDataSource.java:151)
    at WindchillTrustedAuth_1609234588892_992625.evaluate(WindchillTrustedAuth_1609234588892_992625:212)
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:302)
    ... 16 more
Caused by: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D....
    at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:343)
    at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:122)
    ... 26 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/trustedAuth/servlet/odata/D...
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
    at java.net.URL.openStream(URL.java:1045)
    at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:339)
    ... 27 more
 

Please let us know how we can handle this situation?

ujadhav's picture
Joined: Apr 12 2019 - 1:30am
Last seen: 3 months 1 week ago

0 Answers:

No answers yet
Feedback
randomness