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.ace.erp.extra.aop.UserCacheAspect.java

@Around(value = "userServicePointcut() && cacheablePointcut()")
public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable {

    String methodName = pjp.getSignature().getName();
    Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null;

    String key = "";
    boolean isIdKey = false;
    if ("getUserById".equals(methodName)) {
        key = idKey(String.valueOf(arg));
        isIdKey = true;//from w w w .j  ava 2 s . c  om
    } else if ("getUserByName".equals(methodName)) {
        key = usernameKey((String) arg);
    } else if ("getUserByEmail".equals(methodName)) {
        key = emailKey((String) arg);
    } else if ("getUserByMobilePhoneNumber".equals(methodName)) {
        key = mobilePhoneNumberKey((String) arg);
    }

    User user = null;
    if (isIdKey == true) {
        user = get(key);
    } else {
        Integer id = get(key);
        if (id != null) {
            key = idKey(String.valueOf(id));
            user = get(key);
        }
    }
    //cache hit
    if (user != null) {
        log.debug("cacheName:{}, hit key:{}", cacheName, key);
        return user;
    }
    log.debug("cacheName:{}, miss key:{}", cacheName, key);

    //cache miss
    user = (User) pjp.proceed();

    //put cache
    put(user);
    return user;

}

From source file:com.alibaba.china.plugin.cache.spring.aop.CacheAopSupport.java

License:Open Source License

private Object retriveKey(ProceedingJoinPoint joinPoint) {
    Method method = (Method) joinPoint.getTarget();
    method.getAnnotation(VersionedBy.class);

    Object[] args = joinPoint.getArgs();

    if (args == null || args.length == 0) {
        return null;
    }//from   w w w .  j av  a2s.  co  m

    Annotation[][] paramAnnotations = method.getParameterAnnotations();

    List<Object> keyList = new ArrayList<Object>();

    for (Annotation[] annos : paramAnnotations) {
        for (Annotation a : annos) {
            if (a instanceof Key) {
                Key keyAnno = (Key) a;
                int index = keyAnno.value();
                if (index >= 0 && index < args.length) {
                    keyList.add(args[index]);
                }
            }
        }
    }

    if (keyList.size() == 0) {
        return null;
    } else if (keyList.size() == 1) {
        return keyList.get(0);
    }
    return keyList.toArray();
}

From source file:com.alibaba.china.plugin.cache.spring.aop.CacheAopSupport.java

License:Open Source License

private Object retriveValue(ProceedingJoinPoint joinPoint) {
    Method method = (Method) joinPoint.getTarget();
    method.getAnnotation(VersionedBy.class);

    Object[] args = joinPoint.getArgs();

    if (args == null || args.length == 0) {
        return null;
    }/*from   ww w  .j  a v a 2 s. co m*/

    Annotation[][] paramAnnotations = method.getParameterAnnotations();

    List<Object> valueList = new ArrayList<Object>();

    for (Annotation[] annos : paramAnnotations) {
        for (Annotation a : annos) {
            if (a instanceof Value) {
                Value valueAnno = (Value) a;
                int index = valueAnno.value();
                if (index >= 0 && index < args.length) {
                    valueList.add(args[index]);
                }
            }
        }
    }

    if (valueList.size() == 0) {
        return null;
    } else if (valueList.size() == 1) {
        return valueList.get(0);
    }
    return valueList.toArray();

}

From source file:com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Around("call(@com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous * *(..)) && @annotation(asynchronousAnnotation)")
public Object makeAsynchronous(ProceedingJoinPoint pjp, Asynchronous asynchronousAnnotation) throws Throwable {
    final Signature signature = pjp.getStaticPart().getSignature();
    if (signature instanceof MethodSignature) {
        final MethodSignature methodSignature = (MethodSignature) signature;
        int i = 0;
        Object[] methodArguments = pjp.getArgs();
        Annotation[][] parameterAnnotations = methodSignature.getMethod().getParameterAnnotations();
        List<Promise> valueParams = new ArrayList<Promise>();
        for (final Class<?> parameterType : methodSignature.getParameterTypes()) {
            if ((isPromise(parameterType) || isPromiseArray(parameterType)
                    || (isCollection(parameterType) && hasWaitAnnotation(parameterAnnotations[i])))
                    && !hasNoWaitAnnotation(parameterAnnotations[i])) {
                Object param = methodArguments[i];
                if (isPromise(parameterType)) {
                    valueParams.add((Promise) param);
                } else if (isCollection(parameterType)) {
                    valueParams.add(new AndPromise((Collection) param));
                } else {
                    valueParams.add(new AndPromise((Promise[]) param));
                }/*from  w  w w  .j a  va  2 s .  c o  m*/
            } else {
                valueParams.add(null);
            }
            i++;
        }

        Promise[] values = valueParams.toArray(new Promise[0]);
        Boolean daemon = asynchronousAnnotation.daemon() ? true : null;
        AsynchronousAspectTask task = new AsynchronousAspectTask(daemon, pjp, values);
        return task.getReturnValue();
    }

    return pjp.proceed();
}

From source file:com.baomidou.framework.aop.ResubmitAspect.java

License:Apache License

/**
 * <p>//from   w w  w  .  j av a 2s.  co  m
 * ?
 * </p>
 * 
 * @param joinPoint
 *            ?
 * @param formToken
 *            ??
 * @throws Throwable
 */
@Around("@annotation(formToken)")
public void execute(ProceedingJoinPoint joinPoint, FormToken formToken) throws Throwable {
    Object[] args = joinPoint.getArgs();
    String className = joinPoint.getTarget().getClass().getName();
    for (Object arg : args) {
        if (arg != null && arg instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) arg;
            HttpSession session = request.getSession(true);
            if (formToken != null) {
                if ("GET".equalsIgnoreCase(request.getMethod())) {
                    /* GET ? token */
                    this.generate(joinPoint, request, session, PARAM_TOKEN_FLAG + className);
                } else {
                    /* POST ? token */
                    this.validation(joinPoint, request, session, PARAM_TOKEN_FLAG + className);
                }
            }
        }
    }
}

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 ww  w.j av a  2  s .  c om*/
    final PerformanceMonitoringExecutionObserver perfObserver = new PerformanceMonitoringExecutionObserver(
            observer, monitor, timer, event.catchFailures(), name, operation);

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

From source file:com.boyuanitsm.fort.aop.logging.LoggingAspect.java

License:Apache License

@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }/*from ww  w.  j  a  v  a  2  s  . co m*/
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspect.java

License:Apache License

private Object processMethodFailure(final ProceedingJoinPoint proceedingJoinPoint,
        final String[] exceptionHandlerNames, final Throwable thrownException) throws Throwable {
    final Method handlerMethod = getHandlerMethod(proceedingJoinPoint, thrownException.getClass(),
            exceptionHandlerNames);//from  w  ww . jav  a 2 s .  c om
    if (handlerMethod != null) {
        logger.trace("Selected handlerMethod : " + handlerMethod.getName());
        try {
            return handlerMethod.invoke(proceedingJoinPoint.getThis(),
                    getExceptionHandlerArgs(thrownException, proceedingJoinPoint.getArgs()));
        } catch (final InvocationTargetException invocationTargetException) {
            throw invocationTargetException.getCause(); // exception thrown by handler method
        }
    } else {
        throw thrownException;
    }
}

From source file:com.clicktravel.cheddar.application.retry.RetryableAspectTest.java

License:Apache License

@Test
public void shouldAttemptMethodAndCallExceptionHandler_withExceptionThrownAndExceptionHandlerNamed()
        throws Throwable {
    // Given/*from  ww  w.ja  v  a2s.c  o  m*/
    final RetryableAspect retryableAspect = new RetryableAspect();
    final ProceedingJoinPoint mockProceedingJoinPoint = setupSimpleProceedingJoinPointMock();
    final Retryable mockRetryable = setupSimpleRetryableMock();
    final RetryExceptionHandler retryExceptionHandler = new RetryExceptionHandler();
    final MethodSignature mockMethodSignature = mock(MethodSignature.class);
    final String exceptionHandlerName = "joinPointMethodExceptionHandlingMethod";

    RetryableConfiguration.setRetryableEnabled(false);
    when(mockProceedingJoinPoint.proceed()).thenThrow(new RetryAspectTestException());
    when(mockProceedingJoinPoint.getThis()).thenReturn(retryExceptionHandler);
    when(mockProceedingJoinPoint.getSignature()).thenReturn(mockMethodSignature);
    when(mockProceedingJoinPoint.getArgs()).thenReturn(new Object[] { "exampleArgument" });
    when(mockMethodSignature.getParameterTypes()).thenReturn(
            RetryExceptionHandler.class.getDeclaredMethod("joinPointMethod", String.class).getParameterTypes());
    when(mockRetryable.exceptionHandlers()).thenReturn(new String[] { exceptionHandlerName });

    // When
    retryableAspect.attemptMethodAndRetryIfNeeded(mockProceedingJoinPoint, mockRetryable);

    // Then
    verify(mockProceedingJoinPoint).proceed();

    assertTrue(retryExceptionHandler.exceptionHandlerBeenCalled);
}

From source file:com.clicktravel.cheddar.server.application.logging.LoggingAspect.java

License:Apache License

private String methodCallDetail(final ProceedingJoinPoint point) {
    final StringBuilder sb = new StringBuilder();
    sb.append(point.getTarget().getClass().getSimpleName());
    sb.append('.');
    sb.append(((MethodSignature) (point.getSignature())).getMethod().getName());
    sb.append('(');
    boolean firstArg = true;
    for (final Object arg : point.getArgs()) {
        if (!firstArg) {
            sb.append(',');
        }//w w  w .j  a  v a  2  s  .  co m
        firstArg = false;
        sb.append(arg == null ? "null" : arg.toString());
    }
    sb.append(')');
    return sb.toString();
}