Search in sources :

Example 1 with MethodInvocationProceedingJoinPoint

use of org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint in project cuba by cuba-platform.

the class ServiceInterceptor method getValidateServiceMethodContext.

@Nullable
protected ValidateServiceMethodContext getValidateServiceMethodContext(ProceedingJoinPoint ctx) {
    ValidateServiceMethodContext validatedContext = null;
    if (ctx instanceof MethodInvocationProceedingJoinPoint) {
        MethodInvocationProceedingJoinPoint methodInvocationCtx = (MethodInvocationProceedingJoinPoint) ctx;
        Method method = ((MethodSignature) ctx.getSignature()).getMethod();
        Validated validated = getValidated(method, ctx.getSignature().getDeclaringType());
        if (validated != null) {
            Object[] args = methodInvocationCtx.getArgs();
            ExecutableValidator validator = beanValidation.getValidator().forExecutables();
            validatedContext = new ValidateServiceMethodContext(validator, ctx.getThis(), method, args, validated.value());
        }
    }
    return validatedContext;
}
Also used : Validated(org.springframework.validation.annotation.Validated) ExecutableValidator(javax.validation.executable.ExecutableValidator) MethodSignature(org.aspectj.lang.reflect.MethodSignature) MethodInvocationProceedingJoinPoint(org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable)

Example 2 with MethodInvocationProceedingJoinPoint

use of org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint in project new-cloud by xie-summer.

the class GenericAnnotationAroundAspect method before.

public void before(ProceedingJoinPoint pjp) {
    if (pjp instanceof MethodInvocationProceedingJoinPoint) {
        MethodInvocationProceedingJoinPoint mpjp = (MethodInvocationProceedingJoinPoint) pjp;
        MethodSignature methodSignature = (MethodSignature) mpjp.getSignature();
        // 获取当前的切面方法
        Method method = methodSignature.getMethod();
        DynamicDataSourceHolders.putDataSource(null);
        Class target = mpjp.getTarget().getClass();
        boolean collectResult = collectResult(target, method);
        if (collectResult) {
            log.debug("{}方法{}数据源代理到{}", Thread.currentThread(), method.getName(), DynamicDataSourceHolders.getDataSource());
        } else {
            log.debug("{}方法{}无数据源代理注解", Thread.currentThread(), method.getName());
        }
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) MethodInvocationProceedingJoinPoint(org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)2 MethodSignature (org.aspectj.lang.reflect.MethodSignature)2 MethodInvocationProceedingJoinPoint (org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint)2 Nullable (javax.annotation.Nullable)1 ExecutableValidator (javax.validation.executable.ExecutableValidator)1 Validated (org.springframework.validation.annotation.Validated)1