cannot instantiate message-driven-channel-adapter - spring-integration

I am new to Spring Integration, currently I am facing one issue with Spring-JMS integration for IBM MQ. Currently only problem with Spring-JMS integration. Below mentioned are the Jar's considered for build. Kindly help me to resolve this issue.
org.springframework.integration-1.0.3.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-integration-core-2.0.5.RELEASE.jar
spring-integration-jms-2.0.5.RELEASE.jar
spring-integration-stream-2.0.5.RELEASE.jar
spring-jms-3.0.6.RELEASE.jar
spring-xml-2.0.3.RELEASE.jar
org.springframework.integration-1.0.3.RELEASE.jar
Code Snippet Starts:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<ctx:component-scan base-package="com.iflexsolutions.fcpb"/>
<channel id="InputJMSChannel"/>
<jms:message-driven-channel-adapter id="TestJMSAdapter"
destination="requestQueue" extract-payload="true"
connection-factory="connectionFactory"
channel="InputJMSChannel"
/>
<service-activator id="TestJMSServiceActivator"
input-channel="InputJMSChannel"
output-channel="stdout"
ref="wmXMLTransformerBean"
method="validateAndTransform"/>
<stream:stdout-channel-adapter id="stdout"/>
</beans:beans>
Code Snippet Starts:
Error Details:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.jms.ChannelPublishingJmsMessageListener#0': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.integration.channel.DirectChannel' to required type 'org.springframework.integration.MessageChannel' for property 'requestChannel'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.channel.DirectChannel] to required type [org.springframework.integration.MessageChannel] for property 'requestChannel': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.iflexsolutions.fcpb.mobilebanking.jms.test.LoadApp.main(LoadApp.java:11)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.integration.channel.DirectChannel' to required type 'org.springframework.integration.MessageChannel' for property 'requestChannel'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.channel.DirectChannel] to required type [org.springframework.integration.MessageChannel] for property 'requestChannel': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:481)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:518)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 11 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.channel.DirectChannel] to required type [org.springframework.integration.MessageChannel] for property 'requestChannel': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:233)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:466)
... 17 more

It looks like you have classpath issues - specifically...
spring-integration-core-2.0.5.RELEASE.jar
org.springframework.integration-1.0.3.RELEASE.jar
1.0.x is not compatible with 2.0.x.
Aside from this mismatch, I would recommend you use the current versions of Spring Framework (4.1.4) and Spring Integration (4.1.2).

Related

write own Spring PayloadTransformer and load it

I'm currently working with citrus-framework to test an application.
One of my interfaces uses Protobuf and I would like to implement a protobuf-to-json-transformer which is compatible with spring-integration to use it similarly like the following but with my transformer instead of the object-to-string-transformer:
<int:channel id="configRawReplies" />
<int:object-to-string-transformer id="configtransformer" input-channel="configRawReplies" output-channel="configResponse" />
<int:channel id="configResponse">
<int:queue />
</int:channel>
for now I have a prototyp exactly like object-to-string-transformer and I'm loading it with:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString">
<property name="input-channel" value="none"/>
<property name="output-channel" value="none"/>
</bean>
but it fails.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Proto2Json' defined in URL [file:/Users/nobody/DevOops/test/citrus-scala/target/test-classes/citrus-context.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'input-channel' of bean class [com.pme.citrus.transformer.ProtoToJSONString]:
Bean property 'input-channel' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Does somebody have an idea or an hint where to look on the web?
BR
That's correct. You really need to follow a design in the ObjectToStringTransformer to implement your own AbstractPayloadTransformer. And that one has to be as a plain <bean> definition in your application context.
Only the problem that you don't understand why we really have all those custom tags to utilize input-channel and output-channel attributes as well. The point is that this
<int:object-to-string-transformer>, for example, provides for the application context several beans, including the mentioned ObjectToStringTransformer instance, a MessageTransformingHandler and, finally, ConsumerEndpointFactoryBean to connect a MessageHandler with an inputChannel.
So, what you are missing here is a generic <int:transformer> definition for your custom AbstractPayloadTransformer implementation:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString"/>
<int:tranformer ref="Proto2Json" input-channel="configRawReplies" output-channel="configResponse"/>
Please, read more Reference Manual to avoid similar discussions in the future:
https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips
https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html

Mule RegistrationException

So this one makes me wonder. I have a Mule integration with a couple of flows in it and they all work nice. Except for the last one.
If I end that one in a file endpoint, it works as expected. But if I end it in my WS POST service.. I get an error complaining about multiple JAXB contexts.
I have multiple JAXB contexts but as said they work fine if I'm not trying to post my JSON to that REST service.
And somehow, I can't see that my HTTP endpoint has anything to do with JAXB either so I guess it's a misguiding error?
But then, what is wrong with my HTTP endpoint, I use it as inbound in the other flows and also tried to create an entirely new one for this particular flow, but still this nagging about JAXB.
<http:request-config name="WS" host="127.0.0.1" port="81" doc:name="HTTP Request Configuration" basePath="WSService"/>
<http:request-config name="MQService" host="127.0.0.1" port="82" doc:name="HTTP Request Configuration" />
<mulexml:jaxb-context name="JAXB_A" packageNames="se.razorlib.SystemAProduct" doc:name="JAXB Context"/>
<mulexml:jaxb-context name="JAXB_B" packageNames="se.razorlib.SystemAPurchase" doc:name="JAXB Context"/>
<mulexml:jaxb-context name="JAXB_C" packageNames="se.razorlib.SystemAOrder" doc:name="JAXB Context"/>
<context:property-placeholder location="razorlib.properties"/>
<flow name="ProductToSystemA">
....
<http:request config-ref="WS" path="Product/REST/GetProduct/{id}/{index}" method="GET" doc:name="WS">
<http:request-builder>
<http:uri-param paramName="id" value="${WS.id}"/>
<http:uri-param paramName="index" value="1"/>
</http:request-builder>
</http:request>
.....
</flow>
<flow name="PurchaseToSystemA">
.....
</flow>
.....
and this particular flow
<flow name="PurchaseDeliver">
<file:inbound-endpoint path="C:\temp\fileIn" responseTimeout="10000" doc:name="FileIn"/>
<mulexml:jaxb-xml-to-object-transformer returnClass="se.razorlib.SystemAPurchase.Header" encoding="UTF-16" jaxbContext-ref="JAXB_B" doc:name="XML to JAXB Object"/>
<custom-transformer returnClass="java.util.List" encoding="utf-16" class="se.razorlib.Transformer.Map2ZZPurchase" doc:name="Map2ZZ"/>
<json:object-to-json-transformer encoding="UTF-16" doc:name="Object to JSON"/>
<logger message="'Payload ' #[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="WS" path="PurchaseSvc/REST/Deliver/{id}" method="POST" doc:name="WSDeliver">
<http:request-builder>
<http:uri-param paramName="id" value="${WS.id}"/>
</http:request-builder>
</http:request>
<!-- <file:outbound-endpoint path="C:\temp\fileOut" responseTimeout="10000" doc:name="File" outputPattern="inkop2ZZ-#[function:dateStamp].json" mimeType="text/json" encoding="UTF-8"/> -->
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="Oh no!!" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="C:\temp\fileError" responseTimeout="10000" doc:name="File" outputPattern="error-inkop2ZZ-#[function:dateStamp].xml" mimeType="text/xml" encoding="UTF-8"/>
</catch-exception-strategy>
</flow>
The error I get is this one:
Root Exception stack trace:
org.mule.api.registry.RegistrationException: More than one object of type class javax.xml.bind.JAXBContext registered but only one expected.
Regards
I have seen a similar scenario's, this might be because of Multiple jaxb-context. Resolved by placing all the packages in one Context
<mulexml:jaxb-context name="JaxbContext" packageNames="se.razorlib.SystemAProduct:se.razorlib.SystemAPurchase:se.razorlib.SystemAOrder"/>
In flow
<mulexml:jaxb-xml-to-object-transformer returnClass="se.razorlib.SystemAPurchase.Header" encoding="UTF-16" jaxbContext-ref="JaxbContext" doc:name="XML to JAXB Object"/>
Hope this helps.
First I would not be surprised that the file endpoint gave no error. The file doesn't care what it gets. It just wants ones and zeros. I somewhat agree with the answer above but I think you only need to reference the package for the three Java bindings.
<mulexml:jaxb-context name="myJaxb" packageNames="se.razorlib"/>
You are defining the context for JAXB transformations. The package says it all.

Spring Integration - Difference from channel and int:channel

I'm studing by few days Spring Integration and in some example i've noticed the use of channel and int:channel.
What is the difference ?
In the same way, there are other keywords: someone start with int: and other (with the same name) are not.
It just depends on how you configure the namespaces at the top of the XML file, and specifically the default xmlns. In the first case, the integration schema is the default, in the second, something else is, usually beans...
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
...
In this case, integration is the default xmlns and you would use
<channel ...
and
<beans:bean ...
here...
<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"
...
beans is the default xmlns and you would use
<int:channel...
and
<bean ....
So, it's simply a matter of personal choice.

Mule ESB JAXB XML To Object Transformer Better Way?

Mule 3.3 can automatically unmarshall an XML string to an object using JAXB given that:
1. you first register your jaxb annotated classes with spring.
2. there is a component that requires such type as input
So I have managed to do the transformation, but I had to create a "DumbTransformer" that does nothing. It has a method that returns the same object it receives. I need it in order to trigger the XML to Object conversion so that I can further process the message.
Flow Example:
<spring:beans>
<spring:bean id="dumbTransformer" class="foo.bar.DumbTransformer"/>
</spring:beans>
<flow name="main" doc:name="main">
<vm:inbound-endpoint path="in" doc:name="VM" />
<component doc:name="Java">
<spring-object bean="dumbTransformer"/>
</component>
<splitter expression="#[payload.items]" doc:name="Split Items"/>
<logger message="#[payload]" level="INFO" doc:name="Log Item"/>
<vm:outbound-endpoint path="out" doc:name="VM" />
</flow>
DumbTransformer.java
package foo.bar;
#ContainsTransformerMethods
public class InvoiceUnmarshaller extends AbstractTransformer {
#Transformer
public MyJaxbAnnotatedClass foo(#Payload MyJaxbAnnotatedClass i) {
return i;
}
}
Is there a way to acomplish this without having to create such DumbTransformers?
Thanks.
As you guessed it, the JAXB deserialization doesn't occur because there is no component to satisfy:
there is a component that requires such type as input
So what if you had an auto-transformer to do just that:
<auto-transformer returnClass="foo.bar.MyJaxbAnnotatedClass" />
The Mule XML Module provides OOTB a JAXB Transformer. I would rather leverage mule capabilities whenever possible rather than writing custom code

JAXB Marshalling - extending an existing class

I am in need of creating a series of Java objects via XML using JAXB that all extend a common base class that is already created (not using JAXB). For example, let's say I have following JAXB classes that I am trying to generate:
Penguin.xml -> Penguin.java
Robin.xml -> Robin.java
Cardinal.xml -> Cardinal.java
I already have an existing base class called Bird.java that I wish the three classes above to extend.
What is the best way to do this?
Thanks for your help!
That is very simple: you need to to create a JAXB binding file with following contents:
<jaxb:bindings version="1.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>
<jaxb:globalBindings>
<!-- All beans should extend this base class: -->
<xjc:superClass name="org.mycompany.common.Bird" />
</jaxb:globalBindings>
</jaxb:bindings>
More information on this option (and other sweet things) you can find here.

Resources