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() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:com.facio.test.aspect.LogginAspect.java

@Around("execution(public * com.facio.test.service.IMyDummyComponent.getValue(..))")
public Object methodsGenericsLogging(final ProceedingJoinPoint joinPoint) throws Throwable {
    LOG.info("begin methodsGenericsLogging()");
    Object result = null;// w w w.  j av a2 s .co m

    try {
        LOG.debug("begin INTERCEPTED method=" + joinPoint.getSignature());
        result = joinPoint.proceed();
    } finally {
        LOG.debug("end INTERCEPTED method=" + joinPoint.getSignature());
    }

    return result;
}

From source file:com.facultyshowcase.app.model.helpers.TransactionAspect.java

License:Open Source License

@Around("daoMethod() && @annotation(withTransaction)")
public Object wrapWithTransaction(ProceedingJoinPoint pjp, WithTransaction withTransaction) throws Throwable {
    _logger.trace("wrapWithTransaction()");
    DAOHelper dao = (DAOHelper) pjp.getTarget();

    try {//from  w  w w .  j a v a  2 s  .  c  o  m

        beginTransaction.invoke(dao);

        Object ret = pjp.proceed();

        commitTransaction.invoke(dao);
        return ret;
    } catch (Throwable e) {
        try {
            rollbackTransaction.invoke(dao);
        } catch (Throwable e2) {
            e.addSuppressed(e2);
        }
        throw e;
    }
}

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

License:Apache License

/**
 * Around./*  ww  w  . j  av  a2 s. c o  m*/
 * 
 * @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.feiyangedu.springcloud.petstore.common.config.CustomWebConfiguration.java

License:Apache License

/**
 * Convert HystrixBadRequestException to APIException using AspectJ.
 */// ww  w  .  ja v  a2 s. co  m
@Around("execution(* com..*FeignClient.*(..))")
public Object processFeignClientResult(ProceedingJoinPoint pjp) throws Throwable {
    log.info("Invoke feign client...");
    try {
        return pjp.proceed();
    } catch (HystrixBadRequestException e) {
        Throwable t = e.getCause();
        if (t instanceof APIException) {
            log.warn("Convert HystrixBadRequestException to APIException.");
            throw t;
        }
        log.warn("HystrixBadRequestException", e);
        throw e;
    } catch (Exception e) {
        log.warn(e.getClass(), e);
        throw e;
    }
}

From source file:com.forsrc.aop.LogTracing.java

License:Apache License

/**
 * Do around object./* w ww .j av  a2 s .c  o m*/
 *
 * @param proceedingJoinPoint the proceeding join point
 * @return the object
 * @throws Throwable the throwable
 */
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    long ms = System.currentTimeMillis();
    long time = System.nanoTime();
    Object retVal = proceedingJoinPoint.proceed();
    time = System.nanoTime() - time;
    ms = System.currentTimeMillis() - ms;
    StringBuilder msg = new StringBuilder("[TIME]  method: ")
            .append(proceedingJoinPoint.getSignature().getName()).append("() -> ")
            .append(new Double(1.0d * time / (1000000000d)).toString()).append(" s (").append(ms)
            .append(" ms) --> ").append(proceedingJoinPoint.getTarget().getClass());
    this.appendMessage(msg);
    LOGGER.info(msg);

    return retVal;
}

From source file:com.genyherrera.performancelog.aspect.PerformanceLogAspect.java

License:Apache License

@Around("performanceMethod()")
public Object logPerformanceStats(ProceedingJoinPoint joinpoint) {
    try {//  ww w . j a va 2 s  . c  o m
        PerfLog perfLog = retrievePerfLogAnnotation(joinpoint);
        Long start = null;
        Long end = null;
        Object result = null;

        switch (perfLog.timeStyle()) {
        case NANO_SECONDS:
            start = System.nanoTime();
            result = joinpoint.proceed();
            end = System.nanoTime();
            break;
        case MILI_SECONDS:
            start = System.currentTimeMillis();
            result = joinpoint.proceed();
            end = System.currentTimeMillis();
            break;
        case SECONDS:
            start = System.currentTimeMillis() / 1000;
            result = joinpoint.proceed();
            end = System.currentTimeMillis() / 1000;
            break;
        default:
            start = System.currentTimeMillis();
            result = joinpoint.proceed();
            end = System.currentTimeMillis();
            break;
        }

        switch (perfLog.severity()) {
        case DEBUG:
            logger.debug(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case INFO:
            logger.info(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case WARN:
            logger.warn(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        case ERROR:
            logger.error(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        default:
            logger.debug(String.format("%s took %d " + perfLog.timeStyle().toString(),
                    joinpoint.getSignature().toShortString(), (end - start)));
            break;
        }
        return result;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ghewareunigps.vts.ui.web.signup.Signup.java

@Around("execution(* com.ghewareunigps.vts.ui.web.controllers.SignupController.signup(..)) && args(user,..)")
public Message validateAndSignup(ProceedingJoinPoint joinPoint, User user) throws Throwable {
    user.setRole(User.ROLE_USER);/*  w w  w .  ja va2  s  .c o m*/
    if (dataValidation.validate(user.getUsername(), user.getEmail(), user.getPassword())) {
        if (repository.findByEmailOrUsername(user).isEmpty()) {
            message = (Message) joinPoint.proceed();
            boolean isSaved = repository.save(user);
        } else {
            message = new Message(false, "The user already exists");
        }
    } else {
        message = new Message(false, " please recheck your credentials");
    }

    return message;
}

From source file:com.github.akutschera.maven.plugin.skiptest.aspect.SkipAspect.java

License:Apache License

@Around("execution(public * *.*IT.*(..)) && annotatedWithTest(ann)")
public void aroundJUnitTestCaseMethods(ProceedingJoinPoint pjp, Test ann) throws Throwable {
    int isTestSuccessful = 0;

    if (shouldTestBeSkipped(pjp)) {
        return;//w w  w  .ja v a2 s.c om
    }
    try {
        pjp.proceed();
        if (ann.expected() == Test.None.class) {
            isTestSuccessful = 1;
        }
    } catch (Throwable throwable) {
        Class<? extends Throwable> expectedException = ann.expected();
        if (expectedException.isAssignableFrom(throwable.getClass())) {
            isTestSuccessful = 1;
        } else {
            throw throwable;
        }
    } finally {
        appendTestresultToOutputFile(getNameOfTestFrom(pjp), isTestSuccessful);
    }
}

From source file:com.github.eemmiirr.redisdata.signalizer.RedisDataSignalizerAspect.java

License:LGPL

@Around("redisTransactionalPointcut()")
public Object redisTransactionalAroundAdvice(ProceedingJoinPoint pjp) throws Throwable {

    // Retrieve the RedisData annotation from either the Type or the Method
    // If both are present the Method will override the Type annotation
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    final Method method = pjp.getTarget().getClass().getMethod(methodSignature.getName(),
            methodSignature.getParameterTypes());
    final RedisData redisData = retrieveRedisTransactionalAnnotation(method);

    try {/*  ww w.  j a va2s  . c  o  m*/
        redisTransactionalBeforeAdvice(redisData);
        final Object returnValue = pjp.proceed();
        redisTransactionalAfterAdvice(redisData);
        return returnValue;
    } catch (Throwable t) {
        redisTransactionalAfterThrowing(t, redisData);
        throw t;
    }
}

From source file:com.github.inspektr.audit.AuditTrailManagementAspect.java

License:Apache License

@Around(value = "@annotation(audits)", argNames = "audits")
public Object handleAuditTrail(final ProceedingJoinPoint joinPoint, final Audits audits) throws Throwable {
    Object retVal = null;//w  w  w . ja va  2 s.co  m
    String currentPrincipal = null;
    final String[] actions = new String[audits.value().length];
    final String[][] auditableResources = new String[audits.value().length][];
    try {
        retVal = joinPoint.proceed();
        currentPrincipal = this.auditPrincipalResolver.resolveFrom(joinPoint, retVal);

        if (currentPrincipal != null) {
            for (int i = 0; i < audits.value().length; i++) {
                final AuditActionResolver auditActionResolver = this.auditActionResolvers
                        .get(audits.value()[i].actionResolverName());
                final AuditResourceResolver auditResourceResolver = this.auditResourceResolvers
                        .get(audits.value()[i].resourceResolverName());
                auditableResources[i] = auditResourceResolver.resolveFrom(joinPoint, retVal);
                actions[i] = auditActionResolver.resolveFrom(joinPoint, retVal, audits.value()[i]);
            }
        }
        return retVal;
    } catch (final Exception e) {
        currentPrincipal = this.auditPrincipalResolver.resolveFrom(joinPoint, e);

        if (currentPrincipal != null) {
            for (int i = 0; i < audits.value().length; i++) {
                auditableResources[i] = this.auditResourceResolvers
                        .get(audits.value()[i].resourceResolverName()).resolveFrom(joinPoint, e);
                actions[i] = auditActionResolvers.get(audits.value()[i].actionResolverName())
                        .resolveFrom(joinPoint, e, audits.value()[i]);
            }
        }
        throw e;
    } finally {
        for (int i = 0; i < audits.value().length; i++) {
            executeAuditCode(currentPrincipal, auditableResources[i], joinPoint, retVal, actions[i],
                    audits.value()[i]);
        }
    }
}