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:org.cyclop.validation.AopValidator.java

License:Apache License

private BeanValidator createValidator(ProceedingJoinPoint pjp) {
    BeanValidator validator = BeanValidator.create(pjp.getSignature().toString());
    return validator;
}

From source file:org.dbg4j.core.aop.DebuggingAspect.java

License:Apache License

protected Method getMethod(final ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Method method = signature.getMethod();
    //if this is interface method, but not implementation method, we're trying to get "real" one
    if (method.getDeclaringClass().isInterface()) {
        try {/*from   w w  w  . j av  a  2  s  . com*/
            method = pjp.getTarget().getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
        } catch (Exception ignored) {
            /*it's better to have interface method than nothing*/}
    }
    return method;
}

From source file:org.dockhouse.aop.logging.LoggingAspect.java

License:LGPL

@Around("loggingPoincut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }/*from   www.  ja  v  a 2s.  c o  m*/
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}

From source file:org.easyrec.utils.spring.cache.aop.CachingAspectAdvice.java

License:Open Source License

/**
 * Takes a method name and its arguments and stores the result in a cache.
 *
 * @param pjp the JoinPoint containing information about the intercepted method call
 * @return the result of the method call
 * @throws Throwable//w w w .  j  av a 2  s  .  co m
 */
public Object cacheMethodResult(ProceedingJoinPoint pjp) throws Throwable {
    String targetName = pjp.getTarget().getClass().getName();
    String methodName = pjp.getSignature().getName();
    Object[] args = pjp.getArgs();
    Object result;

    Log logger = LogFactory.getLog(pjp.getTarget().getClass());

    if (logger.isDebugEnabled()) {
        logger.debug("looking for method " + methodName + " result in cache");
    }
    String cacheKey = getCacheKey(targetName, methodName, args);
    Element element = cache.get(cacheKey);
    if (element == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Cache miss - calling intercepted method!");
        }
        result = pjp.proceed();
        if (result == null)
            return null;
        if (logger.isDebugEnabled()) {
            logger.debug("Caching new result!");
        }
        try {
            element = new Element(cacheKey, (Serializable) result);
        } catch (Exception e) {
            logger.debug("xxResult " + result + " for key: " + cacheKey + "..." + e.getMessage());
            e.printStackTrace();
        }

        cache.put(element);
    }

    assert element != null;

    return element.getValue();
}

From source file:org.easyrec.utils.spring.log.aop.IOLogAspectAdvice.java

License:Open Source License

/**
 * Logs a method call and prints the arguments and the return value to the log level given in the
 * iol parameter./* w w w. j  a v  a 2s . c o m*/
 *
 * @param pjp the JoinPoint containing information about the intercepted method call
 * @param iol annotation for the IOLog aspect; contains info about the log level
 * @return the result of the method call
 * @throws Throwable
 */
public Object logIO(ProceedingJoinPoint pjp, IOLog iol) throws Throwable {

    StringBuilder sb = new StringBuilder();

    String methodName = pjp.getSignature().getName();

    // parameter names only work with when compiled with AspectJ compiler
    //String[] params = ((MethodSignature)pjp.getSignature()).getParameterNames();

    Class<?>[] paramTypes = ((MethodSignature) pjp.getSignature()).getParameterTypes();
    Class<?> returnType = ((MethodSignature) pjp.getSignature()).getReturnType();
    Object[] args = pjp.getArgs();

    Log logger = LogFactory.getLog(pjp.getTarget().getClass());

    Object o = pjp.proceed();
    if (!LoggerUtils.isLogLevelEnabled(logger, iol.value()))
        return o;
    sb.append(methodName).append(argsToString(paramTypes, args)).append(':').append(returnType.getName())
            .append('=').append(o);
    LoggerUtils.log(logger, iol.value(), sb.toString());
    return o;
}

From source file:org.easyrec.utils.spring.profile.aop.JamonProfilingAspectAdvice.java

License:Open Source License

/**
 * @param pjp// w  w w.  j  a va 2  s .  c  o  m
 * @return
 */
private String createMonitorName(ProceedingJoinPoint pjp) {
    if (GROUPING_CLASS.equals(grouping)) {
        return pjp.toLongString();
    } else if (GROUPING_METHOD.equals(grouping)) {
        return pjp.getSignature().toLongString();
    } else {
        throw new IllegalStateException(
                "parameter 'grouping' must be one of [" + GROUPING_CLASS + "," + GROUPING_METHOD + "]");
    }
}

From source file:org.ednovo.gooru.security.MethodAuthorizationAspect.java

License:Open Source License

public boolean hasOperationsAuthority(AuthorizeOperations authorizeOperations, ProceedingJoinPoint pjp) {
    if (authorizeOperations.operations().length == 0) {
        return true;
    }//from  w w w . jav  a  2 s.  c  om

    GooruAuthenticationToken authenticationContext = (GooruAuthenticationToken) SecurityContextHolder
            .getContext().getAuthentication();
    if (authenticationContext != null && authenticationContext.getErrorMessage() != null) {
        if (authenticationContext.getErrorCode() == 403) {
            throw new AccessDeniedException(authenticationContext.getErrorMessage());
        } else {
            throw new MethodFailureException(authenticationContext.getErrorMessage());
        }
    }
    if (authenticationContext == null) {
        throw new AccessDeniedException("Invalid Session Token");
    }
    if (hasAuthorization(authorizeOperations)) {
        return true;
    }
    LOGGER.error("Permission Denied For : " + authenticationContext.getPrincipal() + " To Access : "
            + pjp.getSignature().getName());
    return false;
}

From source file:org.entando.entando.aps.system.services.cache.CacheInfoManager.java

License:Open Source License

@Around("@annotation(cacheableInfo)")
public Object aroundCacheableMethod(ProceedingJoinPoint pjp, CacheableInfo cacheableInfo) throws Throwable {
    Object result = pjp.proceed();
    if (cacheableInfo.expiresInMinute() < 0
            && (cacheableInfo.groups() == null || cacheableInfo.groups().trim().length() == 0)) {
        return result;
    }// w  w  w  . j ava  2s .  c om
    try {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method targetMethod = methodSignature.getMethod();
        Class targetClass = pjp.getTarget().getClass();
        Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(),
                targetMethod.getParameterTypes());
        Cacheable cacheable = effectiveTargetMethod.getAnnotation(Cacheable.class);
        if (null == cacheable) {
            return result;
        }
        String[] cacheNames = cacheable.value();
        Object key = this.evaluateExpression(cacheable.key().toString(), targetMethod, pjp.getArgs(),
                effectiveTargetMethod, targetClass);
        for (String cacheName : cacheNames) {
            if (cacheableInfo.groups() != null && cacheableInfo.groups().trim().length() > 0) {
                Object groupsCsv = this.evaluateExpression(cacheableInfo.groups().toString(), targetMethod,
                        pjp.getArgs(), effectiveTargetMethod, targetClass);
                if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
                    String[] groups = groupsCsv.toString().split(",");
                    this.putInGroup(cacheName, key.toString(), groups);
                }
            }
            if (cacheableInfo.expiresInMinute() > 0) {
                this.setExpirationTime(cacheName, key.toString(), cacheableInfo.expiresInMinute());
            }
        }
    } catch (Throwable t) {
        logger.error("Error while evaluating cacheableInfo annotation", t);
        throw new ApsSystemException("Error while evaluating cacheableInfo annotation", t);
    }
    return result;
}

From source file:org.entando.entando.aps.system.services.cache.CacheInfoManager.java

License:Open Source License

@Around("@annotation(cacheInfoEvict)")
public Object aroundCacheInfoEvictMethod(ProceedingJoinPoint pjp, CacheInfoEvict cacheInfoEvict)
        throws Throwable {
    try {//w w  w  . jav  a 2  s .  c  om
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method targetMethod = methodSignature.getMethod();
        Class targetClass = pjp.getTarget().getClass();
        Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(),
                targetMethod.getParameterTypes());
        String[] cacheNames = cacheInfoEvict.value();
        Object groupsCsv = this.evaluateExpression(cacheInfoEvict.groups().toString(), targetMethod,
                pjp.getArgs(), effectiveTargetMethod, targetClass);
        if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
            String[] groups = groupsCsv.toString().split(",");
            for (String group : groups) {
                for (String cacheName : cacheNames) {
                    this.flushGroup(cacheName, group);
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error while flushing group", t);
        throw new ApsSystemException("Error while flushing group", t);
    }
    return pjp.proceed();
}

From source file:org.esupportail.commons.aop.AopUtils.java

License:Apache License

/**
 * @param joinPoint//from  w ww .j av  a 2 s .  c  o m
 * @return The key to cache the method call
 */
public static String getCacheKey(final ProceedingJoinPoint joinPoint) {
    Object[] args = joinPoint.getArgs();
    String key = joinPoint.getSignature().toLongString() + "(";
    String separator = "";
    for (int i = 0; i < args.length; i++) {
        key += separator;
        Object o = args[i];
        if (o == null) {
            key += "null";
        } else {
            key += o.getClass().getSimpleName();
            if (o instanceof String || o instanceof Number || o instanceof Boolean) {
                key += "[" + o + "]";
            } else {
                key += "#" + o.hashCode();
            }
        }
        separator = ", ";
    }
    key += ")";
    return key;
}