Search in sources :

Example 1 with Signature

use of org.aspectj.lang.Signature in project head by mifos.

the class AspectJRESTApprovalInterceptor method profile.

@Around("restMethods() && requestMapping() && excludeAPI() && exludeRestfulServices()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    Signature signature = pjp.getStaticPart().getSignature();
    LOG.debug(this.getClass().getSimpleName() + " staring");
    // FIXME : somehow autowiring is not working
    if (approvalService == null) {
        approvalService = ApplicationContextProvider.getBean(ApprovalService.class);
    }
    if (configurationServiceFacade == null) {
        configurationServiceFacade = ApplicationContextProvider.getBean(ConfigurationServiceFacade.class);
    }
    if (parameterNameDiscoverer == null) {
        parameterNameDiscoverer = ApplicationContextProvider.getBean(ParameterNameDiscoverer.class);
    }
    if (!RESTConfigKey.isApprovalRequired(configurationServiceFacade)) {
        LOG.debug(pjp.getSignature() + " skip approval");
        return pjp.proceed();
    }
    if (signature instanceof MethodSignature) {
        MethodSignature ms = (MethodSignature) signature;
        Method m = ms.getMethod();
        RequestMapping mapping = m.getAnnotation(RequestMapping.class);
        if (isReadOnly(mapping)) {
            LOG.debug(m.getName() + " is read only, hence returning control");
            return pjp.proceed();
        }
        Class<?> methodClassType = m.getDeclaringClass();
        if (!methodClassType.getSimpleName().endsWith("RESTController")) {
            LOG.debug(m.getName() + " is not from REST controller, hence returning control");
            return pjp.proceed();
        }
        Object[] argValues = pjp.getArgs();
        Class<?>[] argTypes = m.getParameterTypes();
        String methodName = m.getName();
        String[] names = parameterNameDiscoverer.getParameterNames(m);
        MethodArgHolder args = new MethodArgHolder(argTypes, argValues, names);
        ApprovalMethod method = new ApprovalMethod(methodName, methodClassType, args);
        approvalService.create(method);
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer) ApprovalService(org.mifos.rest.approval.service.ApprovalService) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Method(java.lang.reflect.Method) ConfigurationServiceFacade(org.mifos.config.servicefacade.ConfigurationServiceFacade) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) Around(org.aspectj.lang.annotation.Around)

Example 2 with Signature

use of org.aspectj.lang.Signature in project dq-easy-cloud by dq-open-cloud.

the class DqLogBO method buildDqLogData.

/**
 * <p>
 * 构建日志数据
 * </p>
 *
 * @param pjp
 * @return
 * @author daiqi
 * 创建时间    2018年2月9日 上午11:14:51
 */
public DqLogBO buildDqLogData(ProceedingJoinPoint pjp) {
    Signature signature = pjp.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;
    Method targetMethod = methodSignature.getMethod();
    Class<?> targetClass = pjp.getTarget().getClass();
    this.buildTargetClassName(targetClass.getName()).buildTargetMethodName(targetMethod.getName());
    this.buildTargetParameterTypes(targetMethod.getParameterTypes()).buildTargetParameterValues(pjp.getArgs());
    this.buildTargetReturnType(targetMethod.getReturnType()).buildLogger(targetClass);
    this.buildRequestPath().buildDqLog(targetClass, targetMethod);
    return this;
}
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 3 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 4 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 5 with Signature

use of org.aspectj.lang.Signature in project rxlib by RockyLOMO.

the class LogInterceptor method doAround.

public final Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    Signature signature = joinPoint.getSignature();
    org.slf4j.Logger log;
    if ((Boolean) TC.get() || (log = getLogger(signature)) == null || !log.isInfoEnabled()) {
        return joinPoint.proceed();
    }
    StringBuilder msg = new StringBuilder();
    try {
        TC.set(TRUE);
        msg.appendLine("Call %s", signature.getName());
        return onProcess(joinPoint, msg);
    } catch (Exception e) {
        return onException(e, msg);
    } finally {
        log.info(msg.toString());
        TC.set(FALSE);
    }
}
Also used : Signature(org.aspectj.lang.Signature)

Aggregations

Signature (org.aspectj.lang.Signature)26 MethodSignature (org.aspectj.lang.reflect.MethodSignature)15 Method (java.lang.reflect.Method)12 Around (org.aspectj.lang.annotation.Around)5 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