Spring 4 lazy-init not honoured for org.springframework.jms.listener.adapter.MessageListenerAdapter? - lazy-loading

I'm trying to convert a Spring 3 app to Spring 4 (4.3.2.RELEASE) but I can't get org.springframework.jms.listener.adapter.MessageListenerAdapter to lazy load anymore.
To isolate the problem I removed all references to the following bean def but it still tries to load and throws a java.lang.NoClassDefFoundError: javax/jms/MessageListener, which is a runtime dependency that I am not providing on purpose in this setup:
<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter" lazy-init="true" scope="prototype">
<property name="defaultListenerMethod" value="handleRequest"/>
<property name="defaultResponseDestination" ref="defaultResponseDestination" />
<property name="delegate" ref="stringRequestToStreamRequestHandler" />
</bean>
Is this expected behaviour or a bug?

Related

**Plugging in Custom Serializer in Apache Ignite**

Plugging in Custom Serializer in Apache Ignite
I tried to add Kyro Serializer in the Binary Configuration bean but at runtime it gave me a class type conversion error.
My Code is
<property name="binaryConfiguration">
<bean class="org.apache.ignite.configuration.BinaryConfiguration">
<property name="typeConfigurations">
<list>
<bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
<property name="typeName" value="testPojo" />
<property name="serializer">
<bean class="com.esotericsoftware.kryo.serializers.DefaultSerializers" />
</property>
</bean>
</list>
</property>
</bean>
</property>
Error Log is
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.esotericsoftware.kryo.serializers.DefaultSerializers] to required type [org.apache.ignite.binary.BinarySerializer] for property 'serializer': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:302)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
... 104 more
On digging in the Apache Ignite provided BinarySerializer, came to a conclusion that one has to write a custom implementation for the serializer as Other plugin Serializers to implement it.
How is the Optimized Marshaller beneficial ?
BinarySerializer is an interface that can be implemented to customize (de)serialization logic for a particular type. This is an analogy to Externalizable for BinaryMarshaller, which is the default marshaller since Ignite 1.5. Refer to this page for details: https://apacheignite.readme.io/docs/binary-marshaller
OptimizedMarshaller implements legacy serialization protocol, which was used before binary format was introduced. It's still available, but binary format is recommended.
You can also implement your own marshaller (e.g., based on Kryo). To do this, implement the Marshaller interface and provide this implementation in configuration via IgniteConfiguration.setMarshaller() property.

Could not refresh JMS Connection for destination 'queue://inventorydsDestination' - retrying in 5000 ms. Cause: AOP configuration seems to be invalid

I'm getting the following exception when I re-deploy the application war in the Tomcat manager. For example, on first time deployment it connects to the external ActiveMQ properly but when I stop/start the war in Tomcat manager, then the following execption is thrown repeatedly. After this, the JMS does not connect to ActiveMQ with the below exception:
[2015-09-13T04:03:33.689] | [ERROR] | [inventorydsRequestListenerContainer-1] | [Could not refresh JMS Connection for destination 'queue://inventorydsDestination' - retrying in 5000 ms. Cause: AOP configuration seems to be invalid: tried calling method [public abstract javax.jms.Connection javax.jms.ConnectionFactory.createConnection() throws javax.jms.JMSException] on target [org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter#168d95c7]; nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException#2fb6f3c3]
applicationContext-Jms.xml
<bean id="jmsJndiConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${inventory.mq.name}"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.jms.QueueConnectionFactory" />
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="jmsJndiConnectionFactory" />
<property name="sessionCacheSize" value="10" />
</bean>
connectionFactory - JNDI configuration
<bean id="jndiName" class="java.lang.String">
<constructor-arg value="${inventory.mq.name}"/>
</bean>
<bean id="bindingObject" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="mqConnectionFactory" />
<property name="username" value="${inventory.activeMQ.username}" />
<property name="password" value="${inventory.activeMQ.password}" />
</bean>
<bean id="mqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${inventory.activeMQ.brokerurl}" />
</bean>
Properties:
inventory.activeMQ.brokerurl=tcp://localhost:61616
inventory.activeMQ.username=admin
inventory.activeMQ.password=admin
inventory.mq.name=jms/connectionFactory
inventory.queue.type=org.apache.activemq.command.ActiveMQQueue
I had similar issue and discovered it was a classpath issue between tomcat and my web application. I needed to set the scope of the jms dependency in my web app to provided instead of the default (i.e. compile). That way, my WAR deployable did not contain another jms jar that clashed with the jms classes contained in the apache-activemq-all jar that was located in the tomcat lib folder.
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms-api</artifactId>
<version>1.1-rev-1</version>
<scope>provided</scope>
</dependency>
Try after skipping ALL Breakpoints in Debug mode/ Switch off Debug Mode or Run in Run Mode

Apache Camel JPA: Connect to two database instances

Is there an obvious way to use two JPA consumers/producers in the Camel Spring DSL to talk to two different database instances? I tried to configure two EntityManagerFactory instances pointing to two Persistence Units but end up with the following when error :(
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: Found 2 beans of type: interface javax.persistence.EntityManagerFactory. Only one bean expected.
Camel Version: 2.13.2
You might have to make 2 entity manager factories, and have them point at different persistence units.
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="primary" />
</bean>
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="secondary" />
</bean>
then when you set up the jpa bean, you can specify two different origins
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jpa2" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory2" />
<property name="transactionManager" ref="transactionManager" />
</bean>
and use:
<from uri="jpa://
or
<from uri="jpa2://

Access activemq Poolable Connection factory as OSGI service

I am using fuse 6.0 and activemq 5.8. Instead of defining activemq poolable connection factory in each bundle, it makes sense to define in a common bundle and expose it as osgi service. I created blue print file in FUSE_HOME/etc and opened an osgi service like this.
<osgix:cm-properties id="prop" persistent-id="xxx.xxx.xxx.properties" />
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${xxx.url}" />
<property name="userName" value="${xxx.username}" />
<property name="password" value="${xxx.password}" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="${maxconnections}" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
<service-properties>
<entry key="name" value="localhost"/>
</service-properties>
</service>
and when i try to access this service in both blueprint files and spring text files like this
<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="concurrentConsumers" value="${xxx.concurrentConsumers}"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>
but I am getting following expection during bundles startup.
Failed to add Connection ID:PLNL6237-55293-1401929434025-11:1201, reason: java.lang.SecurityException: User name [null] or password is invalid.
I even defined compendium definition in my bundles.
How can i solve this problem? any help is appreciated.
I found this online https://issues.apache.org/jira/i#browse/SM-2183
Do i need to upgrade?
It looks to me like you're using the property placeholders incorrectly. First of all, you should know what osgix:cm-properties only exposes the properties at the persistent id that you specify. You can treat it like a java.util.Properties object, and even inject it into a bean as one. This does however mean that it makes no attempt to resolve the properties.
To resolve properties, use spring's property placeholder configurer.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties" ref="prop"/>
</bean>
P.S. The persistent id of cm-properties is the name of the file, not including the file type. You don't need the .properties at the end.

Apache cxf using XSLTJaxbProvider as a JAXRSDataBinding

(apologies for broken links at stackoverflow limits new users to 2 in one post!)
I've scaffolded a web service server using Spring STS and MyEclipse for spring and was interested in transforming the out going soap message.
First thing I wanted to transform was the namespace prefixing so my spring config looked like this
<jaxws:endpoint xmlns:tns="ttps://etc etc">
<jaxws:dataBinding>
<ref bean="data-binding"/>
</jaxws:dataBinding>
</jaxws:endpoint>
<bean ref="data-binding" class="org.apache.cxf.jaxb.JAXBDataBinding">
<property name="namespaceMap">
<map>
<entry>
<key>
<value>ttp://thing</value>
</key>
<value>BeepBeep</value>
</entry>
</map>
</property>
</bean>
this worked fine and my soap message was outputted completely and correctly.
<as>
<b>
<stuff/>
</b>
<c>
<more stuff/>
</c>
</as>
Second I need to change the soap xml but more than the transform features at http://cxf.apache.org/docs/transformationfeature.html allowed
so I read up about the XSLTJaxbProvider at http://cxf.apache.org/docs/jax-rs-advanced-xml.html and plugging in a rs provider to a ws binding at ttp://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CXFDataBindingsasJAXRSproviders to create the following config
<jaxws:endpoint xmlns:tns="ttps://etc etc">
<jaxws:dataBinding>
<ref bean="jaxrs-data-binding"/>
</jaxws:dataBinding>
<bean id="jaxrs-data-binding" class="org.apache.cxf.jaxrs.provider.JAXRSDataBinding">
<property name="namespaceMap">
<map>
<entry>
<key>
<value>ttp://thing</value>
</key>
<value>BeepBeep</value>
</entry>
</map>
</property>
<property name="provider" ref="xsltProvider"/>
<bean id="xsltProvider" class="org.apache.cxf.jaxrs.provider.XSLTJaxbProvider">
<property name="outTemplate" value="classpath:/WEB-INF/templates/transform.xsl"/>
</bean>
now I get an JAXB Exception: Class not known to this context for classes b and c and even if I have an empty xslt stylesheet I get the xml
<as/>
I have tinkered with the config to every end and added #XmlSeeAlso all over the place to no avail.
I guess I have to ask is what I've done possible in config? The fact that it all works as expected before I try and wire in the rs provider as a ws databinding might mean it's not?
Any advice greatly appreciated. Maybe there is a better way to use xslt/manipulate the xml?
Thanks