use of org.springframework.integration.context.Orderable in project spring-integration by spring-projects.
the class AbstractMethodAnnotationPostProcessor method postProcess.
@Override
public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) {
if (this.beanAnnotationAware() && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
try {
resolveTargetBeanFromMethodWithBeanAnnotation(method);
} catch (NoSuchBeanDefinitionException e) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation.");
}
return null;
}
}
List<Advice> adviceChain = extractAdviceChain(beanName, annotations);
MessageHandler handler = createHandler(bean, method, annotations);
if (!CollectionUtils.isEmpty(adviceChain) && handler instanceof AbstractReplyProducingMessageHandler) {
((AbstractReplyProducingMessageHandler) handler).setAdviceChain(adviceChain);
}
if (handler instanceof Orderable) {
Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class);
if (orderAnnotation != null) {
((Orderable) handler).setOrder(orderAnnotation.value());
}
}
if (handler instanceof AbstractMessageProducingHandler || handler instanceof AbstractMessageRouter) {
String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class);
if (sendTimeout != null) {
Long value = Long.valueOf(this.beanFactory.resolveEmbeddedValue(sendTimeout));
if (handler instanceof AbstractMessageProducingHandler) {
((AbstractMessageProducingHandler) handler).setSendTimeout(value);
} else {
((AbstractMessageRouter) handler).setSendTimeout(value);
}
}
}
boolean handlerExists = false;
if (this.beanAnnotationAware() && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object handlerBean = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
handlerExists = handlerBean != null && handler == handlerBean;
}
if (!handlerExists) {
String handlerBeanName = generateHandlerBeanName(beanName, method);
if (handler instanceof ReplyProducingMessageHandlerWrapper && StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) {
handlerBeanName = handlerBeanName + ".wrapper";
}
this.beanFactory.registerSingleton(handlerBeanName, handler);
handler = (MessageHandler) this.beanFactory.initializeBean(handler, handlerBeanName);
}
if (AnnotatedElementUtils.isAnnotated(method, IdempotentReceiver.class.getName()) && !AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
String[] interceptors = AnnotationUtils.getAnnotation(method, IdempotentReceiver.class).value();
for (String interceptor : interceptors) {
DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor();
advisor.setAdviceBeanName(interceptor);
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.setMappedName("handleMessage");
advisor.setPointcut(pointcut);
advisor.setBeanFactory(this.beanFactory);
if (handler instanceof Advised) {
((Advised) handler).addAdvisor(advisor);
} else {
ProxyFactory proxyFactory = new ProxyFactory(handler);
proxyFactory.addAdvisor(advisor);
handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader());
}
}
}
if (!CollectionUtils.isEmpty(adviceChain)) {
for (Advice advice : adviceChain) {
if (advice instanceof HandleMessageAdvice) {
NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(advice);
handlerAdvice.addMethodName("handleMessage");
if (handler instanceof Advised) {
((Advised) handler).addAdvisor(handlerAdvice);
} else {
ProxyFactory proxyFactory = new ProxyFactory(handler);
proxyFactory.addAdvisor(handlerAdvice);
handler = (MessageHandler) proxyFactory.getProxy(this.beanFactory.getBeanClassLoader());
}
}
}
}
AbstractEndpoint endpoint = createEndpoint(handler, method, annotations);
if (endpoint != null) {
return endpoint;
}
return handler;
}
use of org.springframework.integration.context.Orderable in project spring-integration by spring-projects.
the class AbstractSimpleMessageHandlerFactoryBean method createHandlerInternal.
protected final H createHandlerInternal() {
synchronized (this.initializationMonitor) {
if (this.initialized) {
// There was a problem when this method was called already
return null;
}
this.handler = createHandler();
if (this.handler instanceof ApplicationContextAware && this.applicationContext != null) {
((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext);
}
if (this.handler instanceof BeanFactoryAware && getBeanFactory() != null) {
((BeanFactoryAware) this.handler).setBeanFactory(getBeanFactory());
}
if (this.handler instanceof BeanNameAware && this.beanName != null) {
((BeanNameAware) this.handler).setBeanName(this.beanName);
}
if (this.handler instanceof ApplicationEventPublisherAware && this.applicationEventPublisher != null) {
((ApplicationEventPublisherAware) this.handler).setApplicationEventPublisher(this.applicationEventPublisher);
}
if (this.handler instanceof MessageProducer && this.outputChannel != null) {
((MessageProducer) this.handler).setOutputChannel(this.outputChannel);
}
Object actualHandler = extractTarget(this.handler);
if (actualHandler == null) {
actualHandler = this.handler;
}
if (actualHandler instanceof IntegrationObjectSupport) {
if (this.componentName != null) {
((IntegrationObjectSupport) actualHandler).setComponentName(this.componentName);
}
if (this.channelResolver != null) {
((IntegrationObjectSupport) actualHandler).setChannelResolver(this.channelResolver);
}
}
if (!CollectionUtils.isEmpty(this.adviceChain)) {
if (actualHandler instanceof AbstractReplyProducingMessageHandler) {
((AbstractReplyProducingMessageHandler) actualHandler).setAdviceChain(this.adviceChain);
} else if (this.logger.isDebugEnabled()) {
String name = this.componentName;
if (name == null && actualHandler instanceof NamedComponent) {
name = ((NamedComponent) actualHandler).getComponentName();
}
this.logger.debug("adviceChain can only be set on an AbstractReplyProducingMessageHandler" + (name == null ? "" : (", " + name)) + ".");
}
}
if (this.async != null) {
if (actualHandler instanceof AbstractMessageProducingHandler) {
((AbstractMessageProducingHandler) actualHandler).setAsync(this.async);
}
}
if (this.handler instanceof Orderable && this.order != null) {
((Orderable) this.handler).setOrder(this.order);
}
this.initialized = true;
}
if (this.handler instanceof InitializingBean) {
try {
((InitializingBean) this.handler).afterPropertiesSet();
} catch (Exception e) {
throw new BeanInitializationException("failed to initialize MessageHandler", e);
}
}
return this.handler;
}
Aggregations