Search in sources :

Example 16 with Signature

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()));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Signature(org.aspectj.lang.Signature)

Example 17 with Signature

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;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Example 18 with Signature

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;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with Signature

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);
}
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 20 with Signature

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);
}
Also used : Arrays(java.util.Arrays) Signature(org.aspectj.lang.Signature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Tuple(org.rx.bean.Tuple) StringBuilder(org.rx.util.StringBuilder) FeignClient(org.springframework.cloud.netflix.feign.FeignClient) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) LogInterceptor(org.rx.util.LogInterceptor) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) FeignClient(org.springframework.cloud.netflix.feign.FeignClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Signature (org.aspectj.lang.Signature)28 MethodSignature (org.aspectj.lang.reflect.MethodSignature)17 Method (java.lang.reflect.Method)12 Around (org.aspectj.lang.annotation.Around)6 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)4 JoinPoint (org.aspectj.lang.JoinPoint)3 CodeSignature (org.aspectj.lang.reflect.CodeSignature)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Test (org.testng.annotations.Test)2 DataSource (com.ikoori.vip.common.annotion.DataSource)1 BussinessLog (com.ikoori.vip.common.annotion.log.BussinessLog)1 AbstractDictMap (com.ikoori.vip.common.constant.dictmap.base.AbstractDictMap)1 ShiroUser (com.ikoori.vip.server.core.shiro.ShiroUser)1 RequestLockable (com.jim.framework.annotationlock.annotation.RequestLockable)1 DynamicDataSource (com.junliang.spring.config.DynamicDataSource)1 User (gemma.gsec.model.User)1 AnnotationFormatError (java.lang.annotation.AnnotationFormatError)1 Executable (java.lang.reflect.Executable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1