diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java index 9d49bc0d63..229a156952 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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. @@ -30,6 +30,7 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.BeanResolver; +import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; @@ -82,7 +83,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper parameterPayloadExpressions = new HashMap(); - private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); + private final StandardEvaluationContext staticEvaluationContext = new StandardEvaluationContext(); private volatile BeanResolver beanResolver; @@ -107,7 +108,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper headers = new HashMap(); + EvaluationContext methodInvocationEvaluationContext = createMethodInvocationEvaluationContext(arguments); if (this.payloadExpression != null) { - StandardEvaluationContext context = new StandardEvaluationContext(); - context.setVariable("args", arguments); - if (this.beanResolver != null) { - context.setBeanResolver(this.beanResolver); - } - messageOrPayload = this.payloadExpression.getValue(context); + messageOrPayload = this.payloadExpression.getValue(methodInvocationEvaluationContext); } for (int i = 0; i < this.parameterList.size(); i++) { Object argumentValue = arguments[i]; @@ -195,7 +192,7 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper evaluatedHeaders = new HashMap(); for (Map.Entry entry : this.headerExpressions.entrySet()) { - Object value = entry.getValue().getValue(this.evaluationContext); + Object value = entry.getValue().getValue(methodInvocationEvaluationContext); if (value != null) { evaluatedHeaders.put(entry.getKey(), value); } @@ -205,13 +202,23 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper + result = input.receive(0); + assertEquals("send3", result.getPayload()); + } + public static interface SampleGateway { void send1(String value); void send2(String value); + + void send3(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/TestService.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/TestService.java index a8ee2844cf..8ab2ac0acc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/TestService.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/TestService.java @@ -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(); + }