Log JavaMailSenderImpl - spring

i use Spring to send email in my application.
I want to log the imap server operation, when i send emails.
I try to implement log in my applicationContext.xml as follow:
<bean id="JavaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${smtpHost}" />
<property name="port" value="${smtpPort}" />
<property name="username" value="${userName}" />
<property name="password" value="${password}" />
<property name="session" ref="mailSession" />
<props>
<prop key="mail.debug">true</prop>
</props>
</bean>
but doesn't works.Any suggest?
Thanks

You're missing the outer property.
...
<property name="session" ref="mailSession">
<property name="javaMailProperties">
<props>
<prop key="mail.debug">true</prop>
</props>
</property>
...

Related

Spring MVC JavaMailSenderImpl parameters from properties for javaMailProperties

I have a spring configuration of JavaMailSenderImpl included in my mvc.properties file like this:
email.smtp.host=smtp.example.com
email.smtp.port=25
email.smtp.username=example
email.smtp.password=example
email.smtp.auth=false
email.smtp.starttls.enable=false
And my XML configuration of the mail sending bean in servlet is following:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${email.smtp.host}"/>
<property name="port" value="${email.smtp.port}"/>
<property name="username" value="${email.smtp.username}"/>
<property name="password" value="${email.smtp.password}"/>
<property name="protocol" value="smtp"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
I was trying to find information about how to include parameters from properties file also for javaMailProperties, but I am stuck.
I would like to achieve something like that, but this is not working:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${email.smtp.host}"/>
<property name="port" value="${email.smtp.port}"/>
<property name="username" value="${email.smtp.username}"/>
<property name="password" value="${email.smtp.password}"/>
<property name="protocol" value="smtp"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth" value="${email.smtp.auth}"></prop>
<prop key="mail.smtp.starttls.enable" value="${email.smtp.starttls.enable}"></prop>
</props>
</property>
</bean>
How to include such properties also into javaMailProperties?
The way I am doing this by referencing settings stored in a configuration file looks something like this:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${email.smtp.host}"/>
<property name="port" value="${email.smtp.port}"/>
<property name="username" value="${email.smtp.username}"/>
<property name="password" value="${email.smtp.password}"/>
<property name="protocol" value="smtp"/>
<property name="javaMailProperties" ref="propertyConfigurer"/>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:foo.properties</value>
<value>classpath:mail.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

How to listen jms-queue from remote server

i have implemented jms queue and listner in spring application.
I am not able to listen jms queue from remote system. I have configured Queue in server application util-sevice.xml file.
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">http-remoting://182.18.177.115:80</prop>
<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory
</prop>
<prop key="java.naming.security.principal">user</prop>
<prop key="java.naming.security.principal">pwd</prop>
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName" value="jms/RemoteConnectionFactory">
</property>
</bean>
<bean id="credentialsconnectionfactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionFactory" />
<property name="username" value="use" />
<property name="password" value="pwd" />
</bean>
<bean id="genricDbSyncDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="java:/jms/queue/GenricDbSyncQueue" />
</bean>
<bean id="genricDbSyncTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="credentialsconnectionfactory" />
<property name="defaultDestination" ref="genricDbSyncDestination" />
</bean>
standalone-full.xml in remote server
<jms-queue name="GenricDbSyncQueue">
<entry name="jms/queue/GenricDbSyncQueue"/>
<entry name="java:jboss/exported/jms/queue/GenricDbSyncQueue"/>
</jms-queue>
and my local system spring application util-service.xml config file for listening that queue
<bean id="genricDbSyncListener" class="com.ayotta.genericdbsync.GenericDbSyncConsumer" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">http-remoting://182.18.177.115:80</prop>
<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory
</prop>
<property name="username" value="use" />
<property name="password" value="pwd" />
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName" value="jms/RemoteConnectionFactory">
</property>
</bean>
<bean id="credentialsconnectionfactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionFactory" />
<property name="username" value="use" />
<property name="password" value="pwd" />
</bean>
<jms:listener-container connection-factory="credentialsconnectionfactory"
concurrency="1" acknowledge="auto" destination-type="queue">
<jms:listener destination="GenricDbSyncQueue" ref="genricDbSyncListener"
method="onMessage" />
</jms:listener-container>
How to listen that remote jms queue from local system application

FreeMarkerViewResolver not render the template when i request use ajax

Sorry everyone. My english is so bad,but i have some questions to ask.
When i try to use ajax get a freemarker view.It's not render just html code.
The following is my config.
springmvc-servlet.xml
<bean id="freemakerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".html" />
<property name="contentType" value="text/html;charset=UTF-8"></property>
<property name="requestContextAttribute" value="request" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
</bean>
freeMarkerConfigurer
<bean id="freeMarkerConfigurer"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/views/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="number_format">0.##########</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
</bean>
my view
<ul>
<#list items as item>
<li>item.name</li>
</#list>
</ul >
response data
<ul></ul >
It's my wrong.I submit the wrong parameters,so the list is empty.

Spring 4 + Spring Batch + Quartz 2.2.x tutorial

I've been looking for days now for a simple implementation of Spring batch processor with the scheduler (Quartz) but with no luck! all the samples that i laid my hands on were not working or depreciated, my application should provide setting the job firing time dynamically (retrieved from Database)
try adding below code in spring-quartz.xml file
<!--testAlerts cron trigger -->
<bean id="testAlertsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="testAlertsTrigger" />
<property name="jobDetail" ref="testAlertsJobDetail" />
<property name="cronExpression" value="0 0 4 * * ?" />
</bean>
<!-- scheduler -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="hbnTransactionManager" />
<property name="triggers">
<list>
<ref bean="testAlertsTrigger" />
</list>
</property>
<property name="schedulerContextAsMap">
<map>
<entry key="commandDispatcher" value-ref="commandDispatcher" />
</map>
</property>
<property name="autoStartup" value="${QUARTZ.org.quartz.autoStartup}" />
<property name="overwriteExistingJobs" value="${QUARTZ.org.quartz.overwriteExistingJobs}" />
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceId">${QUARTZ.org.quartz.scheduler.instanceId}</prop>
<prop key="org.quartz.scheduler.instanceName">${QUARTZ.org.quartz.scheduler.instanceName}</prop>
<prop key="org.quartz.threadPool.threadCount">${QUARTZ.org.quartz.threadPool.threadCount}</prop>
<prop key="org.quartz.jobStore.class">${QUARTZ.org.quartz.jobStore.class}</prop>
<prop key="org.quartz.jobStore.isClustered">${QUARTZ.org.quartz.jobStore.isClustered}</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">${QUARTZ.org.quartz.jobStore.clusterCheckinInterval}</prop>
</props>
</property>
</bean>

Not seeing BoneCP shutdown() with Hibernate, Spring, Bonecp

I am implementing an application with Spring, Hibernate and BoneCP. When I invoke the shutdown script of Tomcat I see errors like this
The web application [/REST] appears to have started a thread named [BoneCP-release-thread-helper-thread] but has failed to stop it. This is very likely to create a memory leak.
When i see my logs, I am not seeing "Shutting down connection pool...", so I am assuming I am missing something over here.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
xmlns:context="http://www.springframework.org/schema/context">
<bean id="LookupService" class="com.appserver.rest.LookupService">
<property name="userManager" ref="UserManager"></property>
<property name="groupManager" ref="GroupManager"></property>
<property name="messageManager" ref="MessageManager"></property>
<property name="tokenManager" ref="TokenManager"></property>
<property name="accessManager" ref="AccessManager"></property>
<property name="rosterManager" ref="RosterManager"></property>
</bean>
<bean id="LookupServiceV2" class="com.appserver.rest.LookupServiceV2"
parent="LookupService">
</bean>
<bean id="UserManager" class="com.appserver.rest.UserManager">
<constructor-arg index="0">
<ref bean="authManager" />
</constructor-arg>
</bean>
<bean id="GroupManager" class="com.appserver.rest.GroupManager">
<constructor-arg index="0">
<ref bean="authManager" />
</constructor-arg>
</bean>
<bean id="MessageManager" class="com.appserver.rest.MessageManager">
</bean>
<bean id="TokenManager" class="com.appserver.rest.TokenManager">
<constructor-arg index="0">
<ref bean="secureRandom" />
</constructor-arg>
</bean>
<bean id="authManager" class="com.appserver.rest.AuthenticationManager">
<constructor-arg index="0">
<ref bean="secureRandom" />
</constructor-arg>
</bean>
<bean id="AccessManager" class="com.appserver.rest.AccessManager">
</bean>
<bean id="RosterManager" class="com.appserver.rest.RosterManager">
</bean>
<bean id="secureRandom" class="java.security.SecureRandom">
</bean>
<bean id="messageDeleteScheduler" class="com.appserver.schema.MessageDeleteScheduler" />
<bean id="messageDeleteJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="messageDeleteScheduler" />
<property name="targetMethod" value="scheduleMessageDeletion" />
</bean>
<bean id="messageDeleteTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="messageDeleteJob" />
<property name="repeatInterval" value="3600000" />
<property name="startDelay" value="1000" />
</bean>
<bean id="quartz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy" >
<property name="jobDetails">
<list>
<ref bean="messageDeleteJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="messageDeleteTrigger" />
</list>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
autowire="autodetect">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.appserver.schema.GroupDB</value>
<value>com.appserver.schema.UserDB</value>
<value>com.appserver.schema.MessageDB</value>
<value>com.appserver.schema.UserBlockDB</value>
<value>com.appserver.schema.GroupUserMapperDB</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- <prop key="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop> -->
<!-- <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost/testdb</prop>
<prop key="hibernate.connection.username">alpha1</prop>
<prop key="hibernate.connection.password">r0cktheworld</prop>
<prop key="hibernate.connection.pool_size">50</prop>
-->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.globally_quoted_identifiers">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EHCacheProvider</prop>
<!-- <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> -->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<!-- this is connection provider -->
<!-- and this is how you configure it -->
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="jadira.usertype.databaseZone">jvm</prop>
<prop key="jadira.usertype.javaZone">jvm</prop>
</props>
</property>
</bean>
<!-- Spring bean configuration. Tell Spring to bounce off BoneCP -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref local="mainDataSource" />
</property>
</bean>
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost/dbrocker" />
<property name="username" value="root"/>
<property name="password" value="root123"/>
<property name="idleConnectionTestPeriod" value="60"/>
<property name="idleMaxAge" value="240"/>
<property name="maxConnectionsPerPartition" value="60"/>
<property name="minConnectionsPerPartition" value="20"/>
<property name="partitionCount" value="3"/>
<property name="acquireIncrement" value="10"/>
<property name="statementsCacheSize" value="50"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
<context:annotation-config/>
Thanks
This is a known issue. See https://code.google.com/p/guava-libraries/issues/detail?id=92.
Try using the snapshot version of bonecp-0.8.0-rc2 which contains 14.0.1 version of guava that has fixes for guava Finalizer thread not closed.
You can grab the snapshot from here -> https://oss.sonatype.org/content/repositories/snapshots/com/jolbox/bonecp/0.8.0-rc2-SNAPSHOT/

Resources