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:com.evolveum.midpoint.util.aspect.ProfilingDataLog.java

License:Apache License

public Object[] retrieveMethodArguments(ProceedingJoinPoint pjp) {
    return pjp.getArgs();
}

From source file:com.facio.aop.EmulateFilterServletAspect.java

@Around("execution(* com.facio.service.*.*(..))") // the pointcut expression
public Object anyServiceLayerMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    Object result = null;//from  ww w .j  av a  2  s  .  com
    LOG.info("calling Aspect...");

    LOG.debug(
            "method called=" + joinPoint.getSignature().getName() + "; args=" + joinPoint.getArgs().toString());

    LOG.info(" ===== Initialize RequestContext =====");

    //This should be called to cache work
    HystrixRequestContext initializeContext = HystrixRequestContext.initializeContext();
    try {
        result = joinPoint.proceed();
        LOG.debug("result in Aspect=" + result);
    } finally {
        LOG.info(" ===== Close RequestContext =====");
        if (initializeContext != null) {
            initializeContext.shutdown();
        }
        LOG.info("Aspect called.");
    }

    return result;
}

From source file:com.feilong.spring.aop.LogAspect.java

License:Apache License

/**
 * Around./* w w w .ja va  2 s  . c om*/
 * 
 * @param proceedingJoinPoint
 *            the join point
 * @throws Throwable
 *             the throwable
 */
@Around(value = "pointcut()")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // LoggerFactory.
    // log.

    Method method = getMethod(proceedingJoinPoint, Log.class);
    String methodName = method.getName();
    Date begin = new Date();
    // ??
    proceedingJoinPoint.proceed();
    // ???????
    Date end = new Date();
    Object[] args = proceedingJoinPoint.getArgs();
    // for (Object arg : args){
    // log.info("arg:{}", arg.toString());
    // }
    // log.info("{},{}", begin, end);

    _log = getAnnotation(proceedingJoinPoint, Log.class);
    String level = _log.level();
    // log.debug("level:{}", level);
    //   02:13:10 INFO (NativeMethodAccessorImpl.java:?) [invoke0()] method:addUser([1018, Jummy]),:0
    // ReflectUtil.invokeMethod(log, level, "method:{}({}),:{}", objects);

    String format = "method:%s(%s),:%s";
    Object[] objects = { methodName, args, DateExtensionUtil.getIntervalForView(begin, end) };

    Object message = StringUtil.format(format, objects);
    log.log(Level.toLevel(level), message);
}

From source file:com.feilong.spring.aop.ProceedingJoinPointUtil.java

License:Apache License

/**
 *  map for log.// w w w .j a  v a2  s  . co m
 *
 * @param proceedingJoinPoint
 *            the proceeding join point
 * @return the map for log
 */
public final static Map<String, Object> getMapForLog(ProceedingJoinPoint proceedingJoinPoint) {
    Map<String, Object> map = new LinkedHashMap<String, Object>();

    Signature signature = proceedingJoinPoint.getSignature();
    MethodSignature methodSignature = (MethodSignature) signature;

    Method method = methodSignature.getMethod();
    Object[] args = proceedingJoinPoint.getArgs();

    Object target = proceedingJoinPoint.getTarget();

    Class<?> declaringType = methodSignature.getDeclaringType();

    Class<? extends Object> targetClass = target.getClass();
    map.put("target", targetClass.getCanonicalName());
    map.put("method", method.getName());
    map.put("args", args);

    return map;
}

From source file:com.feilong.spring.jdbc.datasource.MultipleGroupReadWriteDataSourceAspect.java

License:Apache License

/**
 * Proceed.//w w w  .  j a  v  a  2  s. com
 *
 * @param proceedingJoinPoint
 *            the proceeding join point
 * @return the object
 * @throws Throwable
 *             the throwable
 * @since 1.1.1
 */
private Object proceed(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object[] args = proceedingJoinPoint.getArgs();
    String format = getProceedingJoinPointJsonInfoExcludeJsonException(proceedingJoinPoint);

    if (log.isInfoEnabled()) {
        log.info("begin proceed ,ProceedingJoinPoint info:[{}],Thread info:{}", format,
                JsonUtil.format(ThreadUtil.getCurrentThreadMapForLog()));
    }
    Date beginDate = new Date();

    //***********************************************************

    Object returnValue = proceedingJoinPoint.proceed(args);

    //***********************************************************
    Date endDate = new Date();

    if (log.isInfoEnabled()) {
        log.info("end proceed:[{}],thread info:[{}],time:{},return:[{}]", format,
                JsonUtil.format(ThreadUtil.getCurrentThreadMapForLog()),
                DateExtensionUtil.getIntervalForView(beginDate, endDate), returnValue);
    }
    return returnValue;
}

From source file:com.github.kopylec.rapidjdbc.SQLAspect.java

@Around("target(repository) && execution(* *(..)) && @annotation(query)")
public Object executeSQLQuery(Repository repository, ProceedingJoinPoint joinPoint, Query query)
        throws Throwable {
    PreparedStatement statement = null;
    try {/*from   w  w  w  .  ja v a 2 s .c om*/
        statement = prepareStatement(query.value(), joinPoint.getArgs());
        LOGGER.debug("Executing SQL query \"{}\" with parameters {}", query.value(),
                Arrays.toString(joinPoint.getArgs()));
        repository.setResultSet(statement.executeQuery());
        return joinPoint.proceed();
    } catch (RapidJDBCException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RapidJDBCException("Error executing query \"" + query.value() + "\" with parameters "
                + Arrays.toString(joinPoint.getArgs()), ex);
    } finally {
        repository.closeResultSet();
        closeResources(statement);
    }
}

From source file:com.github.kopylec.rapidjdbc.SQLAspect.java

@Around("target(repository) && execution(* *(..)) && @annotation(update)")
public Object executeSQLUpdate(Repository repository, ProceedingJoinPoint joinPoint, Update update)
        throws Throwable {
    PreparedStatement statement = null;
    try {/* www . ja v  a 2  s  . co  m*/
        statement = prepareStatement(update.value(), joinPoint.getArgs());
        Object result = joinPoint.proceed();
        LOGGER.debug("Executing SQL update \"{}\" with parameters {}", update.value(),
                Arrays.toString(joinPoint.getArgs()));
        statement.executeUpdate();
        return result;
    } catch (RapidJDBCException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RapidJDBCException("Error executing update \"" + update.value() + "\" with parameters "
                + Arrays.toString(joinPoint.getArgs()), ex);
    } finally {
        closeResources(statement);
    }
}

From source file:com.goblingift.aspect.AspectManager.java

@Around(USERBEAN_METH_REF_TAKEOFF)
public double aroundTakeOff(ProceedingJoinPoint joinPoint) throws Throwable {

    if ((double) Arrays.asList(joinPoint.getArgs()).get(0) >= 25.00) {
        System.out.println("WARNING: User tried to take-off more than 25 bucks: " + joinPoint.getTarget());
        throw new IllegalStateException("THATS TOO MUCH!");
    }/*from   ww w .ja v a  2  s  .  co m*/
    return (double) joinPoint.proceed();
}

From source file:com.google.code.ssm.aop.counter.ReadCounterFromCacheAdvice.java

License:Open Source License

@Around("readSingleCounter()")
public Object readCounter(final ProceedingJoinPoint pjp) throws Throwable {
    if (isDisabled()) {
        getLogger().info("Cache disabled");
        return pjp.proceed();
    }//from   w  ww.  j ava 2s.co m

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    // It will be invoked only if underlying method completes successfully.
    String cacheKey = null;
    ReadCounterFromCache annotation;
    AnnotationData data;
    try {
        Method methodToCache = getCacheBase().getMethodToCache(pjp);
        verifyMethodSignature(methodToCache);
        annotation = methodToCache.getAnnotation(ReadCounterFromCache.class);
        data = AnnotationDataBuilder.buildAnnotationData(annotation, ReadCounterFromCache.class, methodToCache);
        cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(),
                methodToCache.toString());
        Long result = getCacheBase().getCache(data).getCounter(cacheKey);

        if (result != null) {
            getLogger().debug("Cache hit.");
            return convertResult(methodToCache, result);
        }
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
        return pjp.proceed();
    }

    final Object result = pjp.proceed();

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    try {
        if (checkData(result, pjp)) {
            long value = ((Number) result).longValue();
            // tricky way to update counter
            getCacheBase().getCache(data).incr(cacheKey, 0, value, annotation.expiration());
        }
    } catch (Exception ex) {
        warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey);
    }
    return result;
}

From source file:com.google.code.ssm.aop.InvalidateMultiCacheAdvice.java

License:Open Source License

@Around("invalidateMulti()")
public Object cacheInvalidateMulti(final ProceedingJoinPoint pjp) throws Throwable {
    if (isDisabled()) {
        getLogger().info("Cache disabled");
        return pjp.proceed();
    }/*from  ww  w .  jav  a  2 s .  co m*/

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    Collection<String> cacheKeys = null;
    final AnnotationData data;
    final Method methodToCache;
    try {
        methodToCache = getCacheBase().getMethodToCache(pjp);
        final InvalidateMultiCache annotation = methodToCache.getAnnotation(InvalidateMultiCache.class);
        data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateMultiCache.class, methodToCache);
        if (!data.isReturnKeyIndex()) {
            cacheKeys = getCacheBase().getCacheKeyBuilder().getCacheKeys(data, pjp.getArgs(),
                    methodToCache.toString());
        }
    } catch (Exception ex) {
        warn(ex, "Caching on method %s aborted due to an error.", pjp.toShortString());
        return pjp.proceed();
    }

    final Object result = pjp.proceed();

    // This is injected caching. If anything goes wrong in the caching, LOG
    // the crap outta it, but do not let it surface up past the AOP injection itself.
    try {
        // If we have a -1 key index, then build the cacheKeys now.
        if (data.isReturnKeyIndex()) {
            if (!getCacheBase().verifyTypeIsList(result.getClass())) {
                throw new InvalidAnnotationException(String.format(
                        "The return type is not a [%s]. "
                                + "The method [%s] does not fulfill the requirements.",
                        List.class.getName(), methodToCache.toString()));
            }

            @SuppressWarnings("unchecked")
            final List<Object> keyObjects = (List<Object>) result;
            cacheKeys = getCacheBase().getCacheKeyBuilder().getCacheKeys(keyObjects, data.getNamespace());
        }
        getCacheBase().getCache(data).delete(cacheKeys);
    } catch (Exception ex) {
        warn(ex, "Caching on method %s aborted due to an error.", pjp.toShortString());
    }
    return result;

}