Skip to content

Commit 6f85509

Browse files
garyrussellartembilan
authored andcommitted
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.
1 parent f6c36d0 commit 6f85509

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ protected void doInit() {
196196
}
197197
}
198198
else {
199-
Assert.state(this.confirmAckChannel == null || this.confirmAckChannel instanceof NullChannel,
199+
NullChannel nullChannel = extractTypeIfPossible(this.confirmAckChannel, NullChannel.class);
200+
Assert.state(this.confirmAckChannel == null || nullChannel != null,
200201
"A 'confirmCorrelationExpression' is required when specifying a 'confirmAckChannel'");
201-
Assert.state(this.confirmNackChannel == null || this.confirmNackChannel instanceof NullChannel,
202+
nullChannel = extractTypeIfPossible(this.confirmNackChannel, NullChannel.class);
203+
Assert.state(this.confirmNackChannel == null || nullChannel != null,
202204
"A 'confirmCorrelationExpression' is required when specifying a 'confirmNackChannel'");
203205
}
204206
if (this.returnChannel != null) {

spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
2323

24+
import org.springframework.aop.TargetSource;
25+
import org.springframework.aop.framework.Advised;
2426
import org.springframework.beans.BeansException;
2527
import org.springframework.beans.factory.BeanFactory;
2628
import org.springframework.beans.factory.BeanFactoryAware;
@@ -229,6 +231,28 @@ protected <T> T getIntegrationProperty(String key, Class<T> tClass) {
229231
return this.defaultConversionService.convert(this.integrationProperties.getProperty(key), tClass);
230232
}
231233

234+
@SuppressWarnings("unchecked")
235+
protected <T> T extractTypeIfPossible(Object targetObject, Class<T> expectedType) {
236+
if (targetObject == null) {
237+
return null;
238+
}
239+
if (expectedType.isAssignableFrom(targetObject.getClass())) {
240+
return (T) targetObject;
241+
}
242+
if (targetObject instanceof Advised) {
243+
TargetSource targetSource = ((Advised) targetObject).getTargetSource();
244+
if (targetSource == null) {
245+
return null;
246+
}
247+
try {
248+
return extractTypeIfPossible(targetSource.getTarget(), expectedType);
249+
} catch (Exception e) {
250+
throw new IllegalStateException(e);
251+
}
252+
}
253+
return null;
254+
}
255+
232256
@Override
233257
public String toString() {
234258
return (this.beanName != null) ? this.beanName : super.toString();

0 commit comments

Comments
 (0)