Search in sources :

Example 51 with Advised

use of org.springframework.aop.framework.Advised in project spring-data-commons by spring-projects.

the class ProxyProjectionFactoryUnitTests method invokesDefaultMethodOnProxy.

// DATACMNS-655
@Test
public void invokesDefaultMethodOnProxy() {
    CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
    Advised advised = (Advised) ReflectionTestUtils.getField(Proxy.getInvocationHandler(excerpt), "advised");
    Advisor[] advisors = advised.getAdvisors();
    assertThat(advisors.length).isGreaterThan(0);
    assertThat(advisors[0].getAdvice()).isInstanceOf(DefaultMethodInvokingMethodInterceptor.class);
}
Also used : Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) Test(org.junit.Test)

Example 52 with Advised

use of org.springframework.aop.framework.Advised in project spring-data-commons by spring-projects.

the class DomainClassConverterUnitTests method convertsStringToUserCorrectly.

@Test
public void convertsStringToUserCorrectly() throws Exception {
    ApplicationContext context = initContextWithRepo();
    converter.setApplicationContext(context);
    doReturn(1L).when(service).convert(any(), eq(Long.class));
    converter.convert("1", STRING_TYPE, USER_TYPE);
    UserRepository bean = context.getBean(UserRepository.class);
    UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget();
    verify(repo, times(1)).findById(1L);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Advised(org.springframework.aop.framework.Advised) Test(org.junit.Test)

Example 53 with Advised

use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.

the class StreamListenerAnnotationBeanPostProcessor method checkProxy.

private Method checkProxy(Method methodArg, Object bean) {
    Method method = methodArg;
    if (AopUtils.isJdkDynamicProxy(bean)) {
        try {
            // Found a @StreamListener method on the target class for this JDK proxy
            // ->
            // is it also present on the proxy itself?
            method = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
            Class<?>[] proxiedInterfaces = ((Advised) bean).getProxiedInterfaces();
            for (Class<?> iface : proxiedInterfaces) {
                try {
                    method = iface.getMethod(method.getName(), method.getParameterTypes());
                    break;
                } catch (NoSuchMethodException noMethod) {
                }
            }
        } catch (SecurityException ex) {
            ReflectionUtils.handleReflectionException(ex);
        } catch (NoSuchMethodException ex) {
            throw new IllegalStateException(String.format("@StreamListener method '%s' found on bean target class '%s', " + "but not found in any interface(s) for bean JDK proxy. Either " + "pull the method up to an interface or switch to subclass (CGLIB) " + "proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'", method.getName(), method.getDeclaringClass().getSimpleName()), ex);
        }
    }
    return method;
}
Also used : Advised(org.springframework.aop.framework.Advised) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) Method(java.lang.reflect.Method)

Example 54 with Advised

use of org.springframework.aop.framework.Advised in project openmrs-core by openmrs.

the class ServiceContext method addAdvisor.

/**
 * @param cls
 * @param advisor
 */
public void addAdvisor(Class cls, Advisor advisor) {
    Advised advisedService = (Advised) services.get(cls);
    if (advisedService.indexOf(advisor) < 0) {
        advisedService.addAdvisor(advisor);
    }
    addedAdvisors.computeIfAbsent(cls, k -> new HashSet<>());
    getAddedAdvisors(cls).add(advisor);
}
Also used : Advised(org.springframework.aop.framework.Advised)

Example 55 with Advised

use of org.springframework.aop.framework.Advised in project openmrs-core by openmrs.

the class ServiceContext method removeAdvice.

/**
 * @param cls
 * @param advice
 */
public void removeAdvice(Class cls, Advice advice) {
    Advised advisedService = (Advised) services.get(cls);
    advisedService.removeAdvice(advice);
    getAddedAdvice(cls).remove(advice);
}
Also used : Advised(org.springframework.aop.framework.Advised)

Aggregations

Advised (org.springframework.aop.framework.Advised)78 Advisor (org.springframework.aop.Advisor)21 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 ProxyFactory (org.springframework.aop.framework.ProxyFactory)10 Advice (org.aopalliance.aop.Advice)8 JoinPoint (org.aspectj.lang.JoinPoint)6 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)6 TargetSource (org.springframework.aop.TargetSource)6 BeanCreationException (org.springframework.beans.factory.BeanCreationException)6 MessageChannel (org.springframework.messaging.MessageChannel)6 TestBean (org.springframework.beans.testfixture.beans.TestBean)4 ChannelAccessPolicy (org.springframework.integration.security.channel.ChannelAccessPolicy)4 ChannelSecurityInterceptor (org.springframework.integration.security.channel.ChannelSecurityInterceptor)4 ConfigAttribute (org.springframework.security.access.ConfigAttribute)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3