List of usage examples for org.aspectj.lang.reflect MethodSignature getMethod
Method getMethod();
From source file:uk.ltd.woodsideconsultancy.aop.cache.CacheKeyFinderTest.java
License:Open Source License
private JoinPoint initJoinPoint(String methodName, Object[] params, Class<?>... paramTypes) throws NoSuchMethodException, SecurityException { JoinPoint jp = mock(JoinPoint.class); MethodSignature signature = mock(MethodSignature.class); Method method = this.getClass().getMethod(methodName, paramTypes); when(jp.getArgs()).thenReturn(params); when(jp.getSignature()).thenReturn(signature); when(jp.getTarget()).thenReturn(this); when(signature.getMethod()).thenReturn(method); return jp;// w w w . j a va 2 s. c om }
From source file:validation.ValidationInterceptor.java
License:Apache License
@Around("execution(public * *(..)) && @within(validation.AutoValidating)") public Object validateMethodInvocation(ProceedingJoinPoint pjp) throws Throwable { Object result;//from ww w .ja v a2 s. c o m MethodSignature signature = (MethodSignature) pjp.getSignature(); MethodValidator methodValidator = validator.unwrap(MethodValidator.class); Set<MethodConstraintViolation<Object>> parametersViolations = methodValidator .validateAllParameters(pjp.getTarget(), signature.getMethod(), pjp.getArgs()); if (!parametersViolations.isEmpty()) { throw new MethodConstraintViolationException(parametersViolations); } result = pjp.proceed(); //Execute the method Set<MethodConstraintViolation<Object>> returnValueViolations = methodValidator .validateReturnValue(pjp.getTarget(), signature.getMethod(), result); if (!returnValueViolations.isEmpty()) { throw new MethodConstraintViolationException(returnValueViolations); } return result; }