* A Simple Way of Calling Web Service Data Source in BIRT

Key words: Web Service data source  BIRT

BIRT supports SOAP-based Web Services access. But using a SOAP response as the report data source is complicated and inflexible because it:

1. Requires too many configurations;

2. Needs too many JARs and becomes heavy-loaded;

3. Uses too many API interfaces to make the code lengthy and difficult to debug;

4. Receives only simple result sets that are not recomputable.

An example: Call Web Services according to an input parameter to get the weather data in a certain region.

URL

http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=...

The returned data is in the following XML format:

<?xml   version="1.0" encoding="utf-8"?>

<ArrayOfString   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">

 <string>Henan   (Province).</string>

 <string>Xinyang(City).</string>

 <string>464000</string>

 <string>57297.jpg</string>

 <string>2019/12/20   16:00:31</string>

 <string>0 C/10 C</string>

 <string>December 20 is cloudy to   overcast</string>

 <string>East to north is less than   category 3</string>

 <string>...</string>

</ArrayOfString>

Expected structuralization result:

undefined 

In this case I suggest using esProc. esProc encapsulates the returned result of HTTP service’s URL string as a file stream to get data source with simple and easy to debug code. It also provides a set-operation-related function library to handle subsequent structured computations, which makes any third-party library unnecessary, and then returns the computing result to BIRT’s DataSet for reporting. For the above example, we only need a 5-line script:


A

1

=wsdl=concat("\"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=",urlencode("Xinyang","UTF-8"),"\":\"UTF-8\"")

2

=httpfile(${wsdl})

3

=xml(file(A2).read(),"ArrayOfString/string")

4

=create(${A1.(concat("str",#)).concat@c()})

5

>A4.record(A3)

With the help of esProc SPL, we can handle many other similar computing scenarios conveniently. For more examples, read Some Examples of Achieving Dynamic Data Sources in BIRT, and XML Data Parsing & Calculation.

esProc provides JDBC driver to conveniently integrate with BIRT and other reporting tools. Read How to Call an SPL Script in BIRT to find how to use and deploy esProc JDBC.

Read Getting Started with esProc to download and install esProc, get a license for free and find related documentation.