From 02dbe3c1a392ed20fc7cf42ed1ee616b4c05ff3a Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 1 Apr 2015 21:38:47 +0300 Subject: [PATCH] INT-3668: Add `late-binding` for GatewayProxyFB JIRA: https://jira.spring.io/browse/INT-3668 Note: the `defaultRequestChannel`, `defaultReplyChannel` and `errorChannel` remain as `MessageChannel` references, since they are really some global shared and it looks logical to require those channels be populated by end-user directly Reinstated start() during backport. --- .../gateway/GatewayProxyFactoryBean.java | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 925d70e832..a9d7cb018f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -444,21 +444,17 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint private MethodInvocationGateway createGatewayForMethod(Method method) { Gateway gatewayAnnotation = method.getAnnotation(Gateway.class); MessageChannel requestChannel = this.defaultRequestChannel; + String requestChannelName = null; MessageChannel replyChannel = this.defaultReplyChannel; + String replyChannelName = null; Long requestTimeout = this.defaultRequestTimeout; Long replyTimeout = this.defaultReplyTimeout; String payloadExpression = this.globalMethodMetadata != null ? this.globalMethodMetadata.getPayloadExpression() : null; Map headerExpressions = new HashMap(); if (gatewayAnnotation != null) { - String requestChannelName = gatewayAnnotation.requestChannel(); - if (StringUtils.hasText(requestChannelName)) { - requestChannel = this.resolveChannelName(requestChannelName); - } - String replyChannelName = gatewayAnnotation.replyChannel(); - if (StringUtils.hasText(replyChannelName)) { - replyChannel = this.resolveChannelName(replyChannelName); - } + requestChannelName = gatewayAnnotation.requestChannel(); + replyChannelName = gatewayAnnotation.replyChannel(); /* * INT-2636 Unspecified annotation attributes should not * override the default values supplied by explicit configuration. @@ -503,14 +499,8 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint if (!CollectionUtils.isEmpty(methodMetadata.getHeaderExpressions())) { headerExpressions.putAll(methodMetadata.getHeaderExpressions()); } - String requestChannelName = methodMetadata.getRequestChannelName(); - if (StringUtils.hasText(requestChannelName)) { - requestChannel = this.resolveChannelName(requestChannelName); - } - String replyChannelName = methodMetadata.getReplyChannelName(); - if (StringUtils.hasText(replyChannelName)) { - replyChannel = this.resolveChannelName(replyChannelName); - } + requestChannelName = methodMetadata.getRequestChannelName(); + replyChannelName = methodMetadata.getReplyChannelName(); String reqTimeout = methodMetadata.getRequestTimeout(); if (StringUtils.hasText(reqTimeout)){ requestTimeout = this.convert(reqTimeout, Long.class); @@ -535,8 +525,18 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint gateway.setTaskScheduler(this.getTaskScheduler()); } gateway.setBeanName(this.getComponentName()); - gateway.setRequestChannel(requestChannel); - gateway.setReplyChannel(replyChannel); + if (StringUtils.hasText(requestChannelName)) { + gateway.setRequestChannelName(requestChannelName); + } + else { + gateway.setRequestChannel(requestChannel); + } + if (StringUtils.hasText(replyChannelName)) { + gateway.setReplyChannelName(replyChannelName); + } + else { + gateway.setReplyChannel(replyChannel); + } if (requestTimeout == null) { gateway.setRequestTimeout(-1); } @@ -557,13 +557,6 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint return gateway; } - private MessageChannel resolveChannelName(String channelName) { - Assert.state(this.channelResolver != null, "ChannelResolver is required"); - MessageChannel channel = this.channelResolver.resolveDestination(channelName); - Assert.notNull(channel, "failed to resolve channel '" + channelName + "'"); - return channel; - } - // Lifecycle implementation @Override // guarded by super#lifecycleLock