Announcement Announcement Module
Collapse
No announcement yet.
file:outbound-channel-adapter help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • file:outbound-channel-adapter help

    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
    Code:
    <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
    Code:
    ARN - Execution of JMS message listener failed [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1]
    org.springframework.integration.message.MessageHandlingException: failed to write Message payload to file
    	at org.springframework.integration.file.FileWritingMessageHandler.handleMessage(FileWritingMessageHandler.java:109)
    	at org.springframework.integration.dispatcher.AbstractDispatcher.sendMessageToHandler(AbstractDispatcher.java:85)
    	at org.springframework.integration.dispatcher.AbstractUnicastDispatcher.dispatch(AbstractUnicastDispatcher.java:54)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:56)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:116)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:94)
    	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:223)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:180)
    	at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:76)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:48)
    	at org.springframework.integration.dispatcher.AbstractDispatcher.sendMessageToHandler(AbstractDispatcher.java:85)
    	at org.springframework.integration.dispatcher.AbstractUnicastDispatcher.dispatch(AbstractUnicastDispatcher.java:54)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:56)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:116)
    	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:222)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:180)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendReplyMessage(AbstractReplyProducingMessageHandler.java:119)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:107)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:48)
    	at org.springframework.integration.dispatcher.AbstractDispatcher.sendMessageToHandler(AbstractDispatcher.java:85)
    	at org.springframework.integration.dispatcher.AbstractUnicastDispatcher.dispatch(AbstractUnicastDispatcher.java:54)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:56)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:116)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:94)
    	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:223)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:180)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:168)
    	at org.springframework.integration.jms.ChannelPublishingJmsMessageListener.onMessage(ChannelPublishingJmsMessageListener.java:203)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:506)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:463)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:322)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:260)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:944)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.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.FileWritingMessageHandler.handleMessage(FileWritingMessageHandler.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

  • #2
    One option would be a chain:
    Code:
    <chain input-channel="fileChannel">
       <object-to-string-transformer/>
       <file:outbound-channel-adapter ... />
    </chain>

    Comment


    • #3
      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

      Code:
      xception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#5': Cannot resolve reference to bean 'org.springframework.integration.handler.MessageHandlerChain#0' while setting bean property 'handler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#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.EventDrivenConsumer] to required type [org.springframework.integration.message.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
      	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:948)
      	at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:702)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:378)
      	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
      	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
      	at com.sample.bootstrap.Bootstrap.main(Bootstrap.java:21)
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#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.EventDrivenConsumer] to required type [org.springframework.integration.message.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.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.EventDrivenConsumer] to required type [org.springframework.integration.message.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
      	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1288)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1249)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
      	... 28 more
      Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.integration.endpoint.EventDrivenConsumer] to required type [org.springframework.integration.message.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
      	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)
      	at org.springframework.beans.TypeConverterDelegate.convertToTypedCollection(TypeConverterDelegate.java:456)
      	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:190)
      	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
      	at org.springframework.beans.BeanWrapperImpl.convertForProperty(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

      Comment


      • #4
        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

        Comment


        • #5
          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).

          Comment


          • #6
            Using of @Async annotation in spring

            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}">
            <integrationoller>
            <integration:interval-trigger interval="1000"/>
            </integrationoller>
            </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

            Comment


            • #7
              Originally posted by Mark Fisher View Post
              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:
              Code:
                <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:
              Code:
                <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.FileWritingMessageHandler">
                  <beans:constructor-arg value="${conf.directory}" />
              
                  <beans:property name="fileNameGenerator">
                    <beans:bean
                      class="org.springframework.integration.file.DefaultFileNameGenerator">
                      <beans:property name="headerName" value="file_name" />
                    </beans:bean>
                  </beans:property>
              
                  <beans:property name="outputChannel" ref="nullChannel"/>    
                </beans:bean>
              The exception:
              Code:
              (...)
              Caused by: org.springframework.beans.ConversionNotSupportedException: 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.EventDrivenConsumer] to required type [org.springframework.integration.core.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
              	at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
              	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
              	at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
              	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)
              	... 26 more
              Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDrivenConsumer] to required type [org.springframework.integration.core.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
              	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
              	at org.springframework.beans.TypeConverterDelegate.convertToTypedCollection(TypeConverterDelegate.java:520)
              	at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173)
              	at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(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).
              Last edited by PiotrD; Nov 16th, 2011, 10:28 AM.

              Comment


              • #8
                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.

                Comment

                Working...
                X