Search in sources :

Example 61 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project FS-Blog by JamesZBL.

the class AspectUtil method getAnnotation.

/**
 * 获取连接点的制定类型的注解
 *
 * @param joinPoint 连接点
 * @param clazz     注解类
 *
 * @return 注解
 */
public static Annotation getAnnotation(ProceedingJoinPoint joinPoint, Class clazz) {
    try {
        // 拦截的对象
        Object object = joinPoint.getTarget();
        Signature signature = joinPoint.getSignature();
        // 拦截方法名
        String methodName = signature.getName();
        Class[] parameterTypes = ((MethodSignature) signature).getMethod().getParameterTypes();
        try {
            // 反射目标方法
            Method method = object.getClass().getDeclaredMethod(methodName, parameterTypes);
            // 获取注解
            return method.getDeclaredAnnotation(clazz);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    return null;
}
Also used : Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 62 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project rocketmq-externals by apache.

the class MQAdminAspect method aroundMQAdminMethod.

@Around(value = "mQAdminMethodPointCut() || multiMQAdminMethodPointCut()")
public Object aroundMQAdminMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    long start = System.currentTimeMillis();
    Object obj = null;
    try {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        MultiMQAdminCmdMethod multiMQAdminCmdMethod = method.getAnnotation(MultiMQAdminCmdMethod.class);
        if (multiMQAdminCmdMethod != null && multiMQAdminCmdMethod.timeoutMillis() > 0) {
            MQAdminInstance.initMQAdminInstance(multiMQAdminCmdMethod.timeoutMillis());
        } else {
            MQAdminInstance.initMQAdminInstance(0);
        }
        obj = joinPoint.proceed();
    } finally {
        MQAdminInstance.destroyMQAdminInstance();
        logger.debug("op=look method={} cost={}", joinPoint.getSignature().getName(), System.currentTimeMillis() - start);
    }
    return obj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Example 63 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project paascloud-master by paascloud.

the class MqProducerStoreAspect method getAnnotation.

private static MqProducerStore getAnnotation(JoinPoint joinPoint) {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Method method = methodSignature.getMethod();
    return method.getAnnotation(MqProducerStore.class);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 64 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project dubbo-faker by moyada.

the class FakerAop method questRecord.

@SuppressWarnings("unchecked")
public void questRecord(JoinPoint jp, Faker faker) throws NoSuchMethodException {
    if (!enable) {
        return;
    }
    // 参数值
    Object[] args = jp.getArgs();
    Signature signature = jp.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Method targetMethod = methodSignature.getMethod();
    // 方法名
    String methodName = signature.getName();
    // 调用接口对象
    String declaringClassName = signature.getDeclaringTypeName();
    // 返回值
    Class returnType = methodSignature.getReturnType();
    String returnTypeName = returnType.getName();
    // 
    // // 参数类型
    Class<?>[] parameterTypes = targetMethod.getParameterTypes();
// String[] argsType = Stream.of(parameterTypes).map(Class::getTypeName).toArray(String[]::new);
// String argsTypeName = JsonUtil.toJson(argsType);
// 
// CatchDTO catchDTO = CatchCache.get(declaringClassName, methodName, returnTypeName, argsTypeName);
// if(null == catchDTO) {
// Class[] interfaces = signature.getDeclaringType().getInterfaces();
// if(null == interfaces || interfaces.length == 0) {
// log.error("FakerAop Exception: {}.{}({}) can not find any interface class.", declaringClassName, declaringClassName, argsTypeName);
// return;
// }
// for (Class inter : interfaces) {
// Method method = inter.getMethod(methodName, parameterTypes);
// if (null != method) {
// catchDTO = CatchCache.set(declaringClassName, methodName, returnTypeName, argsTypeName, inter.getName());
// break;
// }
// }
// }
// 
// if(null == catchDTO) {
// return;
// }
// 
// catchDTO.setAppName(appName);
// String type = faker.value();
// catchDTO.setType(type);
// catchDTO.setArgsValue(JsonUtil.toJson(args));
// fakerService.catchRequest(catchDTO);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 65 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project nextprot-api by calipho-sib.

the class ServiceEntryValidation method checkValidEntry.

@Around("execution(* org.nextprot.api.*.service.*.*(..))")
public // @Around("execution(* org.nextprot.api.*.service.*.*(.., @aspects.ValidEntry (*), ..))")
Object checkValidEntry(ProceedingJoinPoint pjp) throws Throwable {
    Object[] arguments = pjp.getArgs();
    for (Object arg : arguments) {
        if ((arg != null) && EntryConfig.class.isAssignableFrom(arg.getClass())) {
            String argument = ((EntryConfig) arg).getEntryName();
            String entryAccession = EntryUtils.getEntryName(argument);
            if (!uniqueNames.contains(entryAccession)) {
                LOGGER.error("neXtProt entry " + argument + " was not found, throwing EntryNotFoundException");
                throw new EntryNotFoundException(argument);
            }
        }
    }
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Annotation[][] annotations = ms.getMethod().getParameterAnnotations();
    int i = 0;
    for (Annotation[] paramAnnotations : annotations) {
        for (Annotation annotation : paramAnnotations) {
            if (ValidEntry.class.isAssignableFrom(annotation.getClass())) {
                if (!uniqueNames.contains(arguments[i])) {
                    LOGGER.error("neXtProt entry " + arguments[i] + " was not found, throwing EntryNotFoundException");
                    throw new EntryNotFoundException((String) arguments[i]);
                }
                break;
            }
        }
        i++;
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) EntryNotFoundException(org.nextprot.api.commons.exception.EntryNotFoundException) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation) 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