Announcement Announcement Module
Collapse
No announcement yet.
Cant have a Map payload via payload-expression on a Gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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!

      Comment


      • #4
        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!

        Comment


        • #5
          Thanks Artem,

          issue: https://jira.springsource.org/browse/INT-2613

          Comment

          Working...
          X