带有宁静API的Birt [英] Birt with restful APIs

查看:69
本文介绍了带有宁静API的Birt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个PHP项目开发BIRT报告.通过使用JDBC数据源直接连接到数据库,我可以轻松地开发报告.但是某些数据来自宁静的api,而我无法从这些api端点创建数据源.

I am developing BIRT reports for a PHP project. I can easily develop reports by connecting directly to the database using JDBC Datasource. However certain data come from restful api and I am unable to create a datasource from those api endpoints.

Birt可以选择从Web服务创建数据源,但是,这似乎仅接受SOAP API.我想知道是否有人可以向我展示如何从REST API创建Birt数据源.我通读了谷歌提供的所有搜索结果.一些建议使用POJO数据源,而另一些建议使用脚本化数据源,这需要Java方面的知识,而PHP程序员很难破解.大多数链接都重定向到devshare,后者现在指向打开的文本,并且内容不再存在.我尝试了以下所有建议.

Birt has option to create datasource from web services, however this seems to only accept SOAP APIs. I was wondering if someone can show me how to create birt datasources from REST APIs. I read through all the search results provided by 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. Most links redirect to devshare which now points to open text and the content doesnot exist anymore. I tried all the recommendations which are as follows.

使用Web服务数据源:它需要wsdl文件的位置,而REST API不在该位置.它仅随SOAP API一起提供.如果有其他替代方法,那就太好了.

Using Webservices Datasource: It requires the location of wsdl file which is not there for a REST API. It comes only with SOAP API. Would be great if there is an alternative to this.

尝试过POJO数据源和脚本化数据源:但是,作为PHP开发人员,无法获得良好的结果,因为那里没有逐步的指导来做到这一点.

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.

因为REST在今天非常流行,所以我想知道是否有任何直接的方法可以做到这一点,或者是否有人可以帮助Java或Javascript程序来处理PHP头的脚本化数据源.在过去的15天里,我一直在尝试这种方法,非常希望获得一些帮助.

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. I have been trying this for the last 15 days and is desperate for some help.

推荐答案

最终获得了脚本化数据源.

Ended up with scripted datasource.

使用open()方法创建脚本化数据源,如下所示:

Create a scripted datasource with open() method as follows:

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;

您可能需要在scriptlib文件夹中包含Apache Commons IO.

You may need Apache Commons IO included in your scriptlib folder.

这篇关于带有宁静API的Birt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆