use of org.springframework.messaging.core.BeanFactoryMessageChannelDestinationResolver in project spring-integration by spring-projects.
the class ConsumerEndpointFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (this.beanName == null) {
logger.error("The MessageHandler [" + this.handler + "] will be created without a 'componentName'. " + "Consider specifying the 'beanName' property on this ConsumerEndpointFactoryBean.");
} else {
try {
if (!this.beanName.startsWith("org.springframework")) {
MessageHandler targetHandler = this.handler;
if (AopUtils.isAopProxy(targetHandler)) {
Object target = ((Advised) targetHandler).getTargetSource().getTarget();
if (target instanceof MessageHandler) {
targetHandler = (MessageHandler) target;
}
}
if (targetHandler instanceof IntegrationObjectSupport) {
((IntegrationObjectSupport) targetHandler).setComponentName(this.beanName);
}
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Could not set component name for handler " + this.handler + " for " + this.beanName + " :" + e.getMessage());
}
}
}
if (!CollectionUtils.isEmpty(this.adviceChain)) {
/*
* ARPMHs advise the handleRequestMessage method internally and already have the advice chain injected.
* So we only advise handlers that are not reply-producing.
* Or if one (or more) of advices is IdempotentReceiverInterceptor.
* If the handler is already advised,
* add the configured advices to its chain, otherwise create a proxy.
*/
Class<?> targetClass = AopUtils.getTargetClass(this.handler);
boolean replyMessageHandler = AbstractReplyProducingMessageHandler.class.isAssignableFrom(targetClass);
for (Advice advice : this.adviceChain) {
if (!replyMessageHandler || advice instanceof HandleMessageAdvice) {
NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(advice);
handlerAdvice.addMethodName("handleMessage");
if (this.handler instanceof Advised) {
((Advised) this.handler).addAdvisor(handlerAdvice);
} else {
ProxyFactory proxyFactory = new ProxyFactory(this.handler);
proxyFactory.addAdvisor(handlerAdvice);
this.handler = (MessageHandler) proxyFactory.getProxy(this.beanClassLoader);
}
}
}
}
if (this.channelResolver == null) {
this.channelResolver = new BeanFactoryMessageChannelDestinationResolver(this.beanFactory);
}
initializeEndpoint();
}
Aggregations