I tried to check online how to integrate one of the best reporting framework BIRT Framework (http://eclipse.org/birt/) with one of the best ESBs i.e. Mulesoft (https://www.mulesoft.com/resources/esb/what-mule-esb) but couldn't find much. So after few trial and errors I could do some integration on my local and I thought its worth sharing it so writing this blog. This is my first ever tech blog so I hope doing it write ... if you have any questions then please do get in touch with me ...
The advantages of BIRT reports are
- The BIRT documentation is pretty extensive and well maintained.
- Because of its library features and easy to maintain .rptdesign files one can create complex and rich reports.
- Supports most of the file formats including PDF, HTML, SVG etc.
These advantages if combined with Mulesoft can give rich and complex reports for any type of business needs. For example if one needs to create a complex PDF report from the DB data using Mulesoft this is a good fit for it.
In the following example we will be integrating reporting engine API with Mulesoft project and depending upon the inbound parameters we will be fetching the data for report and creating a PDF out of it.
I have used common Java component in this case but in future there is definitely a scope for addiing / creating BIRT connector from the Mulesoft.
In order to run this example we would need following items:
- MySQL (to fetch data from the report, one can use scripted datasource as well but I prefer to use mysql for BIRT reports.)
- BIRT Reporting Engine runtime (download from http://download.eclipse.org/birt/downloads/#runtime)
- Anypoint Studio for Mulesoft Developement (download from https://www.mulesoft.com/studio)
First lets create a database and a table for the report ...
- MySQL Setup:
mysql> create database mulesbirtint;
mysql> use mulesbirtint;
mysql> CREATE TABLE tech_companies (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
ceo varchar(255) NOT NULL,
hq varchar(255) NOT NULL,
state varchar(20) DEFAULT NULL,
PRIMARY KEY (id)
);
mysql> insert into tech_companies values
(null,'Appnovation','Arnold Leung', 'Vancouver' , 'BC'),
(null,'Salesforce','Marc Benioff', 'San Francisco' , 'CA'),
(null,'Google' , 'Larry Page' , 'Mountain View' , 'CA'),
(null,'Facebook' , 'Mark Zukerberg' , 'Palo Alto', 'CA'),
(null,'Yahoo' , 'Marissa Mayer' , 'Sunnyvale' , 'CA');
- Reporting Setup
- Mulesoft Setup
Create flows and components as show in the below image. We will be creating an incound http endpoint and in its header we will pass value for the state. We will also have a Java component which will take the header (state) value from the eventContext and create a final PDF report output in the output folder of the project.
Alright , now that the Muleproject is setup .. only thing remaining is to run it ...
Rightclick the project in Anypoint studio > Run As > Mule Application .... once the application is deployed .. go to any browser and invoke the http endpoint :
http://localhost:8081/?state=BC
Check the output folder in the project structure .. you can see the output report created final_report.pdf ....
let me know if you guys face any issues .... cheers !!
In the above picture we can see how the project has been setup in anypoint studio. The flow starts with http inbound endpoint , then there a logger to show the inbound parameters and then the Java component.The tech_companies.rptdesign file is kept in the reports folder.
Update the pom.xml to add BIRT dependencies in it ..
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.3.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.apache.poi</artifactId>
</exclusion>
<!-- <exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>com.ibm.icu</artifactId>
</exclusion> -->
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<repositories>
<repository>
<id>sonatype-nexus-releases</id>
<name>Sonatype Nexus Releases</name>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
</repositories>
In the logger component add following message, it will print the state value passed from http request:
Request received .. generate report for state #[message.inboundproperties."http.request.params".state]
The Java component is calling the GenerateReport.java class which contains below code :
package com.appnovation.demos;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class GenerateReport implements Callable {
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
String param = eventContext.getMessage().getInboundProperty("state");
generateReportAsPerParam(param);
return "Report generation completed";
}
private void generateReportAsPerParam(String param) throws EngineException {
IReportEngine engine = null;
EngineConfig config = null;
try {
config = new EngineConfig();
config.setBIRTHome("/Users/username/Downloads/birt-runtime-4_4_2/ReportEngine");
config.setLogConfig("Users/username/test", Level.FINEST);
Platform.startup(config);
final IReportEngineFactory FACTORY = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = FACTORY.createReportEngine(config);
// Open the report design
IReportRunnable design = null;
design = engine
.openReportDesign("reports/tech_companies.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("param_1", param.toUpperCase());
// final HTMLRenderOption HTML_OPTIONS = new HTMLRenderOption();
// HTML_OPTIONS.setOutputFileName("output/final_report.html");
// HTML_OPTIONS.setOutputFormat("html");
// HTML_OPTIONS.setHtmlRtLFlag(false);
// HTML_OPTIONS.setEmbeddable(false);
// HTML_OPTIONS.setImageDirectory("C:\\test\\images");
PDFRenderOption PDF_OPTIONS = new PDFRenderOption();
PDF_OPTIONS.setOutputFileName("output/final_report.pdf");
PDF_OPTIONS.setOutputFormat("pdf");
task.setRenderOption(PDF_OPTIONS);
task.run();
task.close();
engine.destroy();
} catch (final Exception EX) {
EX.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
Alright , now that the Muleproject is setup .. only thing remaining is to run it ...
Rightclick the project in Anypoint studio > Run As > Mule Application .... once the application is deployed .. go to any browser and invoke the http endpoint :
http://localhost:8081/?state=BC
Check the output folder in the project structure .. you can see the output report created final_report.pdf ....
let me know if you guys face any issues .... cheers !!
Very informative. Thank you.
ReplyDeleteThis helps the readers a lot Mulesoft Online Training Hyderabad
ReplyDeleteSo excited to hear about this course and practically take on learning Mulesoft Online Training Hyderabad
ReplyDelete
ReplyDeleteGreat Article. its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
Mulesoft online course hyderabad
the blog is about Xml to HTML Transformation using XSLT Transform in Mulesoft it is useful for students and Mulesoft Developers for more updates on Mulesoft follow the link
ReplyDeletemulesoft Online Training
For more info on other technologies go with below links
Python Online Training
tableau online training hyderabad
ServiceNow Online Training
It is nice blog this is helps the readers alot this article was very clear and its useful informayion.
ReplyDeleteBig data hadoop online training Hyderabad
ReplyDeletethe blog is good and Interactive it is about Mulesoft BIRT integration it is useful for students and Mulesoft Developers for more updates on Mulesoft follow the link
mulesoft Online Training
For more info on other technologies go with below links
Python Online Training
tableau online training hyderabad
ServiceNow Online Training
Great Article. its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeletesalesforce Online Training Hyderabad
This information is really awesome thanks for sharing most valuable information.
ReplyDeleteMuleSoft Online Training
MuleSoft Training in Hyderabad
I really liked your blog post.Much thanks again. Awesome.
ReplyDeleteMulesoft Self Learning
Mulesoft Online Course in Hyderabad