List of usage examples for org.springframework.aop.support NameMatchMethodPointcutAdvisor NameMatchMethodPointcutAdvisor
public NameMatchMethodPointcutAdvisor(Advice advice)
From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java
/** * Get Advice from .aspect package and create for each Advice class instance an * Advisor with mapped name "*extend"./*from w w w .ja v a 2 s. c om*/ * * @return A List of Advisor. */ private static List getListAdvisorClass() { List advisors = new LinkedList(); try { Class[] listClassAdvice = getClasses("org.mule.providers.soap.axis.wsdl.wsrf.aspect"); Class advice = null; Advisor advisor = null; for (int i = 0; i < listClassAdvice.length; i++) { advice = listClassAdvice[i]; try { advisor = new NameMatchMethodPointcutAdvisor((Advice) advice.newInstance()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } if (advisor != null) { ((NameMatchMethodPointcut) advisor).setMappedName(MAPPED_NAME); advisors.add(advisor); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } return advisors; }
From source file:org.impalaframework.spring.service.proxy.DefaultProxyFactoryCreator.java
protected void addInterceptor(String beanName, ProxyFactory proxyFactory, ServiceEndpointTargetSource targetSource, Map<String, String> options) { ServiceEndpointOptionsHelper optionsHelper = new ServiceEndpointOptionsHelper(options); optionsHelper.setProceedWithNoService(allowNoService); optionsHelper.setSetContextClassLoader(setContextClassLoader); optionsHelper.setLogWarningNoService(logWarningNoService); optionsHelper.setRetryCount(retryCount); optionsHelper.setRetryInterval(retryInterval); ServiceEndpointInterceptor interceptor = new ServiceEndpointInterceptor(targetSource, beanName, optionsHelper);/* w w w .j a v a 2 s . c o m*/ if (logger.isDebugEnabled()) { logger.debug("Creating dynamic proxy for " + beanName + " with allowNoService '" + allowNoService + "' and setContextClassLoader '" + setContextClassLoader + "'"); } final InfrastructureProxyIntroduction infrastructureIntroduction = new InfrastructureProxyIntroduction( targetSource); NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(infrastructureIntroduction); advisor.addMethodName("getWrappedObject"); proxyFactory.addAdvisor(advisor); proxyFactory.addAdvice(interceptor); }
From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java
@Override public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) { if (this.beanAnnotationAware() && AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) { try {//from w w w . j a v a 2 s .co m 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); 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; }
From source file:org.springframework.integration.config.ConsumerEndpointFactoryBean.java
public void afterPropertiesSet() throws Exception { try {//from w ww . j a v a 2 s . co m 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 handleRequesMessage method internally and already have the advice chain injected. * So we only advise handlers that are not reply-producing. If the handler is already advised, * add the configured advices to its chain, otherwise create a proxy. */ if (!(this.handler instanceof AbstractReplyProducingMessageHandler)) { if (AopUtils.isAopProxy(this.handler) && this.handler instanceof Advised) { Class<?> targetClass = AopUtils.getTargetClass(this.handler); for (Advice advice : this.adviceChain) { NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(advice); handlerAdvice.addMethodName("handleMessage"); if (AopUtils.canApply(handlerAdvice.getPointcut(), targetClass)) { ((Advised) this.handler).addAdvice(advice); } } } else { ProxyFactory proxyFactory = new ProxyFactory(this.handler); for (Advice advice : this.adviceChain) { proxyFactory.addAdvice(advice); } this.handler = (MessageHandler) proxyFactory.getProxy(this.beanClassLoader); } } } this.initializeEndpoint(); }
From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java
private Object applyChannelInterceptor(Object bean, DirectChannelMetrics interceptor, ClassLoader beanClassLoader) { NameMatchMethodPointcutAdvisor channelsAdvice = new NameMatchMethodPointcutAdvisor(interceptor); channelsAdvice.addMethodName("send"); channelsAdvice.addMethodName("receive"); return applyAdvice(bean, channelsAdvice, beanClassLoader); }
From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java
private Object applyHandlerInterceptor(Object bean, SimpleMessageHandlerMetrics interceptor, ClassLoader beanClassLoader) { NameMatchMethodPointcutAdvisor handlerAdvice = new NameMatchMethodPointcutAdvisor(interceptor); handlerAdvice.addMethodName("handleMessage"); return applyAdvice(bean, handlerAdvice, beanClassLoader); }
From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java
private Object applySourceInterceptor(Object bean, SimpleMessageSourceMetrics interceptor, ClassLoader beanClassLoader) { NameMatchMethodPointcutAdvisor sourceAdvice = new NameMatchMethodPointcutAdvisor(interceptor); sourceAdvice.addMethodName("receive"); return applyAdvice(bean, sourceAdvice, beanClassLoader); }