Announcement Announcement Module
Collapse
No announcement yet.
Nullpointer in AggregatingMessageHandler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nullpointer in AggregatingMessageHandler

    I have the following use case:

    1. Splitter bean: incoming String is splitted and returned
    2. Pass bean: that just returns the incoming payload
    3. Aggregator bean: a logger that expects to get ALL strings to log them

    The SplitAggregate.xml looks like this:
    Code:
    	<message-bus />
    
    	<channel id="inputChannel"/>
    	<channel id="passChannel"/>
    	<channel id="logChannel"/>
    
    	<splitter id="splitterEndpoint" input-channel="inputChannel" output-channel="passChannel"
    		ref="splitter" method="split" />
    	<beans:bean id="splitter"
    		class="test.Split">
    	</beans:bean>
    	
    	<service-activator id="passEndpoint" input-channel="passChannel" output-channel="logChannel"
    		ref="pass" method="pass"/>
    	<beans:bean id="pass"
    		class="test.Pass">
    	</beans:bean>
    
    	<aggregator id="aggregator" input-channel="logChannel"
    		ref="logAll" method="log" />
    	<beans:bean id="logAll"
    		class="test.LogAll">
    	</beans:bean>
    The Split class:
    Code:
    package test;
    
    public class Split {
    
        public String[] split(String payload) {
            return payload.split(",");
        }
    }
    The Pass class:
    Code:
    package test;
    
    public class Pass {
    
        public String pass(String payload) {
            return payload;
        }
    }
    The LogAll class:
    Code:
    package test;
    
    import java.util.List;
    
    public class LogAll {
    
        public void log(List<String> payloads) {
            System.out.println(">>>" + payloads);
        }
    }
    To start the Demo:
    Code:
    package test;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.integration.channel.ChannelRegistry;
    import org.springframework.integration.channel.MessageChannel;
    import org.springframework.integration.config.MessageBusParser;
    import org.springframework.integration.message.GenericMessage;
    
    public class Demo {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("SplitAggregate.xml", Pass.class);
            context.start();
            ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
            MessageChannel channel = channelRegistry.lookupChannel("inputChannel");
            channel.send(new GenericMessage<String>("1,2,3,4"));
        }
    
    }
    The error message I get is:
    Caused by: java.lang.NullPointerException
    at org.springframework.integration.aggregator.Aggrega tingMessageHandler.processReleasedMessages(Aggrega tingMessageHandler.java:91)
    Here the return message is null that causes this exception.

    I have attached also the source code in a zip file. Should I create a Jira entry for this?

  • #2
    Please do report a JIRA issue for this.

    Comment


    • #3
      Splitter and Aggregator

      I have created an issue under INT-369. There I have also put a comment about the problem and solution I found.

      There is something confusing when reading the Reference Manual for the Splitter and Aggregator in:
      http://static.springframework.org/sp...onent-splitter

      To be more precise:

      1. Splitter
      A component acting as a Splitter returns a List of output messages (as a return value of the method). In this case each output message is send one by one (instead of the whole list) to the output channel.
      => Ergo: a Splitter requires only an output channel. The component's method can be called directly or by an optional input-channel.

      2. Aggregator
      A component acting as an Aggregator expects a List of input messages (as an input argument of the method). The messages send to the input channel one-by-one are totally collected in a List before passing it to the Aggregator.
      =>Ergo: an Aggregator requires only an input channel.
      Last edited by ttruong; Sep 12th, 2008, 04:49 PM.

      Comment


      • #4
        Patch

        In case somebody can't wait. Attached you'll find a patch for workaround

        Comment

        Working...
        X