Monday 30 March 2015

Quick Learn : Report Scheduling & Bursting in Jasper Server 6.x with an example scenario

There are numerous posts on scheduling and report bursting in jasper. Even though there were, this article is an outcome of my research & hope will help you to do the same very faster with an end to end example. 

Setup : 

1) Jasper Reports Server Professional 6.0
2) A sample demo Report ( 07g.RevenueDetailReport) - Available only in professional Jasper Server.
3) Email Server : Gmail
(User Name : testjasperreport@gmail.com Password : jasperreports) - these are open for the community people who reads this page.

Aim of the post : 

Schedule a Report and send the output of report to email with attachment & also send success or failure notification email.

Step - 1

To work with email notifications & report bursting we need to work with 2 files.
They are
i)js.quartz.properties
Location of the file :
C:\Jaspersoft\jasperreports-server-6.0\apache-tomcat\webapps\jasperserver-pro\WEB-INF

Configure the mail server

report.scheduler.web.deployment.uri=http://127.0.0.1:8080/jasperserver-pro/

report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=testjasperreport@gmail.com
report.scheduler.mail.sender.password=jasperreports
report.scheduler.mail.sender.from=testjasperreport@gmail.com
report.scheduler.mail.sender.protocol=smtp
report.scheduler.mail.sender.port=587


If your mail server requires authentication, change below property from false to true as shown in below.

ii) applicationContext-report-scheduling
Location of the file :
C:\Jaspersoft\jasperreports-server-6.0\apache-tomcat\webapps\jasperserver-pro\WEB-INF

 <bean id="reportSchedulerMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${report.scheduler.mail.sender.host}"/>
        <property name="username" value="${report.scheduler.mail.sender.username}"/>
        <property name="password" value="${report.scheduler.mail.sender.password}"/>
        <property name="protocol" value="${report.scheduler.mail.sender.protocol}"/>
        <property name="port" value="${report.scheduler.mail.sender.port}"/>
        <property name="javaMailProperties">
            <props>
                        <prop key="mail.smtp.auth">true</prop>
        <prop key="mail.smtp.starttls.enable">true</prop>
            </props>
        </property>
    </bean>

NOTE : Restart jasper server once the changes done if it is already running

Step - 2 

Now, lets work with a report and test.
* Professional server is having sample built in reports. Pick one of the report , for instance  pick "07g.RevenueDetailReport"

* Locate this report in the server, right click it find "schedule" option and click on it


Step - 3

* After clicking Schedule option, it will take us to "Schedule Job" jasper page. We call scheduling procedure as job and term it as scheduling jobs for reports.

* Click on "Create Schedule" button  and find the four tabs i) Schedule ii) Parameters iii) Output Options and iv) Notifications

i)  Schedule Tab:

As shown in below image set
a) the date and time of execution
b) Recurrence ( See documentation for the various recurrence in reference
c) Move to Parameters tab.



ii) Parameters Tab :
select the parameters of the report here .. we will get the output in pdf format for the selected input controls
* Fill all the required properties in all of the sections and save the job.

iii)  Output Options 
find the options in the image

iv) Notifications :
Find the information in below image


Click on Save button and give a name to scheduler (job)
Find the all scheduled  jobs ..

OUTPUT : Check it out in email

login to the gamil with below credentials and check the output.
testjasperreport@gmail.com /jasperreports


Opening the 2nd mail : Attachments one

Opening the 1st mail : Notifications mail


Check the output in CC mail :




Solution-2 :  (smtps)

Change below at 1st location. 
file name & location : <Jasper Installed Home>apache-tomcat/webapps/jasperserver/WEB-INF/js.quartz.properties

report.scheduler.web.deployment.uri=http://127.0.0.1:8080/jasperserver-pro/

report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=testjasperreport@gmail.com
report.scheduler.mail.sender.password=jasperreports
report.scheduler.mail.sender.from=testjasperreport@gmail.com
report.scheduler.mail.sender.protocol=smtps
report.scheduler.mail.sender.port=465

Change below in 2nd location

 <bean id="reportSchedulerMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${report.scheduler.mail.sender.host}"/>
        <property name="username" value="${report.scheduler.mail.sender.username}"/>
        <property name="password" value="${report.scheduler.mail.sender.password}"/>
        <property name="protocol" value="${report.scheduler.mail.sender.protocol}"/>
        <property name="port" value="${report.scheduler.mail.sender.port}"/>
        <property name="javaMailProperties">
            <props>
                        <prop key="mail.smtps.auth">true</prop>
        <prop key="mail.smtps.starttls.enable">true</prop>
            </props>
        </property>
    </bean>

and the remaining procedure of setting mail is same

NOTE (Additional Notes): 
If we use Microsoft Exchange mail Services, then we need to add one more line in the applicationContext-report-scheduling.xml

      <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.smtp.starttls.required">true</prop>
        </props>

Resources 

Find More information at below sites : 

1)  http://stackoverflow.com/questions/9683679/email-not-sent-in-jasper-report-scheduling
2) https://mdahlman.wordpress.com/2011/09/28/emailing-reports-from-jasperreports-server/
3) http://community.jaspersoft.com/wiki/configuring-report-scheduler
4) https://community.jaspersoft.com/documentation/tibco-jasperreports-server-installation-guide-community-edition/v60/configuring-report

No comments:

Post a Comment