consume JSON from REST API

Options
sspiros
edited February 11, 2022 in Analytics #1
<div>Hi,</div><div> </div><div>I am trying to design a report that gets JSON data from a RESTful resource. As far as I understood natively this option isn't available and I have to rely on external classes. I came across <a data-ipb='nomediaparse' href='http://stackoverflow.com/questions/14228131/how-can-i-import-json-data-from-a-rest-api-into-bir'>this suggestion</a>. I built the necessary jars (basic and dependencies), created a scripted datasource modified the open script then a dataset with fetch script but I cannot get it to work no matter what. All of the time I get the following error:</div><div><pre class="_prettyXprint">...................A BIRT exception occurred. See next exception for more information.Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id=&quot;83"]/method[@name=&quot;open"]#5) Script source: /report/data-sources/script-data-source[@id=&quot;83"]/method[@name=&quot;open"], line: 0, text:__bm_OPEN(). (Element ID:1)at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:99................................... </pre></div><div>(I included the most important part of the message)</div><div> </div><div>1) So what is the cause of such an error? Not loading the class properly?</div><div>   I tried to load the resource from the property box</div><div>   I tried to load the external jars in the classpath</div><div>   I copied the inside the scriptlib folder</div><div>   Nothing worked.</div><div> </div><div>2) In the open script is necessary to import explicitly all of the dependencies of the target class (despite the fact that the java source code does it already)?</div><div> </div><div>3) Is there any other way to achieve my objective? (I am banging my head for a couple of days now.....)</div><div> </div><div>Thanks in advance</div>

Comments

  • kclark
    kclark E
    edited November 4, 2013 #2
    Options
    <p>What version of BIRT are you using?  I recently built a pojo that got JSON from REST and it worked well for me.  Can you attach the rptdesign for me to take a look at?</p>
    Warning No formatter is installed for the format ipb
  • sspiros
    edited November 6, 2013 #3
    Options
    <p>Hi,</p><p> </p><p>I am using version 3.7.2. (The .rptdesign is supposedly reads a json from a local host...)</p>
  • <p>Hi Kristopher,</p><p> </p><p>I am also trying to use REST API Data Source in my report. I came across this Dev Share -</p><p> </p><p><a data-ipb='nomediaparse' href='http://www.birt-exchange.org/devshare/_/designing-birt-reports/1561-rest-api-oda-plugin-for-birt'>http://www.birt-exchange.org/devshare/_/designing-birt-reports/1561-rest-api-oda-plugin-for-birt</a></p><p> </p><p>I did the same as per the above link and everything works well for the examples they provided.</p><p> </p><p>But when I try to use  my own JSON response, it is giving ODA Exception</p><p> </p><div>[color=#ff0000;]org.eclipse.datatools.connectivity.oda.OdaException ;[/color]</div><div>[color=#ff0000;]    java.lang.NullPointerException[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.oda.profile.OdaConnectionWrapper.open(OdaConnectionWrapper.java:215)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.oda.profile.OdaConnectionWrapper.<init>(OdaConnectionWrapper.java:59)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.oda.profile.OdaConnectionFactory.createConnection(OdaConnectionFactory.java:26)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSourceWizardPageCore$1.run(DataSourceWizardPageCore.java:244)[/color]</div><div>[color=#ff0000;]at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.ui.wizards.ConnectionProfileDetailsPage.testConnection(ConnectionProfileDetailsPage.java:194)[/color]</div><div>[color=#ff0000;]at org.eclipse.datatools.connectivity.ui.wizards.ConnectionProfileDetailsPage$2.widgetSelected(ConnectionProfileDetailsPage.java:131)[/color]</div><div>[color=#ff0000;]at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)[/color]</div><div>[color=#ff0000;]at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)[/color]</div><div> </div><div> </div><div>Is  this RESTAPI plugin provided in the Dev Share is usable? Is there any other way I can use RESTAPI-JSON in BIRT.</div><div> </div><div>I am using the latest version of BIRT 4.3 in Jboss Studio(Kepler).</div><div> </div><div>Any help is much appreciated..</div><div> </div><div>Regards,</div><div>Priya</div>
  • <p>Forgot to mention. My sample result when I execute the url <a data-ipb='nomediaparse' href='http://localhost:8080/dc-bus-rest-service/v1/persons'>http://localhost:8080/dc-bus-rest-service/v1/persons</a> in browser is below.</p><pre>{"data":[{"id":0,"name":"com.dc123.i18n.contacts","description":"com.dc123.i18n.contacts","code":"CONTACTS","compositeType":"com.dc123.framework.rest.types.CompositeGroup","facts":[]},{"id":1,"name":"PRIMARY_ATTRIBUTES","description":"PRIMARY_ATTRIBUTES","code":"PRIMARY_ATTRIBUTES","compositeType":"com.dc123.framework.rest.types.CompositeGroup","facts":[]},{"id":2,"name":"PA_BIRTHYEAR","description":"PA_BIRTHYEAR","code":"PA_BIRTHYEAR","compositeType":"com.dc123.framework.rest.types.AttributeCategory","facts":[]},{"id":3,"name":"PA_NAME","description":"PA_NAME","code":"PA_NAME","compositeType":"com.dc123.framework.rest.types.AttributeCategory","facts":[]},{"id":4,"name":"PA_POSTCODE","description":"PA_POSTCODE","code":"PA_POSTCODE","compositeType":"com.dc123.framework.rest.types.AttributeCategory","facts":[]},{"id":5,"name":"SocialPropertyToday","description":"SocialPropertyToday","code":"SPT","compositeType":"com.dc123.framework.rest.types.Domain","facts":[]},{"id":101,"name":"com.dc123.i18n.listings.placed","description":"com.dc123.i18n.listings.placed","code":"LISTING_PLACED","compositeType":"com.dc123.framework.rest.types.CompositeGroup","facts":[]}]}</pre><p>[color=#000000;]Regards,[/color]</p><p>[color=#000000;]Priya[/color]</p>
  • <div>Hi Priya,</div><div> </div><div>I ve been recently using that plugin for json consumption in a RESTful way. Honestly it is the only solution that has worked so far.</div><div>When dataset is simple (just a selection of table and columns) everything is ok. However when I am trying to create a joined dataset everything just hangs. Just out of curiosity I waited and it took ten minutes for the eclipse suite to unfreeze. If I wanted to add a filter another ten minutes... So creation and editing of the joined dataset is nearly impossible. (Total records are 120 lines of 4 columns, nothing that much..).</div><div> </div><div>Keep in mind that the json answer cannot be flat</div><div>for example </div><div> </div><div>{ "name" : "George"</div><div>  "position" : "CTO"</div><div>}</div><div> </div><div>should be transformed to</div><div>{ "table_name":[</div><div>    {"name" : "George"</div><div>     "position" : "CTO"},</div><div>    {.....}   ]</div><div>}</div><div> </div>
  • <p>Using the out of the box XML or Web Service ODA, or use a scripted data source to get the JSON string. just get the result, and run it through an old school eval() statement. Don't try to parse it with the out of the box ODA's, you'll drive yourself crazy.</p><p> </p><p><a data-ipb='nomediaparse' href='http://digiassn.blogspot.com/2013/08/birt-using-json.html'>http://digiassn.blogspot.com/2013/08/birt-using-json.html</a></p&gt;
    Warning No formatter is installed for the format ipb
  • Hi All,
    I am struggling through this today. The link Priya shared(http://www.birt-exchange.org/devshare/_/designing-birt-reports/1561-rest-api-oda-plugin-for-birt) is no longer accessible.

    I tried the plugin shared on this link(https://communities.opentext.com/forums/discussion/61303/rest-api-oda-plugin-for-birt).

    But when creating datasource from the rest api endpoint, and testing the connecting it gives ping failed error message accompanied by the following:

    Caused by: java.lang.NullPointerException
    
    at org.eclipse.birt.report.data.oda.restapi.impl.Connection.open(Connection.java:50)
    
    at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250)
    

    Do any of you have any solutions? Thanks in advance.