Search in sources :

Example 56 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project Hystrix by Netflix.

the class AopUtils method getParameterTypes.

/**
 * Gets parameter types of the join point.
 *
 * @param joinPoint the join point
 * @return the parameter types for the method this object
 *         represents
 */
public static Class[] getParameterTypes(JoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    return method.getParameterTypes();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 57 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature 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 58 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project cuba by cuba-platform.

the class TransactionalInterceptor method aroundInvoke.

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    Method method = ((MethodSignature) ctx.getSignature()).getMethod();
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, ctx.getTarget().getClass());
    Transactional transactional = specificMethod.getAnnotation(Transactional.class);
    if (transactional == null)
        throw new IllegalStateException("Cannot determine data store of the current transaction");
    String storeName = Strings.isNullOrEmpty(transactional.value()) ? Stores.MAIN : transactional.value();
    log.trace("Entering transactional method, store='{}'", storeName);
    ((PersistenceImpl) persistence).registerSynchronizations(storeName);
    return ctx.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project Saturn by vipshop.

the class AuditLogAspect method addAuditParamsIfPossible.

private void addAuditParamsIfPossible(ProceedingJoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Annotation[][] annotations = signature.getMethod().getParameterAnnotations();
    int i = 0;
    for (Object arg : joinPoint.getArgs()) {
        for (Annotation annotation : annotations[i]) {
            if (annotation.annotationType() == AuditParam.class) {
                AuditParam auditParamAnno = (AuditParam) annotation;
                String value = auditParamAnno.value();
                if (value != null) {
                    AuditInfoContext.put(value, arg == null ? null : arg.toString());
                }
            }
        }
        i++;
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) AuditParam(com.vip.saturn.job.console.aop.annotation.AuditParam) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 60 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project tesla by linking12.

the class LogAspect method saveLog.

private void saveLog(ProceedingJoinPoint joinPoint, long time) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    LogDO sysLog = new LogDO();
    Log syslog = method.getAnnotation(Log.class);
    if (syslog != null) {
        // 注解上的描述
        sysLog.setOperation(syslog.value());
    }
    // 请求的方法名
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    sysLog.setMethod(className + "." + methodName + "()");
    // 请求的参数
    Object[] args = joinPoint.getArgs();
    try {
        String params = JSONUtils.beanToJson(args[0]).substring(0, 4999);
        sysLog.setParams(params);
    } catch (Exception e) {
    }
    // 获取request
    HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
    // 设置IP地址
    sysLog.setIp(IPUtils.getIpAddr(request));
    // 用户名
    Long currentUserId = BaseController.getUserId();
    String currentUserName = BaseController.getUsername();
    if (null == currentUserId) {
        if (null != sysLog.getParams()) {
            sysLog.setUserId(-1L);
            sysLog.setUsername(sysLog.getParams());
        } else {
            sysLog.setUserId(-1L);
            sysLog.setUsername("获取用户信息为空");
        }
    } else {
        sysLog.setUserId(currentUserId);
        sysLog.setUsername(currentUserName);
    }
    sysLog.setTime((int) time);
    // 系统当前时间
    Date date = new Date();
    sysLog.setGmtCreate(date);
    // 保存系统日志
    logMapper.save(sysLog);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) LogDO(io.github.tesla.ops.system.domain.LogDO) Date(java.util.Date)

Aggregations

MethodSignature (org.aspectj.lang.reflect.MethodSignature)116 Method (java.lang.reflect.Method)95 Around (org.aspectj.lang.annotation.Around)43 JoinPoint (org.aspectj.lang.JoinPoint)30 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 Test (org.junit.Test)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)24 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)13 Signature (org.aspectj.lang.Signature)13 Annotation (java.lang.annotation.Annotation)10 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 List (java.util.List)2 Tick (mysh.util.Tick)2 Ignite (org.apache.ignite.Ignite)2