Integrate BIRT into existing webapp

I would like to add a BIRT reporting engine to an existing webapp in Tomcat. I donโ€™t need a BIRT viewer, I really only want to be able to run reports from a URL, for example http://localhost:8080/birt/output?__report=test.rptdesign&sample=my+parameter , and use various export options pdf, xls , doc, html.

The integration guides that I have found so far include a viewer and record my own servlets to handle different formats.

I was hoping that someone would simply know which servlet mappings from the report-engine web file I need, and which jars I would need to include from the lib directory for this BART implementation with barebones in an existing webapp.

+6
source share
2 answers

I was hoping that someone simply knew which servlet mappings from the report-engine web.xml file I needed, and which banks I would need to include from the lib directory for this BART implementation with barebones in an existing web application.

I didn't necessarily want to write my own servlet. I just wanted to integrate the existing report execution environment with its own stand-alone webapp ( here under the "runtime" button) into my existing webapp, so I do not need to distribute 2 webapps to support BIRT reports. Sorry if this was unclear.

I did this, albeit in the simplest way, in case someone has a similar question (using BIRT runtime 3.7.1):

  • All you need is the following servlet mapping added to your own webapp\web-inf\web.xml :

     <!-- Engine Servlet --> <servlet> <servlet-name>EngineServlet</servlet-name> <servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>EngineServlet</servlet-name> <url-pattern>/output</url-pattern> </servlet-mapping> 
  • Include all banks from the web-inf\lib runtime directory in your own webapp\web-inf\lib directory.

Then you can run the .rptdesign files using the output BIRT report URL from your own webapp and specifying any format you want, for example:

 http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=pdf http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=html http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=xls http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=doc http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=ppt 
+17
source

As I understand you, you are trying to create a birt report form in which you have * .rptdesign in some place.

Ok look at the following code

 this.bundle = ResourceBundle.getBundle("com.tts.mersal.resources.MersalResources"); this.config = new EngineConfig(); this.config.setEngineHome(bundle.getString("BIRT_ENGINE_HOME")); this.config.setLogConfig(bundle.getString("BIRT_LOGGING_FOLDER_PATH"), Level.ALL); Platform.startup(config); this.factory = (IReportEngineFactory)Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); this.engine = factory.createReportEngine( config ); this.engine.changeLogLevel(Level.ALL); ContentReader contentReader = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getFileFolderService().getReader(MersalOutboundReportDialogBean.this.dialogReportNode.getNodeRef()); IReportRunnable report = MersalOutboundReportDialogBean.this.getEngine().openReportDesign(contentReader.getContentInputStream()); ReportDesignHandle designHandle = (ReportDesignHandle)report.getDesignHandle(); OdaDataSource source = (OdaDataSource)designHandle.getModule().findDataSource(DATA_SOURCE_NAME); source.setProperty(source.getPropertyDefn("FILELIST"), buildUrl((String)source.getProperty(designHandle.getModule(), "FILELIST"))); IRunAndRenderTask runAndRenderTask = MersalOutboundReportDialogBean.this.getEngine().createRunAndRenderTask(report); HTMLRenderOption render = new HTMLRenderOption(); render.setOutputFileName("G:/Render.html"); render.setOutputFormat("html"); runAndRenderTask.setRenderOption(render); runAndRenderTask.run(); runAndRenderTask.close(); 

As you can see, the first thing you need to prepare is the birt engine, and then get the report instance from the IReportRunnable type so that you can then set the location of the output using the therender parameter, which will be changed depending on your request.

You have several chocies, HTMLRenderOption, PDFRenderOption and others.

I hope this will serve you.

Thanks.

+1
source

Source: https://habr.com/ru/post/906713/


All Articles