Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use rest api Interface to get json for report by BIRT

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "BIRT how to use rest api interface to obtain json to make reports". In daily operation, I believe many people have doubts about how BIRT uses rest api interface to obtain json to do reports. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "BIRT how to use rest api interface to obtain json to do reports". Next, please follow the editor to study!

JSON data sources cannot be built in BIRT, and although some open source communities provide parsing JSON data source plug-ins, almost all plug-ins are very low-level and inconvenient to use, so they are not recommended.

The general approach to BIRT is to create a "script data source" that connects to URL on that script source and parses the results on its own, but the script is cumbersome to write and requires a lot of work.

For example, to deal with such a scenario: call REST API according to the passed parameters, and return nested JSON data, some of which are in the following format:

[

{

"id": 1000

"content": "It is too hot"

"comment": [

{

"author": "joe"

"score": 3

"comment": "just so so!"

}

{

"author": "jimmy"

"score": 5

"comment": "cool! good!"

}

]

}

...

]

Expect the effect after parsing:

BIRT uses the open () method to create a scripted data source, as follows:

...

ImportPackage (Packages.java.io)

ImportPackage (Packages.java.net)

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)

...

It is recommended to use the aggregator, which encapsulates the return result of the url string of the HTTP service into a file stream, which can directly parse the JSON format string and structure it into an ordinal table. The aggregator carefully designs a set of function libraries in the field of set operations to deal with all kinds of structured operations, such as grouping, sorting, filtering, aggregation, connection, etc., without the assistance of a third-party database. For example, in the above question, the aggregator script only needs three lines:

A

one

= httpfile ("http://yourapi/endpoint/servlet/testServlet?table=blog&type=json")

two

= json (file (A1) .read ())

three

= A2.news (comment;id,content,$ {A2.comment.fname () .concat@c ()})

Finally, the calculation results are returned to the DataSet of BIRT for report presentation. From this example, compared with the conventional method, it takes less code to implement the same algorithm, and it is convenient to perform debugging step by step.

At this point, the study on "how BIRT uses the rest api interface to obtain json for reporting" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report