Results 1 to 3 of 3

Thread: Missing configuration or possible bug about int:router + List<MessageChannel>

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Exclamation Missing configuration or possible bug about int:router + List<MessageChannel>

    Hello guys

    I am working and testing the section Configuring a Router with Annotations where appear the follow snippet code


    @Router
    public MessageChannel route(Message message) {...}

    @Router
    public List<MessageChannel> route(Message message) {...}


    @Router
    public String route(Foo payload) {...}

    @Router
    public List<String> route(Foo payload) {...}
    I tested each approach about the return type but the second does not work

    For example if I work with List<String>

    Code:
    <int:router id="router" 
    		input-channel="inicio"
      	        apply-sequence="true"
    		method="metodoRouter01"							
    		ref="myRouterSinAnnotationTres"	
    />
    
    private List<String> listChannels;
    	
    public MyRouterConAnnotationTres(){
    	listChannels = new ArrayList<String>();
    	listChannels.add("dvdChannel");
    	listChannels.add("instrumentoMusicalChannel");		
    }
    	
    @Router
    public List<String> metodoRouter01(Message<?> message){
    			
    	logger.info("... message: {}", message);
    		
    	return listChannels;		
    }
    It work fine

    But If I work with List<MessageChannel>

    Code:
    <int:router id="router" 
    		input-channel="inicio"
    		apply-sequence="true"
    		method="metodoRouter01"
    		ref="myRouterSinAnnotationCuatro"	
    				/>
    
    private List<MessageChannel> listChannels;
    	
    private DirectChannel dvdChannel;	
    private DirectChannel instrumentoMusicalChannel;
    	
    @Value("#{dvdChannel}")
    public void setDvdChannel(DirectChannel dvdChannel) {
    	this.dvdChannel = dvdChannel;
    }	
    	
    @Value("#{instrumentoMusicalChannel}")
    public void setInstrumentoMusicalChannel(DirectChannel instrumentoMusicalChannel) {
    	this.instrumentoMusicalChannel = instrumentoMusicalChannel;
    }
    	
    public MyRouterSinAnnotationCuatro(){
    	listChannels = new ArrayList<MessageChannel>();
    	listChannels.add(dvdChannel);
    	listChannels.add(instrumentoMusicalChannel);
    }
    		
    public List<MessageChannel> metodoRouter01(Message<?> message){
    				
    	logger.info("... message: {}", message);
    	return listChannels;		
    }
    does not work I dont receive none exception

    How I know it does not work?, simply I have two flow integration files

    one working with List<String> and the second with List<MessageChannel>, each file has

    Code:
    <int:message-history/>
    
    <int:wire-tap pattern="*" channel="logger" />
    	
    <int:logging-channel-adapter id="logger"								 
    				 level="INFO"								 					 
    				 log-full-message="true"	
    				/>
    For the case with List<String> I can see through the history for each Message sent, the follow history:

    startChannel, router->outputchannel, some ServiceActivator, finalChannel


    But with List<MessageChannel> I can see only the follow history for each Message sent it, everyone has the follow sequence:

    startChannel, router->XXX


    I mean with XXX that each Message<T> never left the router, what is wrong?

    I have the same weird behaviour even If I work with List<DirectChannel>

    Thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Oct 2004
    Location
    Berwyn, PA
    Posts
    57

    Default

    The reason List<MessageChannel> is not working is because you are initializing the channel list in the constructor. This happens before Spring invokes the setters so listChannels = [null,null]. You need to do something like:
    Code:
    @PostConstruct
    	public void init() {
    		listChannels = new ArrayList<MessageChannel>();
    		listChannels.add(dvdChannel);
    		listChannels.add(instrumentoMusicalChannel);
    	}
    List<String> works because you are setting string literals.

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hello dturanski

    Thanks so much for the explanation

    Wooh this kind of error is unforgivable

    The reason List<MessageChannel> is not working is because you are initializing the channel list in the constructor. This happens before Spring invokes the setters so listChannels = [null,null].
    Yes I did realize with

    Code:
    for(MessageChannel messageChannel : listChannels){
    			
    	if(messageChannel==null)
    		logger.error("++++++++++SI SOY NULL++++++++");
    	else
    		logger.info("-----------------NO SOY NULL-------------");
    	}
    and I forgot include resolution-required="true" to see the problem

    List<String> works because you are setting string literals.
    Yes, there is no need to wait some initialization or injection of dependencies by the container

    I forgot by complete the order of work

    1. creation target object (by its constructor)
    2. setter injection and/or constructor injection


    Thanks for your time

    Best Regards
    Last edited by dr_pompeii; Aug 24th, 2011 at 11:03 AM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •