I have this method:
@Override
public ClientDomain addClient(@Valid ClientDomain client) throws ValidationException {
Client clientEntity = this.transformer.transform(client);
Client clientEntityResponse = this.dao.save(clientEntity);
return this.transformer.revert(clientEntityResponse);
}
To intercept it, i am using Spring 4 AOP. This is what i have:
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class ValidationInterceptor
implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
System.out.println("Validating " + invocation.getMethod().getName() + " method");
Object[] asd = invocation.getArguments(); // Get object arguments
invocation.proceed();
return null;
}
}
So, i want to get the arguments annotations, in this case, i would expect to recieve the @Valid annotation, and i couldn't find the way to do it. I've already tried this
for (int i = 0; i < asd.length; i++) {
System.out.println("Param: " + asd[i].toString());
Annotation[][] annotations = invocation.getMethod().getParameterAnnotations();
for (Annotation annotation : annotations[i]) {
System.out.println("---" + annotation.getClass().getSimpleName());
}
}
But i am recieving an empty annotation object on getParametersAnnotations()
Do you know how i can do it ?
Aucun commentaire:
Enregistrer un commentaire