In the article “Getting started with BIRT” we worked with the tool designed to create BIRT report templates and using which we can run these reports. But in practice, such an approach is unlikely to be acceptable for business, which makes it necessary to integrate BIRT into an existing Web application.
Steps for integrating BIRT
Let’s take a web-application as a basis, which uses a data model from the previous article, and add the possibility to run a report in it. A Web application is a service for monitoring events in the city. Registered users have an opportunity to subscribe to a specific event topic and, each time when there are any events of the chosen topic, subscribers will receive notifications. Users can offer their news, the service administrator moderates and approves or rejects news for publication.
Adding dependency in Maven
The first thing to do for BIRT integration into an existing project is to connect the necessary libraries. A project builder Maven is used in this case, so a web services container Axis and two following BIRT components should be included into the pom.xml file:
Configuration of deployment descriptor
After we have specified the required dependencies, we need to add information on the deployment of the BIRT servlet. The following points should be added into web.xml file:
1) To set the location of the “working” folder for BIRT. This folder contains our reports:
2) To set a flag value, which determines if reports are available only from the working directory. It’s true by default:
3) To specify a parameter for setting up the work with the report url address. Let’s say our report has the address http://host/repo/test.rptdesign. In this case, the following values are possible:
- all – all paths are supported.
- domain – only the paths in which host corresponds to the current domain are supported. The comparison is character by character, so “127.0.0.1” and “localhost” are considered to be different domains.
- none – URL addresses are not supported
4) To define the location of the configuration file for the report viewer:
5) To define whether the print function is available only on the client side, or on the server side too. The default value is ON.
6) To set the flag that determines whether compelling optimization of result is enabled in HTML for the browser. The default value is true.
7) To specify a classname for generating report names during the export.
8) To set ServletContext and HttpSession Listener.
9) To register and configure ViewerServlet.
10) To register and configure Engine Servlet.
Connecting program files
Next, in the /webapp directory of our project, we create the following folders: logs, report, scriptlib. In the directory /webapp/WEB-INF we create a tlds directory.
We put the files from the archives programfiles.zip as follows:
- birt.tld into /webapp/WEB-INF/tlds
- erver-config.wsdd files and viewer.properties into /webapp/WEB-INF
The content of the webcontent.zip archive we put into /webapp
Adding report template to the project
At this stage, two BIRT components are integrated into our web application (for processing and displaying reports). All we have to do is to put our report template, which we’ve made at the last lesson, to add a link to our report and to run the project.
Our report template is put it into the /webapp/report folder:
Now we can put a link to our report in any view. For example, we can add a link in a menu that opens our report in a new tab:
And the last thing you need to do is to run the application. Jetty is used in our application, so to run the application the command jetty:run is used:
Our application is available at https://localhost:8888/. After clicking the link, our report is opened in a new tab: