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.wuxiansen.beehive.core.security.SecurityAspect.java

License:Open Source License

public Object execute(ProceedingJoinPoint pjp) throws Throwable {
    // ?/*from   w  w w .  j  av  a  2 s .co m*/
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();
    // 
    if (method.isAnnotationPresent(IgnoreSecurity.class)) {
        return pjp.proceed();
    }

    //  request header ?? token
    String token = WebContext.getRequest().getHeader(tokenName);
    //  token 
    if (!tokenManager.checkToken(token)) {
        String message = String.format("token [%s] is invalid", token);
        throw new TokenException(message);
    }
    // 
    return pjp.proceed();
}

From source file:com.yoho.core.trace.instrument.async.TraceAsyncAspect.java

License:Apache License

@Around("execution (@org.springframework.scheduling.annotation.Async  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
    Span span = this.tracer.createSpan(pjp.getSignature().getName());
    this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT);
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(),
            pjp.getTarget().getClass().getSimpleName());
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(),
            pjp.getSignature().getName());
    try {/*  ww w. ja  va2 s .com*/
        return pjp.proceed();
    } finally {
        this.tracer.close(span);
    }
}

From source file:com.yoho.core.trace.instrument.scheduling.TraceSchedulingAspect.java

License:Apache License

@Around("execution (@org.springframework.scheduling.annotation.Scheduled  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
    String spanName = pjp.getSignature().getName();
    Span span = this.tracer.createSpan(spanName);
    this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, SCHEDULED_COMPONENT);
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(),
            pjp.getTarget().getClass().getSimpleName());
    this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(),
            pjp.getSignature().getName());
    try {//from w ww  . j  a va2s . c  om
        return pjp.proceed();
    } finally {
        this.tracer.close(span);
    }
}

From source file:com.young.license.client.advice.LicenseAdvice.java

public Object checkLicense(ProceedingJoinPoint pj) throws Throwable {
    /**/*from www .j  a  v a 2  s  . com*/
     * ?license,?proceed,??
     */
    if (!LicenseTool.verify()) {
        System.out.println("License is expired ....redirect to [" + "redirect:" + Config.getExpirePage() + "]");
        return new ModelAndView("redirect:" + Config.getExpirePage());
    }
    return pj.proceed();
}

From source file:com.yunmel.syncretic.ds.DataSourceAspect.java

License:Apache License

@Around("@annotation(dataSourceChange)")
public Object doAround(ProceedingJoinPoint pjp, DataSourceChange dataSourceChange) {
    Object retVal = null;//from  ww  w  .  j a v a2s  . com
    boolean selectedDataSource = false;
    try {
        if (null != dataSourceChange) {
            selectedDataSource = true;
            if (dataSourceChange.slave()) {
                DynamicDataSource.useSlave();
            } else {
                DynamicDataSource.useMaster();
            }
        }
        retVal = pjp.proceed();
    } catch (Throwable e) {
        LOGGER.warn("???", e);
        throw new DataSourceAspectException("???", e);
    } finally {
        if (selectedDataSource) {
            DynamicDataSource.reset();
        }
    }
    return retVal;
}

From source file:com.zh.snmp.snmpcore.aop.ExceptionInterceptor.java

License:Open Source License

/**
 * Try-catch blokkba csomagolja a service rteg hivsait.
 * <p/>//from ww  w.ja v  a2s .  c  o m
 * A catch gakban kezeljk a kivteleket. Lsd az osztly szint kommentet.
 * Szksg esetn j kivtel tpusokkal bvthet.
 *
 * @param pjp
 * @return
 * @throws Throwable
 */
public Object invokeAround(ProceedingJoinPoint pjp) throws Throwable {

    Object returnValue = null;
    try {
        //service method invocation
        returnValue = pjp.proceed();
    } catch (javax.persistence.OptimisticLockException ex) {
        throw new JpaVersionException(ex);
    } catch (ApplicationException appEx) {
        addIdLogAndThrow(appEx, pjp);
    } catch (SystemException sysEx) {
        addIdLogAndThrow(sysEx, pjp);
    } catch (RemoteException remoteEx) {
        addIdLogAndThrow(new RmiException(ExceptionCodesEnum.RemoteException, remoteEx), pjp);
    } catch (PersistenceException perEx) {
        addIdLogAndThrow(new DaoException(ExceptionCodesEnum.PersistenceException, perEx), pjp);
    } catch (SQLException sqlEx) {
        addIdLogAndThrow(new DaoException(ExceptionCodesEnum.SQLException, sqlEx), pjp);
    } catch (JpaVersionException jpaEx) {
        //FIXME: for cserepj
        throw jpaEx;
    } catch (Throwable ex) {
        addIdLogAndThrow(new SystemException(ExceptionCodesEnum.UnknownExceptionType, ex), pjp);
    }
    return returnValue;
}

From source file:com.zh.snmp.snmpcore.aop.TraceInterceptor.java

License:Open Source License

/**
 * Logozast vegrehajto metodus./*from www .  j a va  2  s.co m*/
 * Naplozza a hivast, folytatja a megszakitott hivast,
 * majd naplozza a kilepest, a visszateresi erteket, es
 * az esetleges kiveteleket, valamint a futas idejet.
 * <p/>
 * Ha kivetel dobas tortent, azt minden esetben tovabbdobja.
 *
 * @param pjp
 * @return
 * @throws Throwable
 */
public Object invokeAround(ProceedingJoinPoint pjp) throws Throwable {
    final String target = getInvocationTarget(pjp, useSimpleClassName);
    if (LOG.isTraceEnabled()) {
        LOG.trace(appendEnteringMsg(target, pjp));
    }

    final long startTime = System.currentTimeMillis();
    try {
        final Object returnValue = pjp.proceed();
        if (LOG.isTraceEnabled()) {
            LOG.trace(appendExitingMsg(target, returnValue));
        }
        return returnValue;

    } catch (Throwable ex) {
        if (LOG.isTraceEnabled()) {
            LOG.trace(appendExceptionMsg(target));
        }
        throw ex;

    } finally {
        final long stopTime = System.currentTimeMillis();
        if (LOG.isTraceEnabled()) {
            LOG.trace(appendPerformanceMsg(startTime, stopTime, target));
        }
    }
}

From source file:com.zoltran.perf.aspect.PerformanceMonitorAspect.java

License:Open Source License

@Around(value = "execution(@com.zoltran.perf.aspect.PerformanceMonitor * *(..)) && @annotation(annot)", argNames = "pjp,annot")
public Object performanceMonitoredMethod(ProceedingJoinPoint pjp, PerformanceMonitor annot) throws Throwable {
    final long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    final long elapsed = System.currentTimeMillis() - start;
    MeasurementRecorderSource mrs = mrecSources.getUnchecked(annot.recorderSource());
    mrs.getRecorder(pjp.toLongString()).record(elapsed);
    if (elapsed > annot.warnThresholdMillis()) {
        if (elapsed > annot.errorThresholdMillis()) {
            LOG.error("Execution time  {} ms for {} exceeds error threshold of {} ms, arguments {}",
                    new Object[] { elapsed, pjp.toShortString(), annot.errorThresholdMillis(), pjp.getArgs() });
        } else {/*from   w  w  w  .java2s .  c om*/
            LOG.warn("Execution time  {} ms for {} exceeds warning threshold of {} ms, arguments {}",
                    new Object[] { elapsed, pjp.toShortString(), annot.warnThresholdMillis(), pjp.getArgs() });
        }
    } else {
        LOG.debug("Execution time {} ms for {}, arguments {}",
                new Object[] { elapsed, pjp.toShortString(), pjp.getArgs() });
    }
    return result;
}

From source file:com.zte.spring.service.LogService.java

@Around("methodCachePointcut()")
public Object around(ProceedingJoinPoint point) throws Throwable {

    Object result = null;/*from   ww w.  j a va2 s .c o  m*/
    String methodName = point.getSignature().getName();

    // ?
    if (methodName.equals("login")) {
        result = point.proceed();
    }

    if (logMethodsMap.containsKey(methodName)) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();
        String loginName = (String) request.getSession().getAttribute("userid");
        String roleName = (String) request.getSession().getAttribute("uname");
        String clientIP = (String) request.getSession().getAttribute("clientIP");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Calendar ca = Calendar.getInstance();
        String operDate = df.format(ca.getTime());
        StringBuffer operDetail = new StringBuffer();
        operDetail.append(roleName).append(loginName).append("(").append(clientIP).append(")");
        Object[] method_param = point.getArgs(); // ??

        // ????
        if (!methodName.equals("addUser") && !methodName.equals("saveNews")
                && !methodName.equals("saveOrUpdateRole") && !methodName.equals("saveOrUpdateParam")
                && !methodName.equals("updateParam")) {
            operDetail.append(logMethodsMap.get(methodName));
        }
        operDetail.append(getOperContent(method_param, methodName));
        SysLog log = new SysLog();
        log.setType("oper");
        log.setCreatime(operDate);
        log.setUname(loginName);
        log.setUid("");
        log.setOper(logMethodsMap.get(methodName));
        log.setContent(operDetail.toString());
        logger.info(log.getContent());
        logService.saveLog(log);
    }

    if (!methodName.equals("login")) {
        result = point.proceed();
    }

    return result;
}

From source file:com.zxy.commons.profiler.connector.PrintProfilerAspect.java

License:Apache License

/**
 * Around advice/*from  w ww. jav  a2  s. c o m*/
 * @param pjp ProceedingJoinPoint
 * @return Object
 * @throws Throwable Throwable
*/
@Around("pointcut()")
public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
    String methodFullName = "unkonwMethod()";
    int monitorTime = 500;
    try {
        Method method = JoinPoinUtil.getMethod(pjp);
        methodFullName = JoinPoinUtil.createMethodFullName(method);
        monitorTime = PrintProfilerHelper.getElapseTimeIfNull(method, monitorTime);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    try {
        Profiler.start(methodFullName, monitorTime);
        return pjp.proceed();
    } finally {
        Profiler.stop();
    }
}