PDA

View Full Version : file:outbound-channel-adapter help



MmarcoM
Dec 29th, 2009, 09:23 AM
Hello all,
i have a spring app where i post message to a common channel (event channel), where a rounter redirects the message to other channels (according to value of one of message's property).

the message being sent is my custom class, which just contains a String and an extra property.

i have defined this channel along with its adapter for creating a file out of a message



<si:channel id="fileChannel"/>
<file:outbound-channel-adapter id="filesOut"
channel="fileChannel"
directory="file:/c:/SpringInteg/files"/>



the problem is that i am receiving this exception


ARN - Execution of JMS message listener failed [org.springframework.jms.listener.DefaultMessageLis tenerContainer#0-1]
org.springframework.integration.message.MessageHan dlingException: failed to write Message payload to file
at org.springframework.integration.file.FileWritingMe ssageHandler.handleMessage(FileWritingMessageHandl er.java:109)
at org.springframework.integration.dispatcher.Abstrac tDispatcher.sendMessageToHandler(AbstractDispatche r.java:85)
at org.springframework.integration.dispatcher.Abstrac tUnicastDispatcher.dispatch(AbstractUnicastDispatc her.java:54)
at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:56)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:116)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:94)
at org.springframework.integration.channel.MessageCha nnelTemplate.doSend(MessageChannelTemplate.java:22 3)
at org.springframework.integration.channel.MessageCha nnelTemplate.send(MessageChannelTemplate.java:180)
at org.springframework.integration.router.AbstractMes sageRouter.handleMessageInternal(AbstractMessageRo uter.java:76)
at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:48)
at org.springframework.integration.dispatcher.Abstrac tDispatcher.sendMessageToHandler(AbstractDispatche r.java:85)
at org.springframework.integration.dispatcher.Abstrac tUnicastDispatcher.dispatch(AbstractUnicastDispatc her.java:54)
at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:56)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:116)
at org.springframework.integration.channel.MessageCha nnelTemplate.doSend(MessageChannelTemplate.java:22 2)
at org.springframework.integration.channel.MessageCha nnelTemplate.send(MessageChannelTemplate.java:180)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendReplyMessage(Abstra ctReplyProducingMessageHandler.java:119)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:107)
at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:48)
at org.springframework.integration.dispatcher.Abstrac tDispatcher.sendMessageToHandler(AbstractDispatche r.java:85)
at org.springframework.integration.dispatcher.Abstrac tUnicastDispatcher.dispatch(AbstractUnicastDispatc her.java:54)
at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:56)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:116)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:94)
at org.springframework.integration.channel.MessageCha nnelTemplate.doSend(MessageChannelTemplate.java:22 3)
at org.springframework.integration.channel.MessageCha nnelTemplate.send(MessageChannelTemplate.java:180)
at org.springframework.integration.channel.MessageCha nnelTemplate.send(MessageChannelTemplate.java:168)
at org.springframework.integration.jms.ChannelPublish ingJmsMessageListener.onMessage(ChannelPublishingJ msMessageListener.java:203)
at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi stenerContainer.java:506)
at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList enerContainer.java:463)
at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL istenerContainer.java:435)
at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac tPollingMessageListenerContainer.java:322)
at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP ollingMessageListenerContainer.java:260)
at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(DefaultMessageListenerContainer.java:944)
at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.run(Def aultMessageListenerContainer.java:868)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: unsupported Message payload type [com.sample.domain.TestMessage]
at org.springframework.integration.file.FileWritingMe ssageHandler.handleMessage(FileWritingMessageHandl er.java:103)
... 35 more


Which in a way i am expecting because i am using a custom message, and the default adapter cannot convert it to a String.

I guess i should use a transformer, but i am not clear on how........ as transformer normally
does a transformation between 2 channels.

my workflow is as follows

eventChannel ---> fileChannel (where adapter will get the message and hopefully store to a file)

if i use a tranformer, shall i amend the workflow as follows?

eventChannel --->tmpChannel--->fileChannel ?

or can i associate a transformer directly to teh file adapter?

anyone could clarifiy?

regards
marco

Mark Fisher
Dec 29th, 2009, 09:27 AM
One option would be a chain:


<chain input-channel="fileChannel">
<object-to-string-transformer/>
<file:outbound-channel-adapter ... />
</chain>

MmarcoM
Dec 30th, 2009, 06:57 AM
Mark,
somehow the solution suggested does not worjk :(
i have tried to define my own transformer,but when runnng my app i got this exception



xception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.config.ConsumerEn dpointFactoryBean#5': Cannot resolve reference to bean 'org.springframework.integration.handler.MessageHa ndlerChain#0' while setting bean property 'handler'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.handler.MessageHa ndlerChain#0': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [java.util.List] for property 'handlers'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.message.MessageHan dler] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:104)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:308)
at org.springframework.context.support.AbstractApplic ationContext.getBeansOfType(AbstractApplicationCon text.java:948)
at org.springframework.context.support.AbstractApplic ationContext.registerListeners(AbstractApplication Context.java:702)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:378)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.sample.bootstrap.Bootstrap.main(Bootstrap.java :21)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.handler.MessageHa ndlerChain#0': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [java.util.List] for property 'handlers'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.message.MessageHan dler] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:269)
... 19 more
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [java.util.List] for property 'handlers'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.message.MessageHan dler] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.convertForProperty(Abst ractAutowireCapableBeanFactory.java:1288)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1249)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:472)
... 28 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.message.MessageHan dler] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:219)
at org.springframework.beans.TypeConverterDelegate.co nvertToTypedCollection(TypeConverterDelegate.java: 456)
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:190)
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:386)
... 32 more


I managed to make it work by setting as endpoint my own service, with this new config

[code]
<si:chain input-channel="fileChannel">
<si:transformer id="fileTransformer" ref="fileTransformerBean"/>
<si:service-activator ref="sampleHandler" method="handleMessage"/>
</si:chain>


somehow i m failing to hook the outbound file adapter...

any extra little help?

thanks and regars
marco

clandestino_bgd
Mar 1st, 2010, 10:32 AM
I have the same problem and same exception when I try to chain object-to-string transformer and file:outbound-channel-adapter.

Basically, I am trying to write message payload of my type ShortMessage to file system.

I thought if I provide toString method in my ShortMessage class, adapter will figure it out that this should be the content of my file, with name set in message header, but it seems that it is not the case.

Any hint how to do this?

thanks,
Milan

Mark Fisher
Mar 1st, 2010, 12:29 PM
Could you please post this in JIRA? The chain *should* accept the object-to-string-transformer.

We had originally designed the outbound File adapter to accept the result of toString(). However, that led to excessively aggressive conversion to Strings (message payloads that should *not* be converted to Strings).

cthopuri
May 11th, 2010, 01:46 AM
Hi,
written code for file handling.It will just copy from input folder files to output folder files.I had done this with Synchronously.But If i do same thing with @Async notation according to annotation rules if you want to apply @Async notation to a method with Return type You need to cast it to Future.
@Async
Future<String> returnSomething(int i) {
// this will be executed asynchronously
}

But here my return type is file.
public Future<File> handleFile(File input)
{
return new AsyncResult<File>;
}
My spring configuration file is

<task:annotation-driven/>
<context:component-scan base-package="">
<file:inbound-channel-adapter id="filesIn" directory="${filefeed.source}">
<integration:poller>
<integration:interval-trigger interval="1000"/>
</integration:poller>
</file:inbound-channel-adapter>

<integration:service-activator input-channel="filesIn" output-channel="filesOut">
<bean id="id" class="class name" />
</integration:service-activator>
<file:outbound-channel-adapter id="filesOut" directory="${filefeed.dest}" delete-source-files="true"/>

while executing my logic i am getting below exception

Caused by: java.lang.IllegalArgumentException: unsupported Message payload type [java.util.concurrent.FutureTask]
at org.springframework.integration.file.FileWritingMe ssageHandler.handleRequestMessage(FileWritingMessa geHandler.java:174)

Let me know what to do

PiotrD
Nov 16th, 2011, 03:52 AM
Could you please post this in JIRA? The chain *should* accept the object-to-string-transformer.

We had originally designed the outbound File adapter to accept the result of toString(). However, that led to excessively aggressive conversion to Strings (message payloads that should *not* be converted to Strings).

Hi Mark, I have the same issue with Spring Integration 2.0.5.RELEASE but I think that this is problem with outbound channel adapter which is the last element in chain rather than with transformer. Currently, I'm trying to chain header enricher and file outbound channel adapter and I'm getting exactly the same exception as MmarcoM.

This is what I cannot do:


<chain input-channel="fileInChannel">
<header-enricher>
<header name="file_name" value="${conf.filename}" />
</header-enricher>
<file:outbound-channel-adapter id="storeConfigurationFileAdapter"
directory="${conf.directory}" />
</chain>


And here is ugly workaround:


<chain input-channel="fileInChannel">
<header-enricher>
<header name="file_name" value="${conf.filename}" />
</header-enricher>
<service-activator ref="fileWritingMessageHandler"
method="handleMessage" />
</chain>

<beans:bean id="fileWritingMessageHandler"
class="org.springframework.integration.file.FileWritingMe ssageHandler">
<beans:constructor-arg value="${conf.directory}" />

<beans:property name="fileNameGenerator">
<beans:bean
class="org.springframework.integration.file.DefaultFileNa meGenerator">
<beans:property name="headerName" value="file_name" />
</beans:bean>
</beans:property>

<beans:property name="outputChannel" ref="nullChannel"/>
</beans:bean>


The exception:


(...)
Caused by: org.springframework.beans.ConversionNotSupportedEx ception: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.util.List' for property 'handlers'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.core.MessageHandle r] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:462)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:499)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:493)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.convertForProperty(Abst ractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
... 26 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDriv enConsumer] to required type [org.springframework.integration.core.MessageHandle r] for property 'handlers[1]': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.co nvertToTypedCollection(TypeConverterDelegate.java: 520)
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:173)
at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:447)
... 32 more


If you find it as a bug, I'll submit JIRA ticket.

Edit: the same is if I have int-event:outbound-channel-adapter as the last chain element (of course it's another chain and another transformer producing appropriate event).

oleg.zhurakousky
Nov 16th, 2011, 07:55 AM
I say if you can provide a simple piece of code that reproduces the issue raise the JIRA and attach the code to it. This way we can look and decide there.