Consuming from Kafka failed; nested exception is java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Iterator is in failed state - spring

Below is my consumer and producer XML I can send message successfully on topic and can read from consumer but in console I am getting below error:
10823 [taskExecutor-30] ERROR
org.springframework.integration.handler.LoggingHandler -
org.springframework.messaging.MessagingException: Consuming from Kafka
failed; nested exception is java.util.concurrent.ExecutionException:
java.lang.IllegalStateException: Iterator is in failed state
Consumer XML
<?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:int="http://www.springframework.org/schema/integration"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xmlns:int-kafka="http://www.springframework.org/schema/integration/kafka"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
http://www.springframework.org/schema/integration/kafka http://www.springframework.org/schema/integration/kafka/spring-integration-kafka.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<int:channel id="inputFromKafka">
<int:queue />
</int:channel>
<int:service-activator input-channel="inputFromKafka"
ref="messageProcessor" method="reader" >
<int:poller fixed-rate="50" task-executor="taskExecutor" >
</int:poller>
</int:service-activator>
<bean id="consumerProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="auto.offset.reset">largest</prop>
<prop key="socket.receive.buffer.bytes">10485760</prop>
<prop key="fetch.message.max.bytes">5242880</prop>
<prop key="auto.commit.interval.ms">100000</prop>
</props>
</property>
</bean>
<int-kafka:zookeeper-connect id="zookeeperConnect"
zk-connect="localhost:2181" zk-connection-timeout="6000"
zk-session-timeout="6000" zk-sync-time="2000" />
<bean id="kafkaThreadListener" class="com.maistylz.adminui.integration.ConsumerStarter"
init-method="initIt" />
<int-kafka:inbound-channel-adapter
kafka-consumer-context-ref="consumerContext" auto-startup="true"
channel="inputFromKafka" id="kafka-inbound-channel-adapter" >
<int:poller fixed-delay="1000" time-unit="MILLISECONDS"
receive-timeout="1000" />
</int-kafka:inbound-channel-adapter>
<task:executor id="taskExecutor" pool-size="50" keep-alive="120" queue-capacity="500"/>
<int-kafka:consumer-context id="consumerContext"
consumer-timeout="400000" zookeeper-connect="zookeeperConnect"
consumer-properties="consumerProperties" >
<int-kafka:consumer-configurations>
<int-kafka:consumer-configuration
group-id="default" max-messages="500" executor="taskExecutor">
<int-kafka:topic id="event-stream" streams="1" />
</int-kafka:consumer-configuration>
</int-kafka:consumer-configurations>
</int-kafka:consumer-context>
</beans>
Producer XML
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-kafka="http://www.springframework.org/schema/integration/kafka"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration/kafka http://www.springframework.org/schema/integration/kafka/spring-integration-kafka.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<int:channel id="inputToKafka">
<int:queue/>
</int:channel>
<bean id="producerProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="topic.metadata.refresh.interval.ms">360000000</prop>
<prop key="message.send.max.retries">5</prop>
<prop key="send.buffer.bytes">5242880</prop>
</props>
</property>
</bean>
<bean id="encoder"
class="org.springframework.integration.kafka.serializer.common.StringEncoder" />
<int-kafka:outbound-channel-adapter
id="kafkaOutboundChannelAdapter" auto-startup="true"
kafka-producer-context-ref="kafkaProducerContext"
channel="inputToKafka" >
<int:poller fixed-delay="1000" receive-timeout="0" task-executor="taskExecutor"/>
</int-kafka:outbound-channel-adapter>
<task:executor id="taskExecutor" pool-size="5" keep-alive="1200" queue-capacity="10000"/>
<int-kafka:producer-context id="kafkaProducerContext">
<int-kafka:producer-configurations>
<int-kafka:producer-configuration broker-list="localhost:9092"
topic="event-stream"
key-class-type="java.lang.String"
value-class-type="java.lang.String"
value-encoder="encoder"
key-encoder="encoder"
/>
</int-kafka:producer-configurations>
</int-kafka:producer-context>
</beans>

Related

Hikari configuration in xml for Master/Slave Datasources

Presently I have a datasource configured using Hikari in my applicationContext.xml. I want to configure in the same xml file for a master/slave kind of datasource.
Also how do I establish a new entity manager factory in the same ?
My applicationContext.xml which is configured for 1 datasource(read as master) looks like:
<xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
<context:spring-configured />
<context:component-scan base-package="com.lkart.dao">
</context:component-scan>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
<property name="dataSourceClassName" value="${database.driverClassName}" />
<property name="maximumPoolSize" value="10" />
<property name="maxLifetime" value="1800000" />
<property name="idleTimeout" value="600000" />
<property name="connectionTimeout" value="60000" />
<property name="dataSourceProperties">
<props>
<prop key="url">${database.url}</prop>
<prop key="user">${database.username}</prop>
<prop key="password">${database.password}</prop>
<prop key="prepStmtCacheSize">250</prop>
<prop key="prepStmtCacheSqlLimit">2048</prop>
<prop key="cachePrepStmts">true</prop>
<prop key="useServerPrepStmts">true</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager"
id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
How do I configure this xml for adding a slave datasource ?
specify url as described in mysql connector-j documentation

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils

As am working on WildFly 8, am getting an error like
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
Log:
{"JBAS014671: Failed services" => {"jboss.undertow.deployment.default-server.default-host./Sample" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./Sample: Failed to start service
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils"}}
This is applicationContext.xml file Code:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"`
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.0.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.rss.master" use-default-filters="false">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#localhost:1521:XE"/>
<property name="username" value="RSS"/>
<property name="password" value="12345"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="format_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>hbm/ExRateMaster.hbm.xml</value>
</list>
</property>
</bean>
<bean id="exRateMasterDao" class="com.rss.master.dao.impl.ExRateMasterDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="exRateMasterBo" class="com.rss.master.bo.impl.ExRateMasterBoImpl">
<property name="exRateMasterDao" ref="exRateMasterDao"/>
</bean>
</beans>

Spring ACL issue with disk store ehcache

I'm trying to implement Spring ACL, but I encountered an issue to which i have no clue of how to solve.
We have a running configuration of echache which is loaded from the following spring context.
<?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:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Support annotation configuration -->
<context:annotation-config />
<context:property-placeholder location="META-INF/test.properties" ignore-unresolvable="true" ignore-resource-not-found="true" />
<!-- Database access -->
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.iwh.driver}" />
<property name="url" value="${db.iwh.url}" />
<property name="username" value="${db.iwh.username}" />
<property name="password" value="${db.iwh.password}" />
<property name="initialSize" value="${db.iwh.initialConnections}" />
<property name="maxActive" value="${db.iwh.maxConnections}" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="datasource"/>
</bean>
<!-- JPA with Hibernate -->
<util:list id="productEntityPackages"/> <!-- Placeholder -->
<util:list id="projectEntityPackages"/> <!-- Placeholder -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datasource"/>
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
<property name="jpaVendorAdapter">
<bean class="dk.intelligentsystems.platform.util.spring.ISHibernateJpaVendorAdapter">
<property name="databasePlatform" value="${db.iwh.dialect}"/>
<property name="showSql" value="${db.iwh.show_sql}"/>
<property name="hbm2ddl" value=""/>
<!-- <property name="hbm2ddlImportFiles" value="''"/> -->
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.cache.default_cache_concurrency_strategy">read-write</prop>
<prop key="net.sf.ehcache.configurationResourceName">/META-INF/ehcache.xml</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<!--prop key="javax.persistence.sharedCache.mode">DISABLE_SELECTIVE</prop-->
</props>
</property>
<!--property name="packagesToScan" ref="entityManagerPackages"/-->
<!-- Managing transactions explicitly -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="txInterceptor" class="dk.intelligentsystems.platform.tx.ISTransactionInterceptor" />
<aop:config>
<!-- Add custom transaction interceptor to all #Transactional methods -->
<aop:pointcut id="transactionalMethod" expression="#annotation(org.springframework.transaction.annotation.Transactional) || within(#org.springframework.transaction.annotation.Transactional *)"/>
<aop:advisor pointcut-ref="transactionalMethod" advice-ref="txInterceptor" order="1"/>
</aop:config>
<!-- Task scheduling -->
<task:scheduler id="taskScheduler" pool-size="8"/>
</beans>
The ehcache looks as:
<?xml version="1.0" encoding="UTF-8"?>
<!-- See http://ehcache.org/documentation/user-guide/hibernate -->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
maxElementsOnDisk="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskExpiryThreadIntervalSeconds="120"
statistics="true"
memoryStoreEvictionPolicy="LRU"/>
<cache name="dk.platform.model.Alarm"
maxElementsInMemory="2000"
eternal="false"
timeToIdleSeconds="360"
timeToLiveSeconds="360">
</cache>
...
The ACL is loaded in this application context (Bottom part stolen from spring security contacts sample):
<?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="spring-test-base.xml"/>
<sec:global-method-security pre-post-annotations="enabled" secured-annotations="disabled" jsr250-annotations="disabled" proxy-target-class="true">
<sec:expression-handler ref="expressionHandler" />
</sec:global-method-security>
<bean id="expressionHandler"
class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<property name="permissionEvaluator">
<bean id="permissionevaluator" class="dk.company.util.AuthorizationProvider">
</bean>
</property>
</bean>
<!-- ========= ACL SERVICE DEFINITIONS ========= -->
<bean id="aclCache" class="org.springframework.security.acls.domain.EhCacheBasedAclCache">
<constructor-arg>
<bean class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
</property>
<property name="cacheName" value="aclCache"/>
</bean>
</constructor-arg>
</bean>
<bean id="lookupStrategy" class="org.springframework.security.acls.jdbc.BasicLookupStrategy">
<constructor-arg ref="datasource"/>
<constructor-arg ref="aclCache"/>
<constructor-arg>
<bean class="org.springframework.security.acls.domain.AclAuthorizationStrategyImpl">
<constructor-arg>
<bean class="org.springframework.security.core.authority.SimpleGrantedAuthority">
<constructor-arg value="ROLE_ADMINISTRATOR"/>
</bean>
</constructor-arg>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.acls.domain.ConsoleAuditLogger"/>
</constructor-arg>
</bean>
<bean id="aclService" class="org.springframework.security.acls.jdbc.JdbcMutableAclService">
<constructor-arg ref="datasource"/>
<constructor-arg ref="lookupStrategy"/>
<constructor-arg ref="aclCache"/>
</bean>
</beans>
When I try to run the application I get the following exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
// Some thousand stack frames...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.ehcache.EhCacheFactoryBean#51e88ff6' defined in class path resource [META-INF/spring-authorization-test.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
... 45 more
Caused by: net.sf.ehcache.CacheException: aclCache Cache: Could not create disk store. This CacheManager configuration does not allow creation of DiskStores. If you wish to create DiskStores, please configure a diskStore path.
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory.getDataFile(DiskOverflowStorageFactory.java:79)
at net.sf.ehcache.store.compound.factories.DiskOverflowStorageFactory.<init>(DiskOverflowStorageFactory.java:71)
at net.sf.ehcache.store.compound.impl.OverflowToDiskStore.create(OverflowToDiskStore.java:63)
at net.sf.ehcache.Cache.initialise(Cache.java:1113)
at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1081)
at net.sf.ehcache.CacheManager.addCache(CacheManager.java:987)
at org.springframework.cache.ehcache.EhCacheFactoryBean.afterPropertiesSet(EhCacheFactoryBean.java:333)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 48 more
I tried removing the <diskStore path="java.io.tmpdir"/> line in the ehcache, but to no avail.
EDIT
Spring version: 3.2.4.RELEASE
Ehcache version: 4.1.9.Final
According to EhCache documentation, you can turn off usage of disk for a cache by setting the overflowToDisk attribute to false. So you could try :
<defaultCache
maxElementsInMemory="10000"
overflowToDisk="false"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskExpiryThreadIntervalSeconds="120"
statistics="true"
memoryStoreEvictionPolicy="LRU"/>

Dependency Injection is working at Mule application startup. Objects are getting null, when a request received and Failing by throwing NullEx

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<context:component-scan base-package="com.example.hibernate" />
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/emp" />
<property name="username" value="root" />
<property name="password" value="admin" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" autowire = "byname">
<property name="dataSource" ref="myDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.connection.pool_size">20</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>Departments.hbm.xml</value>
</list>
</property>
</bean>
<bean id ="employeeDAO" class = "com.example.hibernate.dao.EmployeeDAOImpl" autowire = "byname"/>
</beans>
And here is Mflow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:context="http://www.springframework.org/schema/context"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<spring:beans>
<spring:import resource="DBConfigurations.xml" />
</spring:beans>
<data-mapper:config name="getEmployeeDetailsReq"
transformationGraphPath="getEmployeeDetailsReq.grf" doc:name="getEmployeeDetailsReq" />
<data-mapper:config name="getEmployeeDetailsResponse" transformationGraphPath="getEmployeeDetailsResponse.grf" doc:name="getEmployeeDetailsResponse"/>
<flow name="EmployeeDetailsFlow" doc:name="EmployeeDetailsFlow">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:9090/getEmployeeDetails" doc:name="Receive" />
<object-to-string-transformer doc:name="Object to String" />
<data-mapper:transform config-ref="getEmployeeDetailsReq"
doc:name="getEmployeeDetailsReq" />
<component doc:name="GetTemplateInfo"
class="com.example.hibernate.dao.GetEmployeeDetails" />
<data-mapper:transform config-ref="getEmployeeDetailsResponse" returnClass="java.lang.String" doc:name="getEmployeeDetailsResponse"/>
<json:object-to-json-transformer
doc:name="Object to JSON" />
</flow>
</mule>
Here is my Java Component
package com.example.hibernate.dao;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.example.hibernate.Employee;
public class GetEmployeeDetails implements Callable{
#Autowired
#Qualifier("employeeDAO")
private EmployeeDAO dao;
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
Employee emp = (Employee)eventContext.getMessage().getPayload();
return dao.getEmployeeDetailsById(emp.getId());
}
}
I have tried to inject object using autowire and also by using spring setter injection.
In both the scenarios by adding Syso in constructor and setter method I have noticed, that the object is getting injected at the time of application start up. Sysos are getting printed in the console.
When I send a request, object is getting null and failing by throwing NullPointerException.
Even the same is not working in Service classes as well.
Can any one help me out?
Thanks in advance.
Do you mind trying the following?
Add this to DBConfiguration.xml:
<bean id="getEmployeeDetails"
class="com.example.hibernate.dao.GetEmployeeDetails" />
And change the flow to:
<component>
<spring-object bean="getEmployeeDetails"/>
</component>

Spring JMS Session Issue When Using Open MQ

I'm using spring-jms-3.0.6.RELEASE and open MQ. Any ideas on why the below exception would be raise?
2012-05-02 17:56:18,420 [stuJmsContainer-803059] WARN
org.springframework.jms.listener.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination
'TestQ' - trying to recover. Cause:
MQRA:CA:createSession failed-Only one JMS Session allowed when managed connection is involved in a transaction
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring/testlistener-context-api.xml
classpath:/spring/testmsg-context-api.xml
</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
testlistener-context-api.xml:
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<tx:annotation-driven />
<bean id="testListener" class="com.test.TestListener" />
<bean id="executionInterceptor" class="com.test.ExecutionInterceptor" />
<bean id="testJmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
<property name="destinationName" value="TestQ"/>
<property name="sessionTransacted" value="false"/>
<property name="messageListener" ref="stuMessageListener" />
<property name="concurrentConsumers" value="5" />
<property name="maxConcurrentConsumers" value="100" />
<property name="receiveTimeout" value="30000" />
</bean>
</beans>
testmsg-context-api.xml:
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"/>
<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName" value="${jms.jndi.qconnectionfactory}">
</property>
</bean>
<bean id="jmsTopicConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName" value="${jms.jndi.tconnectionfactory}">
</property>
</bean>
<bean id="myJMSConnectionFactory" class="com.test.OpenMqConnectionFactoryBean">
<property name="imqAddressList" value="${jms.imq.url}" />
<property name="imqDefaultUsername" value="${jms.imq.user}" />
<property name="imqDefaultPassword" value="${jms.imq.password}" />
<property name="imqHost" value="${jms.imq.host}" />
<property name="imqPort" value="${jms.imq.port}" />
</bean>
<bean id="jmsTopicTemplate" class="com.test.CustomJMSTemplate">
<property name="connectionFactory" ref="jmsTopicConnectionFactory" />
<property name="connectionFactoryName" value="${jms.jndi.tconnectionfactory}"/>
<property name="pubSubDomain" value="true" />
</bean>
<bean id="jmsTemplate" class="com.test.CustomJMSTemplate">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="connectionFactoryName" value="${jms.jndi.qconnectionfactory}"/>
</bean>
<tx:annotation-driven />
</beans>
According to the ConnectionAdapter source code and this archive thread on OpenMQ mailing list, either Spring or your code itself creates more than one session on a single JMS Connection.
This OpenMQ behavior (raise an error) can be disabled by setting the system property imq.jmsra.inACC to false but it is not satisfying.
Without transaction manager, Spring uses org.springframework.jms.connection.SingleConnectionFactory to share a single connection for multiple consumers.
You should set DefaultMessageListenerContainer cacheLevelName property to CACHE_NONE so that each consumer thread gets its own session on a single connection.

Resources