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.
This commit is contained in:
Gary Russell
2014-11-04 12:30:33 -05:00
committed by Artem Bilan
parent f6c36d049d
commit 6f85509920
2 changed files with 28 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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> T extractTypeIfPossible(Object targetObject, Class<T> 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();