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;
}
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;
}
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);
}
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);
}
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();
}
Aggregations