Spring Integration
  1. Spring Integration
  2. INT-2275

Add support for any 'outbound-channel-adapter' as end-MessageHandler of the <chain>

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.2 M1
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Java 1.6/1.7, Spring Integration 2.0.5, Spring 3.0.5

      Description

      When I try to define service activator as a chain element using namespace support, exception is raised.
      For example, the following definition does not work:

        <int:chain input-channel="input">
          <int:header-enricher>
            <int:header name="file_name" value="myfile.txt" />
          </int:header-enricher>
          <file:outbound-channel-adapter id="fileWriter" directory="/tmp" />
        </int:chain>
      

      When I do the same using plain bean definition (not using namespaces), everything is fine:

      <int:chain input-channel="input">
          <int:header-enricher>
            <int:header name="file_name" value="myfile.txt" />
          </int:header-enricher>
          <int:service-activator ref="fileWritingMessageHandler"
            method="handleMessage" />
        </int:chain>
      
        <bean id="fileWritingMessageHandler"
          class="org.springframework.integration.file.FileWritingMessageHandler">
          <constructor-arg value="/tmp" />
      
          <property name="fileNameGenerator">
            <bean class="org.springframework.integration.file.DefaultFileNameGenerator">
              <property name="headerName" value="file_name" />
            </bean>
          </property>
          <property name="outputChannel" ref="nullChannel" />
        </bean>
      

      Exactly the same situation is for other activators, for example int-event:outbound-channel-adapter.
      I've enclosed sample maven project reproducing this issue: try to run "FailingTest" and "WorkingTest".

      Exception:

      java.lang.IllegalStateException: Failed to load ApplicationContext
      	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
      	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:321)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      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.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.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:291)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
      	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
      	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
      	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
      	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
      	... 24 more
      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)
      	... 36 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)
      	... 42 more
      

        Issue Links

          Activity

          Hide
          Artem Bilan added a comment -

          Mark, I'm working on it. A couple later I am notifying you of the situation.
          Can you show me that sample from Spring Integration in Action? And I try it.
          Believe me: right now it doesn't work :

          <int:chain input-channel="adapterInsideChain">
              <int-mail:outbound-channel-adapter mail-sender="mailSender"/>
          </int:chain>
          

          Exception:

          org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: The channel-adapter's 'id' attribute is required when no 'channel' reference has been provided, because that 'id' would be used for the created channel.
          

          Nevertheless when I provide 'id' for adapter I catch:

          java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDrivenConsumer] to required type [org.springframework.integration.core.MessageHandler] for property 'handlers[0]': no matching editors or conversion strategy found
          

          maybe it worked in 1.x.x?
          However it is initial implementation: https://github.com/artembilan/spring-integration/commit/3a7a1e1e9caa5ac662c6553775cee7aa9f298d0d#diff-6
          There are problems with some outbound-adapters' handlers, which aren't 'outbound' by their architecture: they implements MessageProducer
          You can see some trick in my tests: https://github.com/artembilan/spring-integration/commit/3a7a1e1e9caa5ac662c6553775cee7aa9f298d0d#L14R17

          Show
          Artem Bilan added a comment - Mark, I'm working on it. A couple later I am notifying you of the situation. Can you show me that sample from Spring Integration in Action? And I try it. Believe me: right now it doesn't work : <int:chain input-channel= "adapterInsideChain" > <int-mail:outbound-channel-adapter mail-sender= "mailSender" /> </int:chain> Exception: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: The channel-adapter's 'id' attribute is required when no 'channel' reference has been provided, because that 'id' would be used for the created channel. Nevertheless when I provide 'id' for adapter I catch: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDrivenConsumer] to required type [org.springframework.integration.core.MessageHandler] for property 'handlers[0]': no matching editors or conversion strategy found maybe it worked in 1.x.x? However it is initial implementation: https://github.com/artembilan/spring-integration/commit/3a7a1e1e9caa5ac662c6553775cee7aa9f298d0d#diff-6 There are problems with some outbound-adapters' handlers, which aren't 'outbound' by their architecture: they implements MessageProducer You can see some trick in my tests: https://github.com/artembilan/spring-integration/commit/3a7a1e1e9caa5ac662c6553775cee7aa9f298d0d#L14R17
          Hide
          Mark Fisher added a comment -

          Artem, here is the example from the book:

          <chain input-channel="passengers">
            <transformer ref="frequentFlyerService" method="configureProfile"/>
            <mail:header-enricher>
              <mail:to expression="payload.emailAddress"/>
            </mail:header-enricher>
            <mail:outbound-channel-adapter mail-sender="mailSender"/>
          </chain>
          
          Show
          Mark Fisher added a comment - Artem, here is the example from the book: <chain input-channel= "passengers" > <transformer ref= "frequentFlyerService" method= "configureProfile" /> <mail:header-enricher> <mail:to expression= "payload.emailAddress" /> </mail:header-enricher> <mail:outbound-channel-adapter mail-sender= "mailSender" /> </chain>
          Hide
          Oleg Zhurakousky added a comment -

          Artem

          What are the chances of this being done today?

          Show
          Oleg Zhurakousky added a comment - Artem What are the chances of this being done today?
          Hide
          Artem Bilan added a comment -

          Hello, Oleg
          I'm working under it right now struggles.
          Now I'm just writing tests throughout the project.
          But as I emailed in the integration-dev it is more about ignored tests.
          So, maybe can I make PR and other tests about 'OCA within chain' should be done in the separetes JIRAs for refactoring later?
          However I want to say that there are a lot of changes...

          Show
          Artem Bilan added a comment - Hello, Oleg I'm working under it right now struggles. Now I'm just writing tests throughout the project. But as I emailed in the integration-dev it is more about ignored tests. So, maybe can I make PR and other tests about 'OCA within chain' should be done in the separetes JIRAs for refactoring later? However I want to say that there are a lot of changes...
          Show
          Artem Bilan added a comment - Issued PR: https://github.com/SpringSource/spring-integration/pull/435

            People

            • Assignee:
              Artem Bilan
              Reporter:
              Piotr Dyraga
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: