From 6f855099209aff69839222342a529b79fab670a8 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 4 Nov 2014 12:30:33 -0500 Subject: [PATCH] INT-3549 Fix AMQP o-c-a Validation JIRA: https://jira.spring.io/browse/INT-3549 `afterPropertiesSet()` checks for `NullChannel` to determine whether a correlation expression is needed for confirms. This code fails when `nullChannel` is proxied. Extract the type before testing. --- .../amqp/outbound/AmqpOutboundEndpoint.java | 6 +++-- .../context/IntegrationObjectSupport.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java index 4e39855b9c..c2224f5ed7 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java @@ -196,9 +196,11 @@ public class AmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler } } else { - Assert.state(this.confirmAckChannel == null || this.confirmAckChannel instanceof NullChannel, + NullChannel nullChannel = extractTypeIfPossible(this.confirmAckChannel, NullChannel.class); + Assert.state(this.confirmAckChannel == null || nullChannel != null, "A 'confirmCorrelationExpression' is required when specifying a 'confirmAckChannel'"); - Assert.state(this.confirmNackChannel == null || this.confirmNackChannel instanceof NullChannel, + nullChannel = extractTypeIfPossible(this.confirmNackChannel, NullChannel.class); + Assert.state(this.confirmNackChannel == null || nullChannel != null, "A 'confirmCorrelationExpression' is required when specifying a 'confirmNackChannel'"); } if (this.returnChannel != null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index 9bf5f51ee1..f1d0a2d871 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -21,6 +21,8 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.aop.TargetSource; +import org.springframework.aop.framework.Advised; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -229,6 +231,28 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo return this.defaultConversionService.convert(this.integrationProperties.getProperty(key), tClass); } + @SuppressWarnings("unchecked") + protected T extractTypeIfPossible(Object targetObject, Class expectedType) { + if (targetObject == null) { + return null; + } + if (expectedType.isAssignableFrom(targetObject.getClass())) { + return (T) targetObject; + } + if (targetObject instanceof Advised) { + TargetSource targetSource = ((Advised) targetObject).getTargetSource(); + if (targetSource == null) { + return null; + } + try { + return extractTypeIfPossible(targetSource.getTarget(), expectedType); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return null; + } + @Override public String toString() { return (this.beanName != null) ? this.beanName : super.toString();