Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Payload Enricher doesnot work when palyload is empty.

  1. #11
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Also, in the code that I posted I am modifying the actual Map to sort of fit what you were trying to do initially. However you can produce a whole different payload type. Basically whatever you return from that method is going to be a new Message payload and in your case I would recommend that since you really don't want to depend on some Spring specific class (e.g., LinkedMultiValueMap). So you can create a new HashMap (if you stil need a Map) or something completely different. . .

  2. #12
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    646

    Default

    Hello, folks!
    I've just reproduced it:
    Code:
    @Test
    	public void testMultiValueMap() {
    		QueueChannel replyChannel = new QueueChannel();
    		DirectChannel requestChannel = new DirectChannel();
    		requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {
    			@Override
    			protected Object handleRequestMessage(Message<?> requestMessage) {
    				return new Source("John", "Doe");
    			}
    		});
    		ContentEnricher enricher = new ContentEnricher();
    		enricher.setRequestChannel(requestChannel);
    
    		SpelExpressionParser parser = new SpelExpressionParser();
    		Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
    		propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
    		enricher.setPropertyExpressions(propertyExpressions);
    		enricher.afterPropertiesSet();
    
    		Message<?> requestMessage = MessageBuilder.withPayload(new LinkedMultiValueMap()).setReplyChannel(replyChannel).build();
    		enricher.handleMessage(requestMessage);
    		Message<?> reply = replyChannel.receive(0);
    		MultiValueMap result = (MultiValueMap) reply.getPayload();
    		assertEquals("test", result.get("name"));
    	}
    The problem is really laying on MultiValueMap. It requeries that the value should be java.util.List.
    The simple fix of it - just wrap the expression with {}:
    HTML Code:
    <int:enricher id="deletePaymentInstrumentEnricher" input-channel="deletePayloadEnricher" >
    <introperty name="paymentInstrumentToken" value="{onewerewrwerwe}" />
    </int:enricher> 
    So, there is no any reason to open new JIRA.

    Best regards,
    Artem Bilan
    Last edited by Cleric; Jun 11th, 2012 at 09:27 AM.

  3. #13
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Right! I totally forgot abou that as well as us using MapAccessor which allows treating key/value as properties on both read and write.
    So thanks Artem!

  4. #14
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    646

    Default

    Sorry, I explain a bit my post:
    1. {} is an inline List: http://static.springsource.org/sprin....html#d0e12704
    2. You also can use on your <http:inbound-gateway> this one:
    HTML Code:
    <http:inbound-gateway
    	payload-expression="requestParams.toSingleValueMap()"/>
    3. Or use the same method in the 'expression' of simple <transformer> before <enricher>

    Hope I'm clear

Tags for this Thread

Posting Permissions

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