Email not sent in Jasper Report Scheduling - jasper-reports

I want to schedule my jasper report so that at a particular time, it will send the report to the mentioned id. I'm using Jasper Server 4.5.0 and I have scheduled a sample report to be sent to my gmail id. However, it's not been sent to the mail id and it doesn't show any Last Ran time too.

I found it hard to setup GMail as my email server. So once I got it working I posted the details in this article.
In the spirit of keeping StackOverflow answers self-contained, here are the key settings. js.quartz.properties:
report.scheduler.web.deployment.uri=http://localhost/jasperserver
report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=me#gmail.com
report.scheduler.mail.sender.password=mypassword
report.scheduler.mail.sender.from=me#gmail.com
report.scheduler.mail.sender.protocol=smtp
report.scheduler.mail.sender.port=587
applicationContext-report-scheduling.xml:
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop> <!--as indicated in JasperReports-Server-Install-Guide.pdf)-->
<prop key="mail.smtp.starttls.enable">true</prop> <!--NOT indicated in JasperReports-Server-Install-Guide.pdf-->
</props>
</property>

One observation,
If you´re going to use an email from Microsoft Exchange, you need on 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>

in my case works with this
first edit this arquive
/opt/jasperreports-server-cp-5.1.0/apache-tomcat/webapps/jasperserver/WEB-INF/js.quartz.properties
report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=username#gmail.com
report.scheduler.mail.sender.password=your_password
report.scheduler.mail.sender.from=username#gmail.com
report.scheduler.mail.sender.protocol=smtps
report.scheduler.mail.sender.port=465
second edit this
opt/jasperreports-server-cp-5.1.0/apache-tomcat/webapps/jasperserver/WEB-INF/applicationContext-report-scheduling.xml
<bean id=”reportSchedulerMailSender”>
<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>

Related

How to use JBossTS (Narayana) with Spring Data JPA

I am investigating the use of a JTA transaction manager with Spring Data JPA. I have successfully configured Atomikos and Bitronix and am trying to configure JBossTS (Arjuna/Narayana).
I followed the instructions for configuring JBossTS for Spring and came up with the following configuration:
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="jpaProperties">
<props>
<prop key="hibernate.format_sql">true"</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.H2Dialect"/>
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jtaDataSource">
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="connectionProperties">
<props>
<prop key="dynamicClass">com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass</prop>
<prop key="password"></prop>
<prop key="user">sa</prop>
</props>
</property>
<property name="driverClassName" value="com.arjuna.ats.jdbc.TransactionalDriver"/>
<property name="url" value="jdbc:arjuna:database.properties"/>
</bean>
</property>
<property name="packagesToScan" value="org.example.domain"/>
</bean>
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager">
<bean class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/>
</property>
<property name="userTransaction">
<bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction"/>
</property>
</bean>
<transaction:annotation-driven/>
However, attempting to run the application throws the following error:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: java.sql.SQLException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:361)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.<init>(IndirectRecoverableConnection.java:109)
at com.arjuna.ats.internal.jdbc.ConnectionImple.<init>(ConnectionImple.java:107)
at com.arjuna.ats.internal.jdbc.ConnectionManager.create(ConnectionManager.java:110)
at com.arjuna.ats.jdbc.TransactionalDriver.connect(TransactionalDriver.java:87)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.resource.transaction.backend.jta.internal.DdlTransactionIsolatorJtaImpl.prepare(DdlTransactionIsolatorJtaImpl.java:49)
... 60 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:346)
There does not seem to be any documentation on whether JNDI is mandatory to run JBossTS and if yes, how it can be configured in a standalone application that does not use a JavaEE container.
A sample application is available on Github in case the full configuration and source code is required. The problem can be seen by running Maven tests as mvn test -D"spring.profiles.active=jbossts".
Replace the <prop key="dynamicClass"> with <prop key="DYNAMIC_CLASS">
Specify the properties file with target/classes
Use the H2 file database instead of the memory
For more information you can see narayana.io

Password Encryption in Hikaricp

I am using HikariCP in a spring project.
Right now, I defined a connection like this
<bean id="hikariConfigLegacyReasonCode" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="HikariCPReasonCodePool" />
<property name="connectionTestQuery" value="SELECT 1" />
<property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<property name="registerMbeans" value="true"/>
<property name="maximumPoolSize" value="15"/>
<property name="idleTimeout" value="60000"/>
<property name="connectionTimeout" value="5000" ></property>
<property name="dataSourceProperties">
<props>
<prop key="url">jdbc:mysql://${LegacyReasonCodeIp}</prop>
<prop key="user">${LegacyReasonCodeUsername}</prop>
<prop key="password">${LegacyReasonCodePassword}</prop>
<prop key="cachePrepStmts" >true</prop>
<prop key="prepStmtCacheSize" >250</prop>
<prop key="prepStmtCacheSqlLimit" >2048</prop>
<prop key="useServerPrepStmts" >true</prop>
</props>
</property>
Here, Server name , username and password will be loaded from a property file. Is there any way to store the DB password in the property file in encrypted manner ?
Try the jasypt project. It includes a number of integrations for Spring, including implementations of:
PropertyPlaceholderConfigurer
PropertyOverrideConfigurer
PreferencesPlaceholderConfigurer
http://www.jasypt.org/spring31.html

Adding Multiple Login Pages in Jasperserver

I want to add multiple login pages to single jasperserver.
i have customize the code and added login1.jsp and login2.jsp in moudles/login/ folder.
also i have added following code in \jasperserver-war\src\main\webapp\WEB-INF\jasperserver-servlet.xml
bean id="urlHandlerMapping" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="/fileview/**">jsFileViewContr</prop>
<!-- anonymous pages -->
<prop key="/login1.html">jsCommContr</prop>
<prop key="/login.html">jsCommContr</prop>
<prop key="/logout.html">jsCommContr</prop>
and
<!-- js mac method name resolver -->
<bean id="paramResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/login1.html">entry</prop>
<prop key="/home.html">homePage</prop>
<prop key="/login.html">login</prop>
I have also added following code to JSCommonController.java in com.jaspersoft.jasperserver.war.control package.
public ModelAndView login1(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/login");
}
public ModelAndView login2(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/login");
}
i deployed server after rebuilting it.
but when i enter
localhost:8080/jasperserver/login1.html
it takes me to
localhost:8080/jasperserver/login.html
and after login on this page it takes me to
localhost:8080/jasperserver/login1.html
but when i try to login on this page login event occures succesfully but it keeps me on same page.
Anybody know how to add multiple login pages in jasper server??
Please help me out.
Thanks.
I found the way for it :) and answer is as follows:
Procedure to add new login page:
Create a new login jsp page. Example entry.jsp
Keep it in jasperserver-war/src/main/webapp/WEB-INF/jsp/modules/login/
Add entry of property of page in urlHandlerMapping bean section in jasper-servlet.xml in anonymous pages section as follows:
<bean id="urlHandlerMapping" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="/fileview/**">jsFileViewContr</prop>
<!-- anonymous pages -->
<prop key="/entry.html">jsCommContr</prop>
<prop key="/login.html">jsCommContr</prop>
<prop key="/logout.html">jsCommContr</prop>
Also add following code in same file in paramResolver bean section.
<bean id="paramResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/entry.html">entry</prop>
<prop key="/home.html">homePage</prop>
<prop key="/login.html">login</prop>
<prop key="/entry.html">jsCommContr</prop>
This will call controller servlet which is mapped as
<bean id="jsCommContr" class="com.jaspersoft.jasperserver.war.control.JSCommonController">
Add following code in com.jaspersoft.jasperserver.war.control.JSCommonController.java
public ModelAndView entry(HttpServletRequest req, HttpServletResponse
res)
throws ServletException {
setupLoginPage(req);
return new ModelAndView("modules/login/entry");
}
This will load entry.jsp from folder modules/login/ folder for url
localhost:8080/jasperserver/entry.html
We also have to add this page entry to the filterInvocationInterceptor bean in applicationContext-security-web.xml
Modify applicationContext-security.xml as follows:
<bean id="filterInvocationInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager"/>
</property>
<property name="accessDecisionManager">
<ref bean="httpRequestAccessDecisionManager"/>
</property>
<!-- <property name="runAsManager"><ref bean="runAsManager"/></property> -->
<property name="objectDefinitionSource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/entry.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR
/login.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR
/logout.html=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMINISTRATOR,IS_AUTHENTICATED_FULLY
Build the war file again and redeploy it on server.
Now you can use
localhost:8080/jasperserver/entry.html
as login page.
To change UI of login page customize entry.jsp and pageSpecific.css.
Locations of files:
entry.jsp :- /jasperserver/jasperserver-war/src/main/webapp/WEB-INF/jsp/modules/login/entry.jsp
jasperserver-servlet.xml :- /jasperserver/jasperserver-war/src/main/webapp/WEB-INF/jasperserver-servlet.xml
JSCommonController.java :-
Physical path: /jasperserver/jasperserver-war-jar/src/main/java/com/jaspersoft/jasperserver/war/control/JSCommonController.java
Package Path: com.jaspersoft.jasperserver.war.control/ JSCommonController
applicationContext-security-web.xml :- /jasperserver/jasperserver-war/shared-config/applicationContext-security-web.xml

Spring Batch MultiResourcePartitioner Performance building BATCH_STEP_EXECUTION table

We have jobs that might process up to 20,000 files. We are using a MultiResourcePartitioner to set things up. The job does run, but we have noticed a bottleneck.
SpringBatch is creating entries in the BATCH_STEP_EXECUTION table for each file found, and will not process any files until it has created a table entry for every file. The loading of this table seems to take a very long time.
In local testing, trying to process just 1,000 files, it is taking 38-40 minutes to add the rows to 'BATCH_STEP_EXECUTION'. Once the table is loaded, the files are processed quite rapidly (usually under 1 minute).
I would hope that this is not typical behavior and that I am just missing something.
Here is how the database is set up (we really subclass the 'OracleDataSource' (we are using 'ojdbc6.jar' file to get to the class) and the db_file is a properties file to get to the url, password, etc.):
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<constructor-arg value="db_file" />
<property name="connectionCachingEnabled" value="true" />
<property name="connectionCacheProperties">
<props merge="default">
<prop key="InitialLimit">10</prop>
<prop key="MinLimit">25</prop>
<prop key="MaxLimit">50</prop>
<prop key="InactivityTimeout">1800</prop>
<prop key="AbandonedConnectionTimeout">900</prop>
<prop key="MaxStatementsLimit">20</prop>
<prop key="PropertyCheckInterval">20</prop>
</props>
</property>
</bean>
Here is the rest of the JobRepository definition:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" >
<property name="databaseType" value="oracle" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT"/>
</bean>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobParametersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
Anyone have any ideas?
As an FYI, SpringSource has identified this as a bug: Batch-1908.
As a workaround, we are simply lowering the number of files to process with a given run, and then increasing the number of times that the job runs in a given day.
We are using 2,000 as our file limit as it provides acceptable performance.
Take this as alternate approach.
For loading the table from files better to use LOADDATA .
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-load.html
This will improve the performance in a better way. For me its take only 30 seconds to process a file with 1 million records

Heroku's Spring MVC Hibernate template application not connecting to DB

I'm trying to get the sample application running, but getting the following error when it tries to connect to the db:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
I haven't changed the applicationContext.xml, and the particular portion is:
<beans profile="default">
<jdbc:embedded-database id="dataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
</beans>
<beans profile="prod">
<bean class="java.net.URI" id="dbUrl">
<constructor-arg value="#{systemEnvironment['DATABASE_URL']}"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="#{ 'jdbc:postgresql://' + #dbUrl.getHost() + #dbUrl.getPath() }"/>
<property name="username" value="#{ #dbUrl.getUserInfo().split(':')[0] }"/>
<property name="password" value="#{ #dbUrl.getUserInfo().split(':')[1] }"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- change this to 'verify' before running as a production app -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
</beans>
I am able to connect to the db using pgAdmin III from my laptop.
Also, I am learning Spring, and I see some beans are wrapped in the profile "prod", but I cannot tell anywhere in code or web.xml that uses a particular profile.
Does the application server (Heroku?) need to start in a particular mode/profile, could that be why the db connection is not opening?
I'm learning Heroku as well.
Are you trying to run application on local machine? To be able to run this sample project on your local machine, you need to have database created. It's not described in the tutorial but if you try to use sample DATABASE_URL (postgres://scott:tiger#localhost/myapp) you need to create user scott with password tiger and create database myapp and grant scott required privileges. What I did, I've created sampledb database with existing postgres user, since it's database admin, I don't need to bother with grants and just changed url to
export DATABASE_URL=postgres://postrges:<password>#localhost/sampledb