use of org.aspectj.lang.Signature in project free-framework by a601942905git.
the class WebLogAspect method doBefore.
/**
* 进入切入点之前执行
* @param joinPoint
*/
@Before("WebLogAspect()")
public void doBefore(JoinPoint joinPoint) {
SYSTEM_MILLIS_THREAD_LOCAL.set(DateUtils.getSystemMillis());
Signature signature = joinPoint.getSignature();
HttpServletRequest request = WebContextUtils.getRequest();
log.info("==================请求开始=====================");
log.info("Request IP:{}", request.getRemoteAddr());
log.info("Request URL:{}", request.getRequestURL());
log.info("Request Method:{}", request.getMethod());
log.info("Request Class Method:{}", signature.getDeclaringTypeName() + "." + signature.getName());
log.info("Request Method Args:{}", Arrays.toString(joinPoint.getArgs()));
}
use of org.aspectj.lang.Signature in project free-framework by a601942905git.
the class DynamicDataSourceAspect method doAround.
/**
* 在切入点方法执行前后加入逻辑
* @param pjp
*/
@Around("pointCutMethod()")
public Object doAround(ProceedingJoinPoint pjp) {
Object obj = null;
Signature signature = pjp.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Object target = pjp.getTarget();
try {
Method method = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
String methodName = method.getName();
setDataSourceType(methodName);
// 执行目标方法
obj = pjp.proceed();
// 释放当前线程中的资源
DataSourceHolder.removeDataSourceKey();
} catch (NoSuchMethodException e) {
log.error("======>DynamicDataSourceAspect.doAround,NoSuchMethodException:{}", e);
} catch (Throwable throwable) {
log.error("======>DynamicDataSourceAspect.doAround,throwable:{}", throwable);
}
return obj;
}
use of org.aspectj.lang.Signature in project myjdbc by beijing-penguin.
the class TransactionManager method doAround.
// 用来做环绕通知的方法可以第一个参数定义为org.aspectj.lang.ProceedingJoinPoint类型
public Object doAround(ProceedingJoinPoint call) throws Throwable {
Signature sig = call.getSignature();
MethodSignature ms = (MethodSignature) sig;
Method method = call.getTarget().getClass().getDeclaredMethod(ms.getName(), ms.getParameterTypes());
Transactional transactional = method.getAnnotation(Transactional.class);
if (transactional == null) {
// 方法无注解,查找类上注解,并判断当前调用方法是否为当前类定义的(防止父类方法触发事务边界)
transactional = method.getDeclaringClass().getAnnotation(Transactional.class);
}
if (transactional != null) {
// 如果不为空,则开启事务
if (transactional.readOnly() == false) {
ConnectionManager.setTransaction(true);
} else {
ConnectionManager.setReadOnly(true);
}
} else {
ConnectionManager.setTransaction(false);
ConnectionManager.setReadOnly(false);
}
Object invokeObj = null;
try {
// 执行目标方法
invokeObj = call.proceed();
// invokeObj = method.invoke(call.getTarget(), call.getArgs());
ConnectionManager.commitAll();
} catch (Throwable e) {
ConnectionManager.rollbackAll();
throw e;
} finally {
ConnectionManager.closeConnectionAll();
}
return invokeObj;
}
use of org.aspectj.lang.Signature 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.Signature in project rxlib by RockyLOMO.
the class FeignInterceptor method onProcess.
@Override
protected Object onProcess(ProceedingJoinPoint joinPoint, StringBuilder msg) throws Throwable {
Signature signature = joinPoint.getSignature();
if (!(signature instanceof MethodSignature)) {
return joinPoint.proceed();
}
Method method = ((MethodSignature) signature).getMethod();
RequestMapping apiMapping = method.getAnnotation(RequestMapping.class);
if (apiMapping == null) {
return joinPoint.proceed();
}
String url = "";
FeignClient feignClient = null;
for (Class<?> pi : joinPoint.getTarget().getClass().getInterfaces()) {
if ((feignClient = pi.getAnnotation(FeignClient.class)) != null) {
break;
}
}
if (feignClient != null) {
url += feignClient.url();
}
RequestMapping baseMapping = method.getDeclaringClass().getAnnotation(RequestMapping.class);
Function<RequestMapping, String> pf = p -> String.join(",", !ArrayUtils.isEmpty(p.value()) ? p.value() : p.path());
if (baseMapping != null) {
url += pf.apply(baseMapping);
}
url += pf.apply(apiMapping);
String httpMethod = ArrayUtils.isEmpty(apiMapping.method()) ? "POST" : String.join(",", Arrays.stream(apiMapping.method()).map(p -> p.name()).collect(Collectors.toList()));
msg.appendLine().appendLine("%s\t\t%s", httpMethod, resolveUrl(url, signature));
return super.onProcess(joinPoint, msg);
}
Aggregations