简体   繁体   English

带有宁静API的Birt

[英]Birt with restful APIs

I am developing BIRT reports for a PHP project. 我正在为一个PHP项目开发BIRT报告。 I can easily develop reports by connecting directly to the database using JDBC Datasource. 通过使用JDBC数据源直接连接到数据库,我可以轻松地开发报告。 However certain data come from restful api and I am unable to create a datasource from those api endpoints. 但是,某些数据来自宁静的api,而我无法从这些api端点创建数据源。

Birt has option to create datasource from web services, however this seems to only accept SOAP APIs. Birt可以选择从Web服务创建数据源,但是这似乎仅接受SOAP API。 I was wondering if someone can show me how to create birt datasources from REST APIs. 我想知道是否有人可以向我展示如何从REST API创建Birt数据源。 I read through all the search results provided by google. 我通读了Google提供的所有搜索结果。 Some recommend using POJO Datasource, while some recommend using scripted Datasource which requires knowledge in Java and which is little difficult for a PHP programmer to crack through. 一些建议使用POJO数据源,而另一些建议使用脚本化数据源,这需要Java知识,而PHP程序员很难破解。 Most links redirect to devshare which now points to open text and the content doesnot exist anymore. 大多数链接都重定向到devshare,后者现在指向打开的文本,并且内容不再存在。 I tried all the recommendations which are as follows. 我尝试了以下所有建议。

Using Webservices Datasource: It requires the location of wsdl file which is not there for a REST API. 使用Webservices数据源:它需要wsdl文件的位置,而REST API不在该位置。 It comes only with SOAP API. 它仅随SOAP API一起提供。 Would be great if there is an alternative to this. 如果有替代方法,那会很好。

Tried POJO Datasource and Scripted Datasource: But as a PHP developer couldn't get a good result as there is no step by step guide out there to do this. 尝试过POJO数据源和脚本化数据源:但是作为PHP开发人员无法获得良好的结果,因为那里没有逐步的指导来做到这一点。

Because REST is pretty popular today, I was wondering if there is any straight forward way to do this, or if there is anyone who can help with Java or Javascript program for scripted datasource for a PHP head. 因为REST在今天非常流行,所以我想知道是否有任何直接方法可以做到这一点,或者是否有人可以帮助Java或Javascript程序为PHP头提供脚本化数据源。 I have been trying this for the last 15 days and is desperate for some help. 在过去的15天里,我一直在尝试这种方法,非常希望获得一些帮助。

Ended up with scripted datasource. 最终获得了脚本化数据源。

Create a scripted datasource with open() method as follows: 使用open()方法创建脚本化数据源,如下所示:

logger = java.util.logging.Logger.getLogger("birt.report.logger");

importPackage(Packages.java.io);
importPackage(Packages.java.net);

//if you have a parameter
var param= params["industryname"].value;

var inStream = new 
URL("http://yourapi/endpoint/" + param).openStream();
var inStreamReader = new InputStreamReader(inStream);
var bufferedReader = new BufferedReader(inStreamReader);
var line;
var result = "";

while ((line = bufferedReader.readLine()) != null)
result += line;
inStream.close();

var json = JSON.parse(result);
vars["HTMLJSON"] = json;

logger.warning (result);
//logger.warning (json);

Then create a dataset with the following methods: 然后使用以下方法创建数据集:

open() 打开()

recNum=0;

fetch() 取()

len = vars["HTMLJSON"].length;

if (recNum >= len)
    return false;

row["name"] = vars["HTMLJSON"][recNum].name;
row["id"] = vars["HTMLJSON"][recNum].id;
row["active"] = vars["HTMLJSON"][recNum].active;

recNum++;

return true;

You may need Apache Commons IO included in your scriptlib folder. 您可能需要在scriptlib文件夹中包含Apache Commons IO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM