Example usage for org.aspectj.lang ProceedingJoinPoint proceed

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

Introduction

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

Prototype

public Object proceed(Object[] args) throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation.

Usage

From source file:com.betfair.cougar.core.impl.kpi.KPIAsyncTimer.java

License:Apache License

@Around("cougarAsyncMethod(event, observer)")
public Object measureAsyncMethod(final ProceedingJoinPoint pjp, KPIAsyncTimedEvent event,
        ExecutionObserver observer) throws Throwable {
    final String eventValue = event.value();
    final String eventOperation = event.operation();
    final String name = eventValue.isEmpty() ? pjp.getTarget().getClass().getSimpleName() : eventValue;
    final String operation = eventOperation.isEmpty() ? pjp.getSignature().getName() : eventOperation;

    final KPITimer timer = new KPITimer();
    timer.start();//from   w  ww. ja va2 s  . c o  m
    final PerformanceMonitoringExecutionObserver perfObserver = new PerformanceMonitoringExecutionObserver(
            observer, monitor, timer, event.catchFailures(), name, operation);

    return pjp.proceed(replaceObserver(perfObserver, pjp.getArgs()));
}

From source file:com.datastax.hectorjpa.spring.ConsistencyLevelAspect.java

License:Open Source License

/**
 * Validates any method that has the valid annotation on it and is wired as
 * a spring service//w w  w . ja v a  2s.c o  m
 * 
 * @param jp
 * @throws Throwable
 */
@Around("@annotation(com.datastax.hectorjpa.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

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

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

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

    stack.push(level);
    JPAConsistency.set(level);

    Object result = null;

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

        if (stack.size() > 0) {
            JPAConsistency.set(stack.peek());
        } else {
            JPAConsistency.remove();
        }

    }

    return result;
}

From source file:com.denimgroup.threadfix.service.eventmodel.aspect.SubmitDefectAspect.java

License:Mozilla Public License

@Around("execution(* com.denimgroup.threadfix.service.DefectSubmissionServiceImpl.submitDefect(..))")
public Object emitEvent(ProceedingJoinPoint joinPoint) throws Throwable {
    LOG.debug("Emitting getProjectMetadata event.");

    Object[] args = joinPoint.getArgs();
    assert args.length == 3 : "Length of join point arguments wasn't 3: " + Arrays.toString(args);

    AbstractDefectTracker tracker = getAs(args[0], AbstractDefectTracker.class);
    List vulns = getAs(args[1], List.class);
    DefectMetadata metadata = getAs(args[2], DefectMetadata.class);

    eventPublisher.publishEvent(new PreDefectSubmissionEvent(tracker, vulns, metadata));

    return joinPoint.proceed(new Object[] { tracker, vulns, metadata });
}

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

License:Apache License

/**
 * Proceed.//ww  w .j  a  v a 2  s .c o  m
 *
 * @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.gxl.kratos.core.shard.SQLExecute.java

License:Apache License

/**
 * ??,?/*from   www.  j  a va 2s.  co  m*/
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param indexType
 *            truemaster?,falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
protected Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean indexType) {
    long befor = System.currentTimeMillis();
    Object obj = null;
    if (null != proceedingJoinPoint) {
        Object[] params = proceedingJoinPoint.getArgs();
        if (0 > params.length)
            return obj;
        Object param = params[0];
        /*
         * org.springframework.jdbc.core.JdbcTemplateupdate*()query*()
         * ?SQL
         */
        if (param instanceof String) {
            String sql = param.toString();
            logger.info("sharding?SQL-->" + sql);
            if (kJdbcTemplate.getIsShard()) {
                if (kJdbcTemplate.getShardMode()) {
                    params = route.dbRouteByOne(sql, params, indexType);
                } else {
                    params = route.dbRouteByMany(sql, params, indexType);
                }
                sql = params[0].toString();
                logger.info("sharding?SQL-->" + sql);
            } else {
                /* ?master/slave??? */
                final int INDEX = ResolveRWWeight.getIndex(kJdbcTemplate.getWr_weight(), indexType);
                setDataSource.setIndex(INDEX);
            }
        }
        try {
            obj = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return obj;
}

From source file:com.gxl.kratos.jdbc.core.SwitchDataSource.java

License:Apache License

/**
 * ???//  ww w  .j  a  v a 2 s  .  c o  m
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param operation
 *            truemaster?falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
public Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean operation) {
    long befor = System.currentTimeMillis();
    Object result = null;
    /* ?? */
    Object[] params = proceedingJoinPoint.getArgs();
    Object param = params[0];
    if (param.getClass() == String.class) {
        final String SQL = (String) param;
        logger.info("??sql-->" + SQL);
        /* ??? */
        if (kJdbcTemplate.getIsShard()) {
            /* ? */
            if (kJdbcTemplate.getShardMode()) {
                /* ? */
                logger.debug("??");
                params = oneTbshard(SQL, params, operation).toArray();
            } else {
                /* ? */
                logger.debug("??");
                params = manyTbshard(SQL, params, operation).toArray();
            }
            String NEW_SQL = params[0].toString();
            logger.info("sharding??sql-->" + NEW_SQL);
        } else {
            /* ?/ */
            int index = WeightResolver.getIndex(kJdbcTemplate.getWr_weight(), operation);
            /* ???master */
            setRoutingIndex(index);
        }
        try {
            /*  */
            result = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return result;
}

From source file:com.gxl.shark.core.shard.SQLExecute.java

License:Apache License

/**
 * ??,?/*ww w  .  ja  v a  2  s . c  o  m*/
 * 
 * @author gaoxianglong
 * 
 * @param proceedingJoinPoint
 *            ?
 * 
 * @param indexType
 *            truemaster?,falseslave?
 * 
 * @exception Throwable
 * 
 * @return Object
 */
protected Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean indexType) {
    long befor = System.currentTimeMillis();
    Object obj = null;
    if (null != proceedingJoinPoint) {
        Object[] params = proceedingJoinPoint.getArgs();
        if (0 > params.length)
            return obj;
        Object param = params[0];
        /*
         * org.springframework.jdbc.core.JdbcTemplateupdate*()query*()
         * ?SQL
         */
        if (param instanceof String) {
            String sql = param.toString();
            logger.info("sharding?SQL-->" + sql);
            if (jdbcTemplate.getIsShard()) {
                if (jdbcTemplate.getShardMode()) {
                    params = route.dbRouteByOne(sql, params, indexType);
                } else {
                    params = route.dbRouteByMany(sql, params, indexType);
                }
                sql = params[0].toString();
                logger.info("sharding?SQL-->" + sql);
            } else {
                /* ?master/slave??? */
                final int INDEX = ResolveRWIndex.getIndex(jdbcTemplate.getWr_index(), indexType);
                setDataSource.setIndex(INDEX);
            }
        }
        try {
            obj = proceedingJoinPoint.proceed(params);
            logger.debug("->" + (System.currentTimeMillis() - befor) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return obj;
}

From source file:com.invariantproperties.project.student.webservice.security.RestParameterChecker.java

License:Apache License

/**
 * Check that the UUID is well-formed in CRUD REST service calls.
 * //from w ww .  ja  v a  2  s . c  o  m
 * @param pjp
 * @param uuid
 * @return
 * @throws Throwable
 */
@Around("target(com.invariantproperties.project.student.webservice.server.rest.AbstractResource) && args(uuid,..) && (execution(* *.create*(..)) || execution(* *.delete*(..)) || execution(* *.update*(..)) || execution(* *.get*(..)))")
public Object checkUuid(ProceedingJoinPoint pjp, String uuid) throws Throwable {
    final Object[] args = pjp.getArgs();
    Object results = null;

    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("checking for bad UUID: %s(%s)...", pjp.getSignature().getName(), uuid));
    }

    if (!StudentUtil.isPossibleUuid(uuid)) {
        results = Response.status(Status.BAD_REQUEST).build();
        LOG.info(pjp.getSignature().getName() + ": attempt to use malformed UUID");
    } else {
        results = pjp.proceed(args);
    }

    return results;
}

From source file:com.invariantproperties.project.student.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on create method./*from  w w w  . j  a  v a  2  s.c om*/
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.invariantproperties.project.student.webservice.server.rest.AbstractResource) && args(rto,..)")
public Object checkParametersCreate(ProceedingJoinPoint pjp, Validatable rto) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());
    final String name = pjp.getSignature().getName();
    Object results = null;

    if (rto.validate()) {
        // this should be safe since parameters have been validated.
        if (log.isDebugEnabled()) {
            log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs())));
        }
        results = pjp.proceed(pjp.getArgs());
    } else {
        // FIXME: this is unsafe
        if (log.isInfoEnabled()) {
            log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs())));
        }
        // TODO: tell caller what the problems were
        results = Response.status(Status.BAD_REQUEST).build();
    }

    return results;
}

From source file:com.invariantproperties.project.student.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on update method.//  w w  w .  j a v a 2 s . co m
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.invariantproperties.project.student.webservice.server.rest.AbstractResource) && args(uuid,rto,..)")
public Object checkParametersUpdate(ProceedingJoinPoint pjp, String uuid, Validatable rto) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());
    final String name = pjp.getSignature().getName();
    Object results = null;

    if (!StudentUtil.isPossibleUuid(uuid)) {
        // this is a possible attack.
        if (log.isInfoEnabled()) {
            log.info(String.format("%s(): uuid", name));
        }
        results = Response.status(Status.BAD_REQUEST).build();
    } else if (rto.validate()) {
        // this should be safe since parameters have been validated.
        if (log.isDebugEnabled()) {
            log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs())));
        }
        results = pjp.proceed(pjp.getArgs());
    } else {
        // FIXME: this is unsafe
        if (log.isInfoEnabled()) {
            log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs())));
        }
        // TODO: tell caller what the problems were
        results = Response.status(Status.BAD_REQUEST).build();
    }

    return results;
}