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:org.apache.rave.synchronization.SynchronizingAspectTest.java

License:Apache License

private ProceedingJoinPoint prepareJoinPoint(String expectedDiscriminator, String expectedId,
        TestService service, Method expectedMethod, TestObject argument, Object[] joinPointArgs)
        throws Throwable {
    MethodSignature methodSignature = createMock(MethodSignature.class);
    expect(methodSignature.getMethod()).andReturn(expectedMethod);
    replay(methodSignature);//from   www  .  j a v  a  2 s.co  m

    ProceedingJoinPoint joinPoint = createMock(ProceedingJoinPoint.class);
    expect(joinPoint.getSignature()).andReturn(methodSignature);
    expect(joinPoint.getTarget()).andReturn(service);
    expect(joinPoint.getArgs()).andReturn(joinPointArgs);
    expect(joinPoint.proceed()).andReturn(expectedMethod.invoke(service, argument));
    replay(joinPoint);

    Lock lock = new ReentrantLock();
    expect(lockService.borrowLock(expectedDiscriminator, expectedId)).andReturn(lock);
    lockService.returnLock(lock);
    replay(lockService);
    return joinPoint;
}

From source file:org.apache.syncope.core.logic.LogicInvocationHandler.java

License:Apache License

@Around("execution(* org.apache.syncope.core.logic.AbstractLogic+.*(..))")
public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
    Class<?> clazz = joinPoint.getTarget().getClass();

    Object[] input = joinPoint.getArgs();

    String category = clazz.getSimpleName();

    MethodSignature ms = (MethodSignature) joinPoint.getSignature();
    Method method = ms.getMethod();

    String event = joinPoint.getSignature().getName();

    AuditElements.Result result = null;
    Object output = null;/*from   www.  ja v a 2s .  c o m*/
    Object before = null;

    try {
        LOG.debug("Before {}.{}({})", clazz.getSimpleName(), event,
                input == null || input.length == 0 ? "" : Arrays.asList(input));

        try {
            before = ((AbstractLogic) joinPoint.getTarget()).resolveBeanReference(method, input);
        } catch (UnresolvedReferenceException ignore) {
            LOG.debug("Unresolved bean reference ...");
        }

        output = joinPoint.proceed();
        result = AuditElements.Result.SUCCESS;

        LOG.debug("After returning {}.{}: {}", clazz.getSimpleName(), event, output);
        return output;
    } catch (Throwable t) {
        output = t;
        result = AuditElements.Result.FAILURE;

        LOG.debug("After throwing {}.{}", clazz.getSimpleName(), event);
        throw t;
    } finally {
        notificationManager.createTasks(AuditElements.EventCategoryType.LOGIC, category, null, event, result,
                before, output, input);

        auditManager.audit(AuditElements.EventCategoryType.LOGIC, category, null, event, result, before, output,
                input);
    }
}

From source file:org.apache.syncope.core.rest.controller.ControllerHandler.java

License:Apache License

@Around("execution(* org.apache.syncope.core.rest.controller.AbstractController+.*(..))")
public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
    final Class<?> clazz = joinPoint.getTarget().getClass();

    final Object[] input = joinPoint.getArgs();

    final String category = clazz.getSimpleName();

    final MethodSignature ms = (MethodSignature) joinPoint.getSignature();
    Method method = ms.getMethod();

    final String event = joinPoint.getSignature().getName();

    AuditElements.Result result = null;
    Object output = null;//from w  ww. j a  v a 2s.c  o m
    Object before = null;

    try {
        LOG.debug("Before {}.{}({})", clazz.getSimpleName(), event,
                input == null || input.length == 0 ? "" : Arrays.asList(input));

        try {
            before = ((AbstractController) joinPoint.getTarget()).resolveBeanReference(method, input);
        } catch (UnresolvedReferenceException ignore) {
            LOG.debug("Unresolved bean reference ...");
        }

        output = joinPoint.proceed();
        result = AuditElements.Result.SUCCESS;

        LOG.debug("After returning {}.{}: {}", clazz.getSimpleName(), event, output);
        return output;
    } catch (Throwable t) {
        output = t;
        result = AuditElements.Result.FAILURE;

        LOG.debug("After throwing {}.{}", clazz.getSimpleName(), event);
        throw t;
    } finally {
        notificationManager.createTasks(AuditElements.EventCategoryType.REST, category, null, event, result,
                before, output, input);

        auditManager.audit(AuditElements.EventCategoryType.REST, category, null, event, result, before, output,
                input);
    }
}

From source file:org.apache.wicket.metrics.aspects.request.WicketFilterRequestCycleUrlAspect.java

License:Apache License

/**
 * Collects data how often a request has been made against the webapp and counts the time how
 * long the request took. Measures the information with the request url
 * /*  www . j a  va2s .  c o m*/
 * @param joinPoint
 *            the joinPoint to be proceed
 * @return returns the boolean of the processRequest method
 * 
 * @throws Throwable
 *             might occur while invoking process request
 */
@Around("execution(* org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(..))")
public Object aroundRequestProcessedWithURL(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    if (args.length >= 3) {
        Object requestAsObject = args[2];
        if (requestAsObject != null && requestAsObject instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = (HttpServletRequest) requestAsObject;
            String requestUrl = httpServletRequest.getRequestURL().toString();
            String replacedUrl = requestUrl.replace('/', '_');
            replacedUrl = replacedUrl.replace('.', '_');
            replacedUrl = replacedUrl.replaceAll(";jsessionid=.*?(?=\\?|$)", "");
            return measureTime("core/application/request/" + replacedUrl, joinPoint, false);
        }
    }
    return joinPoint.proceed();
}

From source file:org.apereo.inspektr.aspect.TraceLogAspect.java

License:Apache License

/**
 * Added TRACE-level log entries for the executing target.
 *
 * @param proceedingJoinPoint the proceeding join point
 * @return the object//from w ww  .  j  a  va2s  .  c om
 * @throws Throwable the throwable
 */
@Around("(execution (public * org.apereo..*.*(..))) && !(execution( * org.apereo..*.set*(..)))")
public Object traceMethod(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    Logger logger = null;

    try {
        logger = this.getLog(proceedingJoinPoint);
    } catch (final Throwable t) {
        t.printStackTrace();
    }

    if (logger == null) {
        System.err.println("Could not obtain logger object from the proceeding joinpoint");
        return proceedingJoinPoint.proceed();
    }

    Object returnVal = null;
    final String methodName = proceedingJoinPoint.getSignature().getName();
    try {
        if (logger.isTraceEnabled()) {
            final Object[] args = proceedingJoinPoint.getArgs();
            final String arguments;
            if (args == null || args.length == 0) {
                arguments = "";
            } else {
                arguments = Arrays.deepToString(args);
            }
            logger.trace("Entering method [{}] with arguments [{}]", methodName, arguments);
        }
        returnVal = proceedingJoinPoint.proceed();
        return returnVal;
    } finally {
        logger.trace("Leaving method [{}] with return value [{}].", methodName,
                returnVal != null ? returnVal.toString() : "null");
    }
}

From source file:org.apereo.portal.concurrency.caching.RequestCacheAspect.java

License:Apache License

protected CacheKey createCacheKey(ProceedingJoinPoint pjp, RequestCache requestCache) {
    final Signature signature = pjp.getSignature();
    final Class<?> declaringType = signature.getDeclaringType();
    final String signatureLongString = signature.toLongString();

    final boolean[] keyMask = requestCache.keyMask();
    final Object[] args = pjp.getArgs();

    final Object[] keyArgs;
    if (keyMask.length == 0) {
        keyArgs = args;// w ww . j a va  2  s .co m
    } else if (keyMask.length != args.length) {
        throw new AnnotationFormatError(
                "RequestCache.keyMask has an invalid length on: " + signature.toLongString());
    } else {
        keyArgs = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            if (keyMask[i]) {
                keyArgs[i] = args[i];
            }
        }
    }

    return CacheKey.build(signatureLongString, declaringType, keyArgs);
}

From source file:org.apromore.aop.AuditAspect.java

License:Open Source License

@Around(value = "execution(* *(..)) && @annotation(audited)", argNames = "pjp,audited")
public Object logMessage(ProceedingJoinPoint pjp, Audited audited) throws Throwable {

    long nanosBefore = System.nanoTime();
    try {//from  w  ww.j a  va2  s.  c o m
        Object returned = pjp.proceed();
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), returned, null,
                durationInNanos);
        LOGGER.info(message);
        return returned;
    } catch (Throwable t) {
        long durationInNanos = System.nanoTime() - nanosBefore;
        String message = buildMessage(audited.message(), pjp.getThis(), pjp.getArgs(), null, t,
                durationInNanos);
        LOGGER.warn(message);
        throw t;
    }
}

From source file:org.broadleafcommerce.common.vendor.service.cache.ServiceResponseCache.java

License:Apache License

public Object processRequest(ProceedingJoinPoint call) throws Throwable {
    CacheRequest cacheRequest = (CacheRequest) call.getArgs()[0];
    Cache cache = ((ServiceResponseCacheable) call.getTarget()).getCache();
    List<Serializable> cacheItemResponses = new ArrayList<Serializable>();
    Iterator<CacheItemRequest> itr = cacheRequest.getCacheItemRequests().iterator();
    while (itr.hasNext()) {
        CacheItemRequest itemRequest = itr.next();
        if (cache.isKeyInCache(itemRequest.key())) {
            cacheItemResponses.add(cache.get(itemRequest.key()).getValue());
            itr.remove();// ww w . j  a  v  a  2 s  . com
        }
    }

    CacheResponse returnValue = (CacheResponse) call.proceed();
    Object[] responses = new Object[cacheItemResponses.size() + returnValue.getCacheItemResponses().length];
    responses = cacheItemResponses.toArray(responses);
    for (int j = 0; j < returnValue.getCacheItemResponses().length; j++) {
        Element element = new Element(cacheRequest.getCacheItemRequests().get(j).key(),
                returnValue.getCacheItemResponses()[j]);
        cache.put(element);
    }
    System.arraycopy(returnValue.getCacheItemResponses(), 0, responses, cacheItemResponses.size(),
            returnValue.getCacheItemResponses().length);
    returnValue.setCacheItemResponses(responses);

    return returnValue;
}

From source file:org.broadleafcommerce.core.web.order.OrderStateAOP.java

License:Apache License

public Object processOrderRetrieval(ProceedingJoinPoint call) throws Throwable {
    Object returnValue;/*from  ww w  .  java 2s  .co m*/
    /*
     * we retrieve the OrderState instance directly from the application
     * context, as this bean has a request scope.
     */
    OrderState orderState = (OrderState) applicationContext.getBean("blOrderState");
    Customer customer = (Customer) call.getArgs()[0];
    Order order = orderState.getOrder(customer);
    if (order != null) {
        returnValue = order;
    } else {
        returnValue = call.proceed();
        returnValue = orderState.setOrder(customer, (Order) returnValue);
    }

    return returnValue;
}

From source file:org.businessmanager.aspect.dao.TrackModificationsAdvise.java

License:Apache License

private TrackModifications getEntity(ProceedingJoinPoint joinPoint) {
    Object[] args = joinPoint.getArgs();
    if (args != null && args.length == 1) {
        if (args[0] instanceof TrackModifications) {
            return (TrackModifications) args[0];
        }//from  w  w w  .j  av  a 2 s  .  c o m
    }
    return null;
}