Announcement Announcement Module
Collapse
No announcement yet.
Accepting only messages with payload of a certain type, rejecting Collection of type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accepting only messages with payload of a certain type, rejecting Collection of type

    I'm using <service-activator> with a method that uses a domain object.
    I've noticed that when a message with a collection of that object is received the method is invoked with one element and the rest are discarded.

    Is this intentional? Is there a way to avoid this behavior without doing the checks in the code or using a splitter/filter?

  • #2
    Hi,

    Thanks for your question. What you are running into is actually not a Spring Integration issue per se, but your issue stems from Spring's Default Conversion Service, which gets initialized if not providing your own. The default conversion service actually tries to be as lenient as possible - Please see for details:

    https://github.com/SpringSource/spri...onService.java

    The problem specifically is the CollectionToObjectConverter (https://github.com/SpringSource/spri...Converter.java).

    It uses the first item from the collection. There are a few solutions possible for your issue. In that regard, please also review the (short) chapter on 'Payload Type Conversion':

    http://static.springsource.org/sprin...ype-conversion

    In order to "fix" your issue, I see 3 options:

    1) Setup your own Conversion Service (Use bean name: "integrationConversionService"). For example you may extend org.springframework.context.support.ConversionServ iceFactoryBean to achieve that and only add the converter that are relevant for your application.

    If you are using Spring 3.0.x, please also see http://org.springframework.integrati...ServiceCreator as it contains a work-around for an issue.

    2) You can provide your own converters, that are more restrictive e.g.:

    Code:
    <int:converter>
        <bean class="org.springframework.integration.mycode.CollectionConverter"/>
    </int:converter>
    3) Or from a different angle, create a typed Channel e.g.:

    Code:
    <int:channel id="inputChannel" datatype="org.springframework.integration.mycode.User"/>
    I hope this give you some options. Please let me know if you run into further issues or need more explanations.

    Thanks!

    Cheers,

    Gunnar

    Comment


    • #3
      Just for reference, I added a documentation Jira in order to clarify and improve the documentation for Spring Integration 3.0:

      https://jira.springsource.org/browse/INT-2819

      Comment


      • #4
        Thank you for the quick answer.

        Comment

        Working...
        X