Search in sources :

Example 76 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project data-prep by Talend.

the class AnnotationUtils method getAnnotatedParameterIndexes.

public static List<Integer> getAnnotatedParameterIndexes(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Method m = ms.getMethod();
    Annotation[][] pa = m.getParameterAnnotations();
    List<Integer> idParameterIndexes = new ArrayList<>();
    int i = 0;
    for (Annotation[] annotations : pa) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                idParameterIndexes.add(i);
            }
        }
        i++;
    }
    return idParameterIndexes;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 77 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project Corgi by kevinYin.

the class AdminLoggerAspect method processLog.

/**
 * 执行记录日志的操作
 *
 * @param jp
 * @param adminLog
 * @param result
 * @throws Exception
 */
private void processLog(JoinPoint jp, AdminLog adminLog, Object result) throws Exception {
    MethodSignature ms = (MethodSignature) jp.getSignature();
    Method method = ms.getMethod();
    // 日志类型,为空时取 MenuResource 的值
    String type = adminLog.type();
    if (StringUtils.isEmpty(type) && method.isAnnotationPresent(MenuResource.class)) {
        MenuResource menuResource = method.getAnnotation(MenuResource.class);
        type = menuResource.value();
    }
    if (doLog(adminLog, result)) {
        // 执行结果的信息
        String resultMessage = getResultMessage(adminLog, result);
        // 参数
        String arguments = getArguments(jp, method, adminLog);
        // ip
        // get admin id from AdminContext
        logger.info("参数列表 | admin: {}, type: {}, arguments: {}, result: {}", AdminContext.getAccountId(), type, arguments, resultMessage);
        // save log
        AdminLogger adminLogger = SpringContextUtil.getBean(AdminLogger.class);
        AdminOperationLog log = new AdminOperationLog();
        log.setOperationType(type);
        log.setResult(resultMessage);
        log.setArguments(arguments);
        log.setUid(AdminContext.getAccountId());
        adminLogger.saveAdminLog(log);
    } else {
        logger.info("DONT LOG ...............");
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) Method(java.lang.reflect.Method) AdminOperationLog(com.ibeiliao.deployment.admin.vo.account.AdminOperationLog)

Example 78 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.

the class InvokeStatAspect method recStat.

@Around(value = "@annotation(InvokeStat)", argNames = "pjp, InvokeStat")
public Object recStat(final ProceedingJoinPoint pjp, InvokeStat invokeStat) throws Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    String recKey = StringUtils.isBlank(invokeStat.value()) ? pjp.getTarget().getClass().getSimpleName() + '.' + signature.getName() : invokeStat.value();
    Tick tick = Tick.tick();
    Object result = pjp.proceed();
    long time = tick.nip();
    String params = invokeStat.recParams() ? JSON.toJSONString(pjp.getArgs()) : null;
    if (invokeStat.writeLog())
        log.info("invoke-time-{}: {}ms, params:{}", recKey, time, params);
    return result;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Tick(mysh.util.Tick) Around(org.aspectj.lang.annotation.Around)

Example 79 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.

the class PerformanceInspector method inspect.

public Object inspect(final ProceedingJoinPoint pjp) throws Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    InvokeInfo invokeInfo = invokeInfoThreadLocal.get();
    boolean isRoot = false;
    if (invokeInfo == null) {
        invokeInfo = new InvokeInfo();
        invokeInfoThreadLocal.set(invokeInfo);
        isRoot = true;
    }
    MutableTriple<Integer, MethodSignature, Long> currInvokeInfo = MutableTriple.of(invokeInfo.currentLevel++, signature, 0L);
    invokeInfo.infos.add(currInvokeInfo);
    try {
        Tick tick = Tick.tick();
        Object result = pjp.proceed();
        currInvokeInfo.setRight(tick.nip());
        return result;
    } finally {
        invokeInfo.currentLevel--;
        if (isRoot) {
            for (MutableTriple<Integer, MethodSignature, Long> info : invokeInfo.infos) {
                System.out.println(genInfoStr(info));
            }
            invokeInfoThreadLocal.set(null);
        }
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Tick(mysh.util.Tick)

Example 80 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project mlib by myshzzx.

the class LocalCacheAspect method getLocalCache.

@Around("local()")
public Object getLocalCache(final ProceedingJoinPoint pjp) throws Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Method method = pjp.getTarget().getClass().getMethod(signature.getName(), signature.getMethod().getParameterTypes());
    Object[] args = pjp.getArgs();
    LocalCache conf = method.getAnnotation(LocalCache.class);
    Cache<Object, AtomicReference<?>> cache = getCache(method, conf);
    if (conf.isMultiKey()) {
        // MultiKeyInvokeWrap keyInfo = parseMultiKey(conf.keyExp(), pjp.getTarget(), signature.getMethod(), args);
        return null;
    } else {
        // single key
        Object key;
        if (StringUtils.isEmpty(conf.keyExp())) {
            // 自动生成 key
            key = genKey(args);
        } else
            key = parseSingleKey(conf.keyExp(), method, args);
        try {
            AtomicReference<?> resultWrapper = cache.get(key, new Callable<AtomicReference<?>>() {

                @Override
                public AtomicReference<?> call() throws Exception {
                    try {
                        return new AtomicReference<>(pjp.proceed());
                    } catch (Throwable t) {
                        if (t instanceof Exception)
                            throw (Exception) t;
                        else
                            throw new Exception(t);
                    }
                }
            });
            return resultWrapper.get();
        } catch (ExecutionException | UncheckedExecutionException | ExecutionError e) {
            throw e.getCause();
        }
    }
}
Also used : ExecutionError(com.google.common.util.concurrent.ExecutionError) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) MethodSignature(org.aspectj.lang.reflect.MethodSignature) AtomicReference(java.util.concurrent.atomic.AtomicReference) Method(java.lang.reflect.Method) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Around(org.aspectj.lang.annotation.Around)

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