Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Which is the correct lifecycle of the BIRT runtime to create multiple reports(Trouble: on one hand if I call destroy() after first report, i get nullPointerException on openReportDocument, one other if i don't call destroy(), engine doesn't release pdf file)
icon4.gif  Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1240323] Thu, 06 February 2014 08:13 Go to next message
David Basilashvili is currently offline David BasilashviliFriend
Messages: 6
Registered: February 2014
Junior Member
Hello!

I use runtime BIRT to generate multiple reports. My maven dependency:
<dependency>
	<groupId>org.eclipse.birt.runtime</groupId>
	<artifactId>org.eclipse.birt.runtime</artifactId>
	<version>4.3.1</version>
</dependency>


How to set up the life cycle of the ReportEngine instance?

The documentation (http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php#reportengine) says: Quote:
Therefore, each application should create just one ReportEngine instance and use it to run multiple reports


I use documentation for creation multiple pdf reports with separate run and render tasks. But I have problems. This is my Spring singleton bean:
@Service
@Named("birtSingleton")
public class BirtSingleton implements ReportEngine, InitializingBean, DisposableBean {

    @Autowired
    BirtPlatform birtPlatform;

    @Override
    public String getInfo() {
        return null;
    }

    IReportEngine reportEngine;

    //this is spring initialize method, it calls when application is started
    @Override
    public void afterPropertiesSet() throws Exception {
        IReportEngineFactory reportEngineFactory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
        reportEngine = reportEngineFactory.createReportEngine(birtPlatform.getEngineConfig());
    }

    @Override
    public void generateReport(ReportParameters reportParameters) throws ReportException {
        System.out.println("Engine: " + reportEngine);

        IReportRunnable reportRunnable;
        try {
            reportRunnable = reportEngine.openReportDesign(reportParameters.getReportDesignPath());
        } catch (EngineException e) {
            throw new ReportException("Error opening report design " + reportParameters.getReportDesignPath(), e);
        }

        try {
            BirtDataSourceAccessStrategy dataSourceAccessStrategy = new UrlAccessStrategy();
            dataSourceAccessStrategy.changeReportDesign(reportRunnable);
        } catch (IOException e) {
            throw new ReportException("Error changing DS properties " + reportParameters.getReportDesignPath(), e);
        }

        IRunTask runTask = reportEngine.createRunTask(reportRunnable);

        String rptDocumentFilePath = reportParameters.getFullRptDocumentFilePath();
        try {
            runTask.run(rptDocumentFilePath);
        } catch (EngineException e) {
            throw new ReportException("Error report running " + reportParameters.getReportDesignPath(), e);
        } finally {
            runTask.close();
        }

        IReportDocument reportDocument;
        try {
            reportDocument = reportEngine.openReportDocument(rptDocumentFilePath);
        } catch (EngineException e) {
            throw new ReportException("Error report document opening " + reportParameters.getReportDesignPath(), e);
        }

        IRenderTask renderTask = reportEngine.createRenderTask(reportDocument);

        PDFRenderOption renderOption = new PDFRenderOption();
        renderOption.setOutputFileName(reportParameters.getFullReportFileName());
        renderOption.setOutputFormat("pdf");

        renderTask.setRenderOption(renderOption);

        try {
            renderTask.render();
        } catch (EngineException e) {
            throw new ReportException("Error rendering " + reportParameters.getReportDesignPath(), e);
        } finally {
            renderTask.close();
            reportDocument.close();
        }
          //after each report generation???
          reportEngine.destroy();
    }


    //this method calls when application terminates
    @Override
    public void destroy() throws Exception {
        //or when application terminates???
        reportEngine.destroy();
    }
}


  1. When I call reportEngine.destroy() after each report generation:

    ReportEngine instance successfully generates first pdf report, but no second generation i get nullPointerException on
    reportDocument = reportEngine.openReportDocument(rptDocumentFilePath);

  2. When I call reportEngine.destroy() in spring termination method destroy():

    ReportEngine instance successfully generates all pdf report, but when application running, I can't access pdf files. ReportEngine doesn't release them.

Where can I locate reportEngine.destroy()? Which is the correct usage of reportEngine?

Help me, please

Re: Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1240471 is a reply to message #1240323] Thu, 06 February 2014 14:41 Go to previous messageGo to next message
donino donino is currently offline donino doninoFriend
Messages: 183
Registered: July 2011
Senior Member
Option 2: destroy a reportEngine in Spring termination.

If you can't access generated pdf files, i think this is a bug due to "setOutputFileName" method, the stream is not correctly closed. You can workaround this by using a FileOutputStream instead. Comment this line:

renderOption.setOutputFileName(reportParameters.getFullReportFileName());

and replace with:

ostream = new FileOutputStream( reportParameters.getFullReportFileName());
renderOption.setOutputStream(ostream);


in your finally block of the renderTask, in addition to the existing code:

ostream.flush();
ostream.close();


That should do it!
Re: Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1240820 is a reply to message #1240471] Fri, 07 February 2014 05:21 Go to previous messageGo to next message
David Basilashvili is currently offline David BasilashviliFriend
Messages: 6
Registered: February 2014
Junior Member
Donimo, it really works! Thank you!

I was looking for this bug, but I found nothing. Do I report a bug?
Re: Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1240974 is a reply to message #1240820] Fri, 07 February 2014 09:38 Go to previous messageGo to next message
donino donino is currently offline donino doninoFriend
Messages: 183
Registered: July 2011
Senior Member
I am glad you got it work! Yes it would be great to report it, i guess many developers are sruggling with this Smile Please post the issue ID here once it is created
Re: Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1244304 is a reply to message #1240974] Wed, 12 February 2014 06:24 Go to previous message
David Basilashvili is currently offline David BasilashviliFriend
Messages: 6
Registered: February 2014
Junior Member
Hello! I reported a bug with id = 427959: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427959
Previous Topic:Updating between 3.7.1 to 4.3.1
Next Topic:Library Data Source Is Hardcoded Into Reports
Goto Forum:
  


Current Time: Sat Apr 20 01:33:39 GMT 2024

Powered by FUDForum. Page generated in 0.04205 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top