Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

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

Introduction

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

Prototype

Object[] getArgs();

Source Link

Usage

From source file:org.cyclop.validation.AopValidator.java

License:Apache License

private void executeParamValidation(ProceedingJoinPoint pjp) {
    Object[] args = pjp.getArgs();
    MethodSignature sig = (MethodSignature) pjp.getSignature();
    Method method = sig.getMethod();
    Annotation[][] allParamAnnotations = method.getParameterAnnotations();

    BeanValidator validator = null;//from   w w w  .  ja v a 2 s .c  om
    for (int paramIdx = 0; paramIdx < allParamAnnotations.length; paramIdx++) {
        Annotation[] paramAnnotations = allParamAnnotations[paramIdx];
        if (paramAnnotations == null || paramAnnotations.length == 0) {
            continue;
        }
        Object obj = args[paramIdx];
        if (contains(paramAnnotations, NotNull.class)
                || (contains(paramAnnotations, Valid.class) && obj != null)) {
            if (validator == null) {
                validator = createValidator(pjp);
            }
            validator.add("METHOD_PARAM_INDEX_" + paramIdx, obj);
        }
    }
    if (validator != null) {
        validator.validate();
    }
}

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

License:Apache License

protected Object doDebug(final ProceedingJoinPoint pjp, final Debug debug) throws Throwable {
    DebuggingAdapter debuggerInstance = getDebugger(debug);

    return debuggerInstance.debug(new MethodInvocationPoint() {

        @Override/*from   w  w  w. j  a v  a2s . c  o  m*/
        public Method getMethod() {
            return DebuggingAspect.this.getMethod(pjp);
        }

        @Nullable
        @Override
        public Object invoke() throws Throwable {
            return pjp.proceed();
        }

        @Nullable
        @Override
        public Object[] getParameters() {
            return pjp.getArgs();
        }

        @Nullable
        @Override
        public Object getInstance() {
            return pjp.getTarget();
        }

        @Override
        public Debug getDebugAnnotation() {
            return debug;
        }
    });
}

From source file:org.dbist.aspect.SqlAspect.java

License:Apache License

public Object print(final ProceedingJoinPoint point) throws Throwable {
    print(point.getArgs());

    return point.proceed();
}

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 ww w .j  a  v a  2  s.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.controller.aop.LoggedInCheckAspect.java

License:Open Source License

@Around("allControllers()")
public Object LoggedInAspect(ProceedingJoinPoint pjp) throws Throwable {

    HttpServletRequest request = (HttpServletRequest) pjp.getArgs()[0];
    HttpSession session = request.getSession(false);

    ModelAndView originalModelAndView = (ModelAndView) pjp.proceed();

    if (extendedWebAppPath == null)
        initPath(request);//  www.  j  a  v a 2 s.c  o m

    boolean signedIn = false;

    try {
        if (session != null && session.getAttribute("signedInOperatorId") != null)
            signedIn = true;

        if (originalModelAndView != null) {
            originalModelAndView.addObject("signedIn", signedIn);
            originalModelAndView.addObject("isDeveloper", Security.isDeveloper(request));
            originalModelAndView.addObject("securityToken", Security.getSecurityToken(request));
            originalModelAndView.addObject("webappPath", webappPath);
            originalModelAndView.addObject("extendedWebappPath", extendedWebAppPath);
            originalModelAndView.addObject("isGenerator", easyrecSettings.isGenerator());
            originalModelAndView.addObject("operationMode", easyrecSettings.getOperationMode());

            originalModelAndView.addObject("currentMonth", MyUtils.getCurrentMonth());
            originalModelAndView.addObject("currentMonthName", MyUtils.getCurrentMonthName());
            originalModelAndView.addObject("currentYear", MyUtils.getCurrentYear());

            if (session != null) {
                originalModelAndView.addObject("signedInOperator", session.getAttribute("signedInOperator"));
                originalModelAndView.addObject("signedInOperatorId",
                        session.getAttribute("signedInOperatorId"));
            }

            originalModelAndView.addObject("easyrecName", easyrecSettings.getName());
            originalModelAndView.addObject("easyrecVersion", easyrecSettings.getVersion());
            originalModelAndView.addObject("easyrecBiz", easyrecSettings.getBiz());
            originalModelAndView.addObject("easyrecReleases", easyrecSettings.getReleases());
            originalModelAndView.addObject("checkUpdateUrl", easyrecSettings.getUpdateURL());
            originalModelAndView.addObject("updateUrl", easyrecSettings.getReleases());
        }
    } catch (IllegalStateException e) {
        logger.debug("User Logged Out and can not get Session atributes.", e);
    }

    String currentPage = request.getRequestURI();
    boolean isPublicSite = PUBLIC_SITES.contains(currentPage);

    if (!signedIn && !isPublicSite)
        return new ModelAndView("redirect:" + webappPath + "/home");

    return originalModelAndView;
}

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//from www  .jav  a 2  s.  c o 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./*from   ww w.j  a  va 2 s  .  co 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.ednovo.gooru.security.MethodAuthorizationAspect.java

License:Open Source License

public boolean hasPartyAuthorization(AuthorizeOperations authorizeOperations, ProceedingJoinPoint pjp,
        RequestMapping requestMapping) {

    GooruAuthenticationToken authenticationContext = (GooruAuthenticationToken) SecurityContextHolder
            .getContext().getAuthentication();

    if (authenticationContext != null) {
        boolean partyOperationCheck = false;
        String apiCallerPermission = null;
        List<String> partyPermissions = authenticationContext.getUserCredential().getPartyOperations();
        List<String> accessblePermissions = Arrays.asList(authorizeOperations.partyOperations());
        if (partyPermissions != null && accessblePermissions != null) {
            for (String partyPermission : partyPermissions) {
                if (accessblePermissions.contains(partyPermission)) {
                    partyOperationCheck = true;
                    apiCallerPermission = partyPermission;
                }//from   w w w  . j  a  va 2  s.  co  m
            }
        }
        final Signature signature = pjp.getStaticPart().getSignature();
        if (signature instanceof MethodSignature) {
            final MethodSignature ms = (MethodSignature) signature;
            String[] paramNames = parameterNameDiscoverer.getParameterNames(ms.getMethod());
            Object[] paramValues = pjp.getArgs();
            String partyUidName = authorizeOperations.partyUId();
            String partyUid = "";
            if (paramNames != null && paramValues != null) {
                for (int paramNameIndex = 0; paramNameIndex < paramNames.length; paramNameIndex++) {
                    String paramName = paramNames[paramNameIndex];
                    if (paramName instanceof String) {
                        if (paramName.equals(partyUidName)) {
                            if (paramValues[paramNameIndex] != null) {
                                partyUid = (String) paramValues[paramNameIndex];
                            }
                        }
                    }
                }
            }
            if (!partyUid.isEmpty()) {
                String[] permittedParties = authenticationContext.getUserCredential().getPartyPermits();
                List<String> permittedPartiesList = Arrays.asList(permittedParties);
                String apiCallerOrgUid = authenticationContext.getUserCredential().getOrganizationUid();
                String userUid = authenticationContext.getUserCredential().getUserUid();
                User user = userService.findByGooruId(partyUid);
                User apiCaller = userService.findByGooruId(userUid);
                RequestMethod[] requestMethods = requestMapping.method();

                if (partyUid.equals(userUid)) {
                    for (RequestMethod requestMethod : requestMethods) {
                        if (requestMethod.equals(RequestMethod.DELETE)) {
                            return false;
                        }
                    }
                    return true;
                } else if (user != null && partyOperationCheck && (permittedPartiesList.contains(partyUid)
                        || permittedPartiesList.contains(user.getOrganization().getPartyUid()))) {
                    if (user.getOrganization().getPartyUid().equals(apiCallerOrgUid)) {
                        if (apiCallerPermission.equalsIgnoreCase(GooruOperationConstants.GROUP_ADMIN)
                                && user.getUserGroup().equals(apiCaller.getUserGroup())) {
                            return true;
                        } else if (apiCallerPermission.equalsIgnoreCase(GooruOperationConstants.ORG_ADMIN)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    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;
    }//from  w w w .ja  v a 2 s.  c o  m
    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 {/*from   w  w w . java  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();
}