Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:com.smallchill.core.aop.PermissionAop.java

License:Apache License

@Around("cutPermission()")
public Object doPermission(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();//from  w ww.  j  av  a 2 s  .c om
    MethodSignature ms = (MethodSignature) point.getSignature();
    Method method = ms.getMethod();
    Permission permission = method.getAnnotation(Permission.class);
    Object[] permissions = permission.value();
    if ((permissions.length == 1 && Func.format(permissions[0]).equals("ALL")) || permissions == null
            || permissions.length == 0) {
        //
        boolean result = PermissionCheckManager.checkAll(request);
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    } else {
        //
        boolean result = PermissionCheckManager.check(permissions, request);
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    }

}

From source file:com.snapdeal.archive.aspect.ArchivingExceptionHandlingAspect.java

License:Open Source License

/**
 * This method is a retry mechanism for various method, It will retry the method the given number of times in case
 * of exception//from www  . j av  a  2  s  .c o  m
 * 
 * @param pjp
 * @throws Throwable
 */
@Around("markArchive()  || insertIntoArchivalDb() || verifyCount() || deleteData()")
public void wrapExceptionHandling(ProceedingJoinPoint pjp) throws Throwable {

    int i = 0;
    while (i < maxRetryCount) {
        try {
            pjp.proceed();
            break;
        } catch (Throwable e) {
            i++;
            int tryCount = i + 1;
            SystemLog.logMessage("Some exception occurred ivoking method " + pjp.getSignature().getName()
                    + ". Trying for " + tryCount + " time");
            if (i == maxRetryCount - 1) {
                SystemLog.logException("Cannot complete the method " + pjp.getSignature().getName()
                        + " evene after trying " + maxRetryCount + " times...");
                throw e;
            }

        }
    }

}

From source file:com.solace.logging.AspectJTimingAspect.java

License:Open Source License

/**
 * Will do the typical invocation of the logging instances via perf4j but
 * will do them instead of on annotated methods but on all public methods.
 * Additionally will guarantee that no instrumentation is needed for the
 * enter and exit in the typical application logs
 * //from   w  ww.j  ava 2s. c  om
 * @param pjp
 *            a ProceedingJoinPoint compiled in via aspectj
 * @return returns the object if any
 * @throws Throwable
 */
@Around(value = "execution(public * *(..))", argNames = "pjp")
public Object doPerfLogging(final ProceedingJoinPoint pjp) throws Throwable {
    Object o = null;
    Object caller = pjp.getThis();

    Logger logger = null;
    if (pjp.getThis() != null)
        logger = Logger.getLogger(pjp.getThis().getClass());
    else
        logger = Logger.getLogger("main");

    Profiled p = DefaultProfiled.INSTANCE;

    try {
        if (logger.isDebugEnabled()) {
            logger.debug(ENTER, pjp.getSignature().toShortString());
            if (pjp.getArgs() != null && pjp.getArgs().length > 0) {
                StringBuilder sb = new StringBuilder();
                for (Object param : pjp.getArgs())
                    sb.append(param).append("; ");

                logger.debug(INPUT, sb.toString());
            }
        }
        o = super.doPerfLogging(pjp, p);
    } finally {
        if (logger.isDebugEnabled())
            logger.debug(EXIT, pjp.getSignature().toShortString());
    }
    return o;
}

From source file:com.spidertracks.datanucleus.spring.ConsistencyLevelAspect.java

License:Open Source License

/**
 * Validates any method that has the valid annotation on it and is wired as
 * a spring service//from w  ww .  j  a v  a2  s  .c o  m
 * 
 * @param jp
 * @throws Throwable
 */
@Around("@annotation(com.spidertracks.datanucleus.spring.Consistency)")
public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable {

    logger.debug("Invoking before advice for @Consistency annotation.  Target object is {} on method {}",
            pjp.getTarget(), pjp.getSignature());

    MethodSignature sig = (MethodSignature) pjp.getSignature();

    Object[] args = pjp.getArgs();

    Method signatureMethod = sig.getMethod();

    Class<?>[] signatureTypes = signatureMethod.getParameterTypes();

    // we do this because we want to get the best match from the child
    // classes
    Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length];

    for (int i = 0; i < signatureTypes.length; i++) {

        if (args[i] != null) {
            runtimeArgs[i] = args[i].getClass();
        } else {
            runtimeArgs[i] = signatureTypes[i];
        }
    }

    Class<?> runtimeClass = pjp.getTarget().getClass();

    // check if this is annotated, if not proceed and execute it

    ConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs);

    if (level == null) {
        return pjp.proceed(args);
    }

    Stack<ConsistencyLevel> stack = threadStack.get();

    stack.push(level);
    com.spidertracks.datanucleus.client.Consistency.set(level);

    Object result = null;

    try {
        result = pjp.proceed(args);
    } finally {
        stack.pop();

        if (stack.size() > 0) {
            com.spidertracks.datanucleus.client.Consistency.set(stack.peek());
        } else {
            com.spidertracks.datanucleus.client.Consistency.remove();
        }

    }

    return result;
}

From source file:com.spstudio.common.log.ServiceExceptionLogAspect.java

@Around("serviceAspect()")
public Object doAroundTask(ProceedingJoinPoint pjp) throws Throwable {
    logger.warn("Entering.." + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
    try {/*from   w w  w .jav  a 2s .  c om*/
        return pjp.proceed();
    } catch (Throwable ex) {

        System.out.println("error in around");
        throw ex;
    } finally {
        logger.warn(
                "Exiting.." + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
    }
}

From source file:com.spstudio.modules.permission.controller.LoginControlAspect.java

@Around("@annotation(com.spstudio.modules.permission.controller.UserSessionValidator)")
public Object sessionValidationAdvice(ProceedingJoinPoint pjp) throws GenericException, Throwable {
    Object args[] = pjp.getArgs();
    Object result = null;//ww w .j a  v  a 2s .  co m
    String targetName = pjp.getTarget().getClass().getSimpleName();
    String methodName = pjp.getSignature().getName();
    logger.info("----------------MethodName-----------------");
    logger.info("Class:" + targetName + " Method:" + methodName);

    //HttpSession session = SysContent.getSession();  
    if (session.getAttribute("username") != null) {

        //Logic to check user priviledge
        Privilege checkingFuncationPrivilege = permissionService.findPrivilegeByFuncationName(methodName);

        String userName = (String) session.getAttribute("username");
        LoginUser loginUser = permissionService.getLoginUserByLoginName(userName);

        if (loginUser != null) {
            Set<Privilege> permissionedPrivileges = permissionService.listPrivilegsByLoginUser(loginUser);
            if (permissionedPrivileges.contains(checkingFuncationPrivilege)) {
                result = pjp.proceed(args);
            } else {
                throw new InsufficientPriviledgeException("403", "no permission");
            }
        } else {
            throw new InsufficientPriviledgeException("403", "no permission");
        }

        return result;
    } else {
        //            System.out.println(((MethodSignature)pjp.getSignature()).getReturnType().getSimpleName().toString());  
        String redirectStr = "login";
        String returnType = ((MethodSignature) pjp.getSignature()).getReturnType().getSimpleName().toString();
        if (returnType.equals("String")) {
            return redirectStr;
        } else if (returnType.equals("Map")) {
            Map<String, Object> resMap = new HashMap<>();
            resMap.put("resCode", MessageContent.MSG_CODE_SESSIONOUTOFDATE);
            resMap.put("resMsg", MessageContent.MSG_SESSIONOUTOFDATE);
            return resMap;
        } else {
            throw new SessionTimeOutException(MessageContent.MSG_CODE_SESSIONOUTOFDATE,
                    MessageContent.MSG_SESSIONOUTOFDATE);
        }
    }
}

From source file:com.spstudio.session.filter.SessionAOP.java

private UserSessionType getSessionType(ProceedingJoinPoint pj) {
    // ? Method  
    MethodSignature joinPointObject = (MethodSignature) pj.getSignature();
    Method method = joinPointObject.getMethod();
    boolean flag = method.isAnnotationPresent(UserSession.class);
    if (flag) {/*from  w ww . j  a  v a  2s  . c o m*/
        UserSession annotation = method.getAnnotation(UserSession.class);
        return annotation.value();
    }
    return null;
}

From source file:com.square.logs.aop.advice.GestionLogAdvice.java

License:Open Source License

/**
 * ajoute le log de l'appel service.//from w ww  . ja va2 s .  c  o m
 * @param point l'appel intercept
 * @return Object retour de l'appel
 * @throws Throwable exception
 */
public Object log(ProceedingJoinPoint point) throws Throwable {
    Object retVal = null;
    final String methodName = point.getSignature().toLongString();
    final Object[] args = point.getArgs();

    final LogDto logDto = new LogDto();
    logDto.setApplication(application);
    logDto.setProfondeur(profondeur);
    logDto.setDate(Calendar.getInstance());
    logDto.setSignature(methodName);

    try {
        logDto.setParametres(Arrays.asList(args));
        retVal = point.proceed();
        logDto.setResultat(retVal);
        if (logLevel == LogLevel.INFO) {
            logService.ajouterLog(logDto);
        }
        return retVal;
    } catch (Throwable e) {
        if (logLevel != LogLevel.NONE) {
            logDto.setTraceException(e.getMessage());
            logService.ajouterLog(logDto);
        }
        throw e;
    }
}

From source file:com.stee.asm.aop.LoggerAdvice.java

License:Open Source License

@Around("servicePointCut()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    logger.doLog(LoggerLevel.INFO, "Invoke --> Class: " + pjp.getTarget().getClass().getSimpleName()
            + " -- Method: " + pjp.getSignature().getName() + " -- Args: " + Arrays.toString(pjp.getArgs()));
    long timeMills = System.currentTimeMillis();
    Object proceed = pjp.proceed();
    logger.doLog(LoggerLevel.INFO,//from w  w w. j  a  va  2s  .co m
            "Finish --> Return: " + proceed + " -- Cost: " + (System.currentTimeMillis() - timeMills));
    return proceed;
}

From source file:com.stratelia.webactiv.util.annotation.AnnotationUtil.java

License:Open Source License

/**
 * Provides a centralized way to extract annotation of a method.
 * @param invocationContext//from   ww w.  java2  s  .  c  o  m
 * @return
 * @throws Exception
 */
private static Method getMethodFromContext(Object invocationContext) throws Exception {
    if (invocationContext instanceof ProceedingJoinPoint) {
        ProceedingJoinPoint context = (ProceedingJoinPoint) invocationContext;
        final String methodName = context.getSignature().getName();
        final MethodSignature methodSignature = (MethodSignature) context.getSignature();
        Method method = methodSignature.getMethod();
        if (method.getDeclaringClass().isInterface()) {
            method = context.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
        }
        return method;
    } else if (invocationContext instanceof InvocationContext) {
        return ((InvocationContext) invocationContext).getMethod();
    }
    throw new NotImplementedException();
}