use of org.aopalliance.intercept.MethodInterceptor in project spring-framework by spring-projects.
the class NullPrimitiveTests method testNullPrimitiveWithCglibProxy.
@Test
public void testNullPrimitiveWithCglibProxy() {
Bar target = new Bar();
ProxyFactory factory = new ProxyFactory(target);
factory.addAdvice(new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
return null;
}
});
Bar bar = (Bar) factory.getProxy();
thrown.expect(AopInvocationException.class);
thrown.expectMessage("Bar.getValue()");
assertEquals(0, bar.getValue());
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-framework by spring-projects.
the class DefaultAdvisorChainFactory method getInterceptorsAndDynamicInterceptionAdvice.
@Override
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Advised config, Method method, Class<?> targetClass) {
// This is somewhat tricky... We have to process introductions first,
// but we need to preserve order in the ultimate list.
List<Object> interceptorList = new ArrayList<>(config.getAdvisors().length);
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
boolean hasIntroductions = hasMatchingIntroductions(config, actualClass);
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
for (Advisor advisor : config.getAdvisors()) {
if (advisor instanceof PointcutAdvisor) {
// Add it conditionally.
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
if (mm.isRuntime()) {
// isn't a problem as we normally cache created chains.
for (MethodInterceptor interceptor : interceptors) {
interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
}
} else {
interceptorList.addAll(Arrays.asList(interceptors));
}
}
}
} else if (advisor instanceof IntroductionAdvisor) {
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
if (config.isPreFiltered() || ia.getClassFilter().matches(actualClass)) {
Interceptor[] interceptors = registry.getInterceptors(advisor);
interceptorList.addAll(Arrays.asList(interceptors));
}
} else {
Interceptor[] interceptors = registry.getInterceptors(advisor);
interceptorList.addAll(Arrays.asList(interceptors));
}
}
return interceptorList;
}
use of org.aopalliance.intercept.MethodInterceptor in project perry by ca-cwds.
the class TestModule method configure.
@Override
protected void configure() {
bind(TestService.class).to(TestServiceImpl.class);
install(new SecurityModule(null).addAuthorizer("case:read", CaseAuthorizer.class).addStaticAuthorizer(TestStaticAuthorizer.class));
bindInterceptor(Matchers.any(), Matchers.any(), new MethodInterceptor() {
PermissionAnnotationMethodInterceptor permissionAnnotationMethodInterceptor = new PermissionAnnotationMethodInterceptor();
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
return permissionAnnotationMethodInterceptor.invoke(new org.apache.shiro.aop.MethodInvocation() {
@Override
public Object proceed() throws Throwable {
return invocation.proceed();
}
@Override
public Method getMethod() {
return invocation.getMethod();
}
@Override
public Object[] getArguments() {
return invocation.getArguments();
}
@Override
public Object getThis() {
return invocation.getThis();
}
});
}
});
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method considersPrimitivesAsWrappers.
// DATAREST-221
@Test
public void considersPrimitivesAsWrappers() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
when(invocation.getMethod()).thenReturn(Helper.class.getMethod("getPrimitive"));
when(interceptor.invoke(invocation)).thenReturn(1L);
assertThat(methodInterceptor.invoke(invocation)).isEqualTo(1L);
verify(factory, times(0)).createProjection((Class<?>) any(), any());
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.
the class ProjectingMethodInterceptorUnitTests method appliesProjectionToNonEmptyLists.
// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void appliesProjectionToNonEmptyLists() throws Throwable {
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperList", Collections.singletonList(mock(Helper.class))));
assertThat(result).isInstanceOf(List.class);
List<Object> projections = (List<Object>) result;
assertThat(projections).hasSize(1);
assertThat(projections).hasOnlyElementsOfType(HelperProjection.class);
}
Aggregations