Thinking in GIS

a blog about GIS from a urban geogeek living at the countryside

Feed, Categories, Archives


Deployment of BIRT reports by email

Posted: June 05, 2007
Categories: devs, Java
Feedback: View Comments

birt is a powerful Open Source Business Intelligence and Reporting Tools I came to use in the last weeks for a project. Its key features are:

  • Eclipse based report solution
  • Very nice report designer producing a standard xml file. This file can be then used to deploy the report in several ways
  • runtime component for easily serving reports on a server, also by a web server (like Tomcat)
  • outstanding Java APIs for creating and modifying the xml report design (DE API), for consuming and deploying the reports in several ways (RE API) and for creating and rendering charts (CE API)

For creating a BIRT report with the Eclipse environment you can use this very nice tutorial.

For standardizing and templating BIRT reports in an enterprise environment using BIRT report libraries and templates you can read this great article.

For deploying your BIRT reports in various ways there is another great article.

After reading the last article you will find out that there are mainly the following ways to deploy a BIRT report (without using Eclipse):

  • Deploy the report with the BIRT Viewer Servlet
  • Deploy the report with a servlet
  • Using the BIRT Viewer in a RCP Application
  • Using the BIRT Report Engine API in RCP Application

Of course if you want to use BIRT reports in a NOT J2EE application, you can still consider to create some kind of web services.

A very nice and easy way I found to deploy reports to an enterprise is by using the BIRT Viewer Servlet in a servlet engine like Tomcat. This is just a question of deploying the Viewer servlet and the report xml files to the web servlet engine, and it is all. Users will be able to access the real time generated reports in a web based way (with HTML and pdf outputs).

You could have the need to send an email with some reports attached on a regular time manner. For doing so I quickly wrote the following Java class that can be run from the command line.

/* BIRT report sender */

package paolocorti.net.java.birt.utilities;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.net.URL;

public class ReportSender {

public static void main (String args[]) throws Exception {

String smtpHost = args[0];
    String from = args[1];
    String to = args[2]; //may be an array: email1,email2,..,emailn
    String bcc = args[3];
    String filepath = args[4];
    String subject = args[5];
    String text = args[6];
    String filename = args[7];

// Get system properties
    Properties props = System.getProperties();

// Setup mail server
    props.put("mail.smtp.host", smtpHost);

// Get session
    Session session = Session.getDefaultInstance(props, null);

// Define message
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));

// Email to...
    String toEmails[] = to.split(",");
    for(int i=0; i

You can run this class from the command line by passing the proper parameters:

  • smtpHost: your SMTP server
  • from: from Email
  • to: to Email, may be an array: email1,email2,..,emailn
  • bcc: bcc Email
  • filepath: url filepath of report (using &__format=pdf parameter for pdf output)
  • subject: subject of Email
  • text: text of Email
  • filename: filename of pdf

You can finally schedule this class to run on regular manner. For example in a Windows server create a bat file to run the procedure and schedule it as you like.

This is a sample:

set CLASSPATH=%CLASSPATH%;c:javajavamail-1.4mail.jar;c:javajavamail-1.4activation.jar; 
java paolocorti.net.java.birt.utilities.ReportSender mySMTPServer fromEmail toEmail1,toEmail2,toEmail3 bccEmail "http://reportserver:8080//birt//frameset?report=myReport.rptdesign&format=pdf" "Email Subject" "Email Text" "filename.pdf"

blog comments powered by Disqus