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.haulmont.cuba.core.sys.PerformanceLogInterceptor.java

License:Apache License

@SuppressWarnings({ "UnusedDeclaration", "UnnecessaryLocalVariable" })
private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    StopWatch stopWatch = new Slf4JStopWatch(ctx.getSignature().toShortString());
    try {//from ww w  .  jav a2s  .c  om
        stopWatch.start();
        Object res = ctx.proceed();
        return res;
    } finally {
        stopWatch.stop();
    }
}

From source file:com.haulmont.cuba.core.sys.ServiceInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    SecurityContext securityContext = AppContext.getSecurityContextNN();
    boolean internalInvocation = securityContext.incServiceInvocation() > 0;
    try {//from  w  ww. j a  va2s  . c  o  m
        if (internalInvocation) {
            if (logInternalServiceInvocation) {
                log.warn("Invoking '{}' from another service", ctx.getSignature());
            }

            ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx);
            validateMethodParameters(ctx, validatedContext);

            Object res = ctx.proceed();

            validateMethodResult(ctx, validatedContext, res);

            return res;
        } else {
            statisticsAccumulator.incMiddlewareRequestsCount();
            try {
                // Using UserSessionsAPI directly to make sure the session's "last used" timestamp is propagated to the cluster
                UserSession userSession = userSessions.getAndRefresh(securityContext.getSessionId(), true);
                if (userSession == null) {
                    throw new NoUserSessionException(securityContext.getSessionId());
                }

                ValidateServiceMethodContext validatedContext = getValidateServiceMethodContext(ctx);
                validateMethodParameters(ctx, validatedContext);

                boolean checkTransactionOnExit = Stores.getAdditional().isEmpty()
                        && !persistence.isInTransaction();

                log.trace("Invoking: {}, session={}", ctx.getSignature(), userSession);

                Object res = ctx.proceed();

                validateMethodResult(ctx, validatedContext, res);

                if (checkTransactionOnExit && persistence.isInTransaction()) {
                    log.warn("Open transaction left in {}", ctx.getSignature().toShortString());
                }

                return res;
            } catch (Throwable e) {
                logException(e, ctx);
                // Propagate the special exception to avoid serialization errors on remote clients
                throw new RemoteException(e);
            }
        }
    } finally {
        securityContext.decServiceInvocation();
    }
}

From source file:com.haulmont.cuba.core.sys.TransactionalInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    Method method = ((MethodSignature) ctx.getSignature()).getMethod();
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, ctx.getTarget().getClass());
    Transactional transactional = specificMethod.getAnnotation(Transactional.class);
    if (transactional == null)
        throw new IllegalStateException("Cannot determine data store of the current transaction");

    String storeName = Strings.isNullOrEmpty(transactional.value()) ? Stores.MAIN : transactional.value();

    log.trace("Entering transactional method, store='{}'", storeName);

    ((PersistenceImpl) persistence).registerSynchronizations(storeName);

    return ctx.proceed();
}

From source file:com.haulmont.cuba.security.sys.AuthenticationInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    if (log.isTraceEnabled())
        log.trace("Authenticating: ", ctx.getSignature());

    try {/* w  w  w.  j av a  2 s . c  o  m*/
        authentication.begin();
        Object res = ctx.proceed();
        return res;
    } finally {
        authentication.end();
    }
}

From source file:com.haulmont.cuba.security.sys.TrustedServiceInterceptor.java

License:Apache License

protected Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    // check if remote access from trusted environment
    checkTrustedAccess(ctx);//  w ww . java 2 s .co  m

    return ctx.proceed();
}

From source file:com.heliosmi.portal.aspect.LoggingAspect.java

License:Apache License

@Around("allBeans()")
public Object profiler(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.nanoTime();
    String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
    log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs()));

    Object returnValue = null;/*from   w  ww. j  a  v  a2 s  .co m*/
    try {
        returnValue = pjp.proceed();
    } catch (Exception exception) {
        log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception)));
        log.error(ExceptionUtils.getStackTrace(exception));
        throw exception;
    }

    long end = System.nanoTime();
    log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. ");

    return returnValue;
}

From source file:com.helpinput.profaop.AspectProfiler.java

License:Apache License

@Around("notSelf() && notProfiler() && notAspectJ() && allMethods()")
public Object exeAround(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Monitor.startMonitor(signature.getMethod());
    Throwable error = null;//from   ww  w . j  a  v  a2  s  .  c om
    try {
        Object result = joinPoint.proceed();
        return result;
    } catch (Throwable e) {
        error = e;
        throw error;
    } finally {
        Monitor.stopMonitor(error);
    }
}

From source file:com.himanshu.um.impl.aop.performance.monitor.DBPerformanceMonitorAOP.java

License:Apache License

@Around("execution(@com.himanshu.um.api.performance.annotation.MonitorPerformance * *(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    long startTime = System.currentTimeMillis();
    /*LOG.debug("logAround() is running!");
    LOG.debug("hijacked method : " + joinPoint.getSignature().getName());
    LOG.debug("hijacked arguments : " + Arrays.toString(joinPoint.getArgs()));
    LOG.debug("Around before is running!");
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("Around after is running!");
    LOG.debug("******");*//*w w w .  j av  a 2s . c  o m*/
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("{}, {}, {}", new Object[] { joinPoint.getTarget().getClass().getName(),
            joinPoint.getSignature().getName(), System.currentTimeMillis() - startTime });
}

From source file:com.hipercube.springstudy.aspect.Ch13Aspect.java

License:Open Source License

@Around("runtimeCheck()")
public Object runtimeCheckAdvice(ProceedingJoinPoint joinPoint) {
    // Before/*  w  ww  .  j  a  v a  2  s .  co  m*/
    String signatureString = joinPoint.getSignature().toShortString();
    logger.info(signatureString + " Start");
    long start = System.nanoTime();
    Object result = null;

    // Method Execution
    try {
        result = joinPoint.proceed();
    } catch (Throwable ignored) {
    }

    // After
    long finish = System.nanoTime();
    logger.info(signatureString + " End");
    long runtime = finish - start;
    logger.info(signatureString + " Execution time: " + runtime + "ns");

    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    requestAttributes.setAttribute("runtime", runtime, RequestAttributes.SCOPE_REQUEST);

    return result;
}

From source file:com.hipercube.springstudy.aspect.Ch13Aspect.java

License:Open Source License

@Around("loginCheck()")
public Object loginCheckAdvice(ProceedingJoinPoint joinPoint) {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    String mid = (String) requestAttributes.getAttribute("sessionMid", RequestAttributes.SCOPE_SESSION);
    if (mid == null) {
        requestAttributes.setAttribute("loginNeed", "?? .",
                RequestAttributes.SCOPE_REQUEST);
        return "ch13/content";
    } else {//from   ww w  .jav a 2  s  .  c o  m
        Object result = null;
        try {
            result = joinPoint.proceed();
        } catch (Throwable ignored) {
        }
        return result;
    }
}