2

Well, I'm building my application project over a Tomcat 6 server. Being my own application packaged as a war file, I've included the whole BIRT 4.2 engine into it, being now able to generate my custom reports on there. The BIRT runtime environment dependencies made my war file to deploy grow up about 20 MB in size.

However, recently I found BIRT has its standalone runtime packaged also as a war file (also called BIRT viewer), which I now use to test the reports I create in pdf format. It's so straightforward to use, it only requires the report file value and its parameters, which you pass as a GET request. It displays the reports in a viewer, where you can get them downloaded from too.

My question is, in which way can I integrate my own application and that runtime just to when a download is requested from my application to let the standalone runtime manage it? This also involves security stuff, as I don't want every user in my application to be able to download all the available reports.

Is it possible right now?

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • I use the runtime as an external process from a python/django server - I manage the security on the python server, and call BIRT from within django to locally to generate the report. But are you looking to use the runtime to handle your requests directly? – Adam Morris Oct 01 '13 at 14:11
  • I intend to, in some way, divide the reporting module from my own app. What I've found is the standalone war file which can run in the same server as I run my app. Obviusly, the comunication between them should be using HTTP requests as far as I understand. – Aritz Oct 01 '13 at 14:30

3 Answers3

1

As I understand, you need to integrate your application with the BIRT Runtime Viewer so that you can generate reports from within your application, but powered by BIRT Viewer in the backend. Here are the steps

Pre-Requisites -

  • I've use the src for 4.2.2 from here

  • I've extracted it here, and call it BIRT_VIEWER_HOME org.eclipse.birt-BIRT_4_2_2_RC2_201301291123\viewer\org.eclipse.birt.report.viewer\

1) Copy all the contents of the web.xml from your BIRT viewer to your application's web.xml. Birt Viewer's web.xml can be spotted here - BIRT_VIEWER_HOME\birt\WEB-INF

2) Copy webcontent folder present under BIRT_VIEWER_HOME\birt\ and put it in your application's root folder. So when deployed in tomcat, it will create a directory structure \webapps\yourapplication\webcontent

3) Create a jsp page, with an iframe inside. Eg. report.jsp which has this content

<iframe src="" id="birtViewer" name="birtViewer" frameborder="0" 
    scrolling="no" class="reportframe" 
    style="height:600px;margin:0px;padding:0px;" />

Notice that I've left the src as empty so that initially, the iframe will not load anything

3) Based on some click or any other criteria, set the src of this iframe with this URL report=reports/">http://localdomain:port/yourapplication/frameset?_report=reports/&__format=pdf

eg. My implementation using JQuery.

$(document).ready(function(){
    var url;
    if(someCondition)
    {
        url = "frameset?__report=reports/testreport.rptdesign&__format=pdf";
    }
    else
    {
        url = "dummyPage.jsp";
    }

    $("#birtViewer").attr('src',url);//setting the src for iframe
})

4) This will load the iframe with the BIRT parameters for this report.

5) You can fill in all the params and hit the "OK" button. The report will be generated in this iframe.

I'll rather let you take care of the security aspects. A simple security measure is to use tomcat's Filter mechanism to check for the BIRT Viewer URL and see if it is accessed by someone who is authenticated or has a session.

UPDATE:

If you want a central BIRT execution point, create a batch file, call that from Java passing the parameters and then get the report from the generated location. This way it is useful via command prompt and from Java/Tomcat. Steps below

  1. Create a batch file, say report.bat and add this code there. Place all the BIRT jars in classpath. I will omit setting the value of variables for brevity

    %JAVACMD% -Dlog4j.configuration="file:%APP_HOME%/conf/log4j.properties" 
    -cp "%CP%" -Djava.util.logging.config.file=%APP_HOME%/conf/birtlogger.properties 
    org.eclipse.birt.report.engine.api.ReportRunner %p1% %p2% %p3% %p4% %p5%
    
    • %APP_HOME%/reports is where I put the designs. You can pass it dynamically though.
    • p1 through p5 are my 5 parameters that I pass to the Report Runner. You can pass any number of parameters though.
  2. Run the report by calling this from your Java/Tomcat. Refer @Adam's answer.

    report.bat -f pdf -p "p1=paramValue1" -p "p2=paramValue2" -p 
    "p3=paramValue3" -p "p4=paramValue4" -p "p5=paramValue5" -o     
    %APP_HOME%\myreportfolder\NameofMyReport.pdf %APP_HOME%\NameofMyReport.rptdesign
    

You will get the report NameofMyReport.pdf generated in %APP_HOME%\myreportfolder. Point your java code to get it loaded from there.

Refer this link if you want a detailed explanation.

Thomas
  • 372
  • 2
  • 10
  • Sounds really good, but I'm afraid what this achieves is to display the plain viewer frame into my own page. What I really want is to have a standalone report server with the templates inside. Then, if having multiple applications deployed for example, each application could access the server to get its report (to be able to download it afterwards). My question is, is really possible to have a centralized report server like that using the standalone runtime? – Aritz Oct 01 '13 at 14:39
  • A Central Server is difficult via HTTP, as you will not have the PDF Object handle without the JSP handling it for you. That is, you will not get a link to click "Save As", but can only display the PDF and let the PDF plugin in the broswer take care of "Save As", "Print" etc. I have updated my answer for a central execution. – Thomas Oct 03 '13 at 11:08
  • Take a look to my answer, I finally implemented my own servlet with the engine integrated, which provides REST access. Thanks for your elaborated response. – Aritz Jul 03 '14 at 13:16
0

One solution is ditch the birt.war and to call BIRT as a separate java process, using the scripts in the ReportEngine subdirectory of the birt-runtime download, by Executing a Java application in a separate process

My J2EE is a bit rusty, but otherwise @Thomas has pretty good instructions for rebuilding the birt.war file with a custom viewservlets.jar. Looks like some older instructions might be here:

http://wiki.eclipse.org/BIRT/FAQ/Birt_Project#Q:_How_do_I_build_the_2.2.2F2.3.2F2.5_BIRT_Viewer.3F

Community
  • 1
  • 1
Adam Morris
  • 8,265
  • 12
  • 45
  • 68
  • So the solution lies in some way in adapting the runtime itself to allow its independent execution and communication. Looks like this can't be done with an HTTP request as I wanted to do... I think I should implement some communication layer in the runtime itself to allow my modules talk with it (web service, message queuing)? – Aritz Oct 03 '13 at 06:56
  • No necessary to fetch the standalone server's source code, I've built up my own servlet solution instead. That way I make them available via REST urls. – Aritz Jul 03 '14 at 13:20
0

I finally decided to set up my own servlet which serves reports based in REST services. This way you can address the desired template/parameters via URL.

Published as an open source git project, you can take a look to it here. Everyone is invited to improve it and new commiters will be welcomed.

Aritz
  • 30,971
  • 16
  • 136
  • 217