No-arg gateway method can be a 'send' operation

- no-arg method will now be a send (instead of receive) if @Payload is present

  - added 'method' to the evaluation context variables with the String value of the invoked method's name

  - added test for new gateway no-arg method send option

  - enable 'payload-expression' in XML for no-arg methods

  - use per-method-invocation evaluation context for header expressions (provides 'args' and 'method' as context variables)
This commit is contained in:
Mark Fisher
2011-09-09 16:16:21 +02:00
parent 08e7287338
commit 74628ccc5f
6 changed files with 55 additions and 14 deletions

View File

@@ -213,6 +213,20 @@ public class GatewayProxyFactoryBeanTests {
assertEquals("foobar", result);
}
@Test
public void testNoArgMethodWithPayloadAnnotation() throws Exception {
QueueChannel requestChannel = new QueueChannel();
startResponder(requestChannel);
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
String result = service.requestReplyWithPayloadAnnotation();
assertEquals("requestReplyWithPayloadAnnotation0bar", result);
}
@Test
public void testMessageAsReturnValue() throws Exception {
final QueueChannel requestChannel = new QueueChannel();

View File

@@ -10,6 +10,7 @@
<int:gateway id="gateway" service-interface="org.springframework.integration.gateway.GatewayWithPayloadExpressionTests$SampleGateway">
<int:method name="send1" request-channel="input" payload-expression="#args[0] + 'bar'"/>
<int:method name="send2" request-channel="input" payload-expression="@testBean.sum(#args[0])"/>
<int:method name="send3" request-channel="input" payload-expression="#method"/>
</int:gateway>
<int:gateway id="annotatedGateway"

View File

@@ -67,12 +67,21 @@ public class GatewayWithPayloadExpressionTests {
assertEquals("foobar", result.getPayload());
}
@Test
public void noArgMethodWithPayloadExpression() throws Exception {
gateway.send3();
Message<?> result = input.receive(0);
assertEquals("send3", result.getPayload());
}
public static interface SampleGateway {
void send1(String value);
void send2(String value);
void send3();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.integration.gateway;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.Payload;
/**
* @author Mark Fisher
@@ -38,4 +39,7 @@ public interface TestService {
Message<?> requestReplyWithMessageReturnValue(String input);
@Payload("#method + #args.length")
String requestReplyWithPayloadAnnotation();
}