Results 1 to 5 of 5

Thread: Cant have a Map payload via payload-expression on a Gateway

  1. #1
    Join Date
    Jun 2010
    Posts
    7

    Default Cant have a Map payload via payload-expression on a Gateway

    My intention is to have the service interface free from Spring dependencies and have all gateways defined on the context xml. Im getting


    Code:
    Ambiguous method parameters; found more than one Map-typed parameter and neither one contains a @Payload annotation
    Is this intentional and is there any work around?


    Thanks!

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

    Default

    Hello

    Please, read this one: http://static.springsource.org/sprin...r.html#gateway
    And keep in mind: if your gateway's method has more then one parameters you should say to framework which from them to interpret as payload and which as headers

    And as you see the exception asks you to add that one ;-)

    Cheers,
    Artem Bilan

  3. #3
    Join Date
    Jun 2010
    Posts
    7

    Default

    Hi Cleric,

    Thank you for your response.

    What I was actually doing is specify via XML configuration (payload-expression) what the payload should be. Here is a sample:

    Code:
    public interface CampaignGateway {
    
    	public Campaign createCampaign(Map<String, String> map);
    }
    on the gateway definition
    Code:
     <int:gateway service-interface="my.integration.CampaignGateway">
             <int:method name="createCampaign"  request-channel="requestChannel" 
                          payload-expression="#args[0]" reply-channel="responseChannel">
                         <int:header name="Content-type" value="application/x-www-form-urlencoded"/>
             </int:method>
         </int:gateway>
    Please note that I use payload-expression="#args[0]".

    Im getting mbiguous method parameters; found more than one Map-typed parameter and neither one contains a @Payload annotation.

    Checking GatewayMethodInboundMessageMapper, here's the code that throws the exception:
    Code:
          else if (Map.class.isAssignableFrom(methodParameter.getParameterType())) {
    				if (messageOrPayload instanceof Map && !foundPayloadAnnotation) {
    					throw new MessagingException("Ambiguous method parameters; found more than one " +
    							"Map-typed parameter and neither one contains a @Payload annotation");
    				}
    				this.copyHeaders((Map<?, ?>) argumentValue, headers);
    			}
    It seems the code only expects Map type payloads to be defined via @Payload annotation.

    Thanks!

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

    Default

    A-ha!

    Now I understand you!
    Great catch!
    I've just reproduced it:
    Code:
    @Test
    	public void toMessageWithMap() throws Exception {
    		Method method = TestService.class.getMethod("sendMap", Map.class);
    		GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
    		mapper.setPayloadExpression("#args[0]");
    		Message<?> message = mapper.toMessage(new Object[] {new HashMap<String, String>()});
    		assertEquals("test", message.getPayload());
    	}
    It's realy a bug.
    Can you open a JIRA about this and we will think what to do: https://jira.springsource.org/browse/INT ?

    Right now it sounds as "Can't use gateway's method parameter as Map and payload-expression together"

    Thanks!

  5. #5
    Join Date
    Jun 2010
    Posts
    7

Posting Permissions

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