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.onboard.service.activity.impl.test.ActivityRecorderImplTest.java

License:Apache License

private ProceedingJoinPoint getASampleProceedingJoinPoint() throws Throwable {
    ProceedingJoinPoint p = mock(ProceedingJoinPoint.class);
    when(p.getArgs()).thenReturn(new Object[] { original });
    when(p.proceed()).thenReturn(identifiable);
    ActivityService object = mock(ActivityService.class);
    when(p.getTarget()).thenReturn(object);
    return p;// w w  w.  ja va2 s  . c om
}

From source file:com.onboard.service.index.impl.IndexAspectImpl.java

License:Apache License

@Override
public Object deleteByPrimaryKey(ProceedingJoinPoint joinpoint) {
    Object returnVal = null;/*from www  .j  av  a2 s.c  o  m*/
    //String modelType = joinpoint.getTarget().getClass().getName();
    // TODO: get model type from mapper
    String modelType = "";
    IndexableService indexableService = indexableServices.getIndexableService(modelType);

    try {
        returnVal = joinpoint.proceed();
        if (indexableService != null) {
            String documentId = this.getDocumentId(indexableService.modelType(),
                    (Integer) joinpoint.getArgs()[0]);
            indexServices.getIndexService().deleteIndexById(documentId);
        }
    } catch (Throwable e) {
        // TODO ?Activityaround advice?
        logger.error("fail to update index: ", e);
    }
    return returnVal;
}

From source file:com.onboard.service.index.impl.IndexAspectImpl.java

License:Apache License

@Override
public Object deleteByExample(ProceedingJoinPoint joinpoint) {
    Object returnVal = null;/*  w  w  w .ja  v a  2s  .com*/
    //String modelType = joinpoint.getTarget().getClass().getName();
    // TODO: get model type from mapper
    String modelType = "";
    IndexableService indexableService = indexableServices.getIndexableService(modelType);
    List<String> documentIdList = new ArrayList<String>();
    if (indexableService != null) {
        BaseExample example = (BaseExample) joinpoint.getArgs()[0];
        List<Indexable> items = indexableService.getIndexablesByExample(example);

        documentIdList = new ArrayList<String>();
        for (Indexable item : items) {
            documentIdList.add(this.getDocumentId(item.getType(), item.getId()));
        }
    }
    try {
        returnVal = joinpoint.proceed();
        if (!documentIdList.isEmpty()) {
            indexServices.getIndexService().deleteIndexByIdList(documentIdList);
        }

    } catch (Throwable e) {
        logger.error("fail to update index: ", e);
    }
    return returnVal;
}

From source file:com.otterca.ca.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on create method./* w w w .  jav  a2s .  c  om*/
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.otterca.ca.webservice.server.rest.AbstractResource) && args(rto,..)")
public Object checkParametersCreate(ProceedingJoinPoint pjp, Validatable rto) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());
    final String name = pjp.getSignature().getName();
    Object results = null;

    if (rto.validate()) {
        // this should be safe since parameters have been validated.
        if (log.isDebugEnabled()) {
            log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs())));
        }
        results = pjp.proceed(pjp.getArgs());
    } else {
        // FIXME: this is unsafe
        if (log.isInfoEnabled()) {
            log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs())));
        }
        // TODO: tell caller what the problems were
        results = Response.status(Status.BAD_REQUEST).build();
    }

    return results;
}

From source file:com.otterca.ca.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on find methods. This is actually a no-op but it allows
 * us to log method entry.//from   w  w  w .j a v  a 2s .  co m
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.otterca.ca.webservice.server.rest.AbstractResource) && execution(* *.find*(..))")
public Object checkParametersFind(ProceedingJoinPoint pjp) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s(%s): entry", pjp.getSignature().getName(), Arrays.toString(pjp.getArgs())));
    }
    final Object results = pjp.proceed(pjp.getArgs());

    return results;
}

From source file:com.otterca.ca.webservice.server.rest.UnexpectedResourceExceptionHandler.java

License:Apache License

/**
 * Check for an unhandled exception from a REST resource. If we catch one
 * AND the method returns a Response we can return a Server Internal Error
 * (500) error code instead of blowing up. We need to check though since
 * some methods don't return a Response.
 * //from  w  ww. java2  s  .  c  om
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.otterca.ca.webservice.server.rest.AbstractResource)")
public Object checkForUnhandledException(ProceedingJoinPoint pjp) throws Throwable {
    Object results = null;
    Logger log = Logger.getLogger(pjp.getSignature().getClass());

    try {
        results = pjp.proceed(pjp.getArgs());
        //} catch (ObjectNotFoundException e) {
        //    // this is safe to log since we know that we've passed filtering.
        //    String args = Arrays.toString(pjp.getArgs());
        //    results = Response.status(Status.NOT_FOUND).entity("object not found: " + args).build();
        //    if (log.isDebugEnabled()) {
        //        log.debug("object not found: " + args);
        //    }
    } catch (Exception e) {
        // find the method we called. We can't cache this since the method
        // may be overloaded
        Method method = findMethod(pjp);
        if ((method != null) && Response.class.isAssignableFrom(method.getReturnType())) {
            // if the method returns a response we can return a 500 message.
            if (!(e instanceof UnitTestException)) {
                if (log.isInfoEnabled()) {
                    log.info(String.format("%s(): unhandled exception: %s", pjp.getSignature().getName(),
                            e.getMessage()), e);
                }
            } else if (log.isTraceEnabled()) {
                log.info("unit test exception: " + e.getMessage());
            }
            results = Response.status(Status.INTERNAL_SERVER_ERROR).build();
        } else {
            // DO NOT LOG THE EXCEPTION. That just clutters the log - let
            // the final handler log it.
            throw e;
        }
    }

    return results;
}

From source file:com.ottervpn.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on create method./*from   w  w w. j  a  v  a2  s .c  o  m*/
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.ottervpn.webservice.server.rest.AbstractResource) && args(rto,..)")
public Object checkParametersCreate(ProceedingJoinPoint pjp, Validatable rto) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());
    final String name = pjp.getSignature().getName();
    Object results = null;

    if (rto.validate()) {
        // this should be safe since parameters have been validated.
        if (log.isDebugEnabled()) {
            log.debug(String.format("%s(%s): entry", name, Arrays.toString(pjp.getArgs())));
        }
        results = pjp.proceed(pjp.getArgs());
    } else {
        // FIXME: this is unsafe
        if (log.isInfoEnabled()) {
            log.info(String.format("%s(%s): bad arguments", name, Arrays.toString(pjp.getArgs())));
        }
        // TODO: tell caller what the problems were
        results = Response.status(Status.BAD_REQUEST).build();
    }

    return results;
}

From source file:com.ottervpn.webservice.server.rest.CheckPostValues.java

License:Apache License

/**
 * Check post values on find methods. This is actually a no-op but it allows
 * us to log method entry./*from   w ww  .j  a v  a  2s  .  co m*/
 * 
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.ottervpn.webservice.server.rest.AbstractResource) && execution(* *.find*(..))")
public Object checkParametersFind(ProceedingJoinPoint pjp) throws Throwable {
    final Logger log = Logger.getLogger(pjp.getSignature().getDeclaringType());

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s(%s): entry", pjp.getSignature().getName(), Arrays.toString(pjp.getArgs())));
    }
    final Object results = pjp.proceed(pjp.getArgs());

    return results;
}

From source file:com.ottervpn.webservice.server.rest.UnexpectedResourceExceptionHandler.java

License:Apache License

/**
 * Check for an unhandled exception from a REST resource. If we catch one
 * AND the method returns a Response we can return a Server Internal Error
 * (500) error code instead of blowing up. We need to check though since
 * some methods don't return a Response.
 * // ww  w. j a va  2  s . co  m
 * @param pjp
 * @return
 * @throws Throwable
 */
@Around("target(com.ottervpn.webservice.server.rest.AbstractResource)")
public Object checkForUnhandledException(ProceedingJoinPoint pjp) throws Throwable {
    Object results = null;
    Logger log = Logger.getLogger(pjp.getSignature().getClass());

    try {
        results = pjp.proceed(pjp.getArgs());
        //} catch (ObjectNotFoundException e) {
        //    // this is safe to log since we know that we've passed filtering.
        //    String args = Arrays.toString(pjp.getArgs());
        //    results = Response.status(Status.NOT_FOUND).entity("object not found: " + args).build();
        //    if (log.isDebugEnabled()) {
        //        log.debug("object not found: " + args);
        //    }
    } catch (Exception e) {
        // find the method we called. We can't cache this since the method
        // may be overloaded
        Method method = findMethod(pjp);
        if ((method != null) && Response.class.isAssignableFrom(method.getReturnType())) {
            // if the method returns a response we can return a 500 message.
            if (!(e instanceof UnitTestException)) {
                if (log.isInfoEnabled()) {
                    log.info(String.format("%s(): unhandled exception: %s", pjp.getSignature().getName(),
                            e.getMessage()), e);
                }
            } else if (log.isTraceEnabled()) {
                log.info("unit test exception: " + e.getMessage());
            }
            results = Response.status(Status.INTERNAL_SERVER_ERROR).build();
        } else {
            // DO NOT LOG THE EXCEPTION. That just clutters the log - let
            // the final handler log it.
            throw e;
        }
    }

    return results;
}

From source file:com.p5solutions.trackstate.aop.TrackStateProxyAspect.java

License:Open Source License

/**
 * Wrap around a method with the annotation of {@link WrapTrackStateProxy}. If {@link TrackStateProxyStategy#PROXY},
 * the returning value of this method will be proxied via the {@link #trackStateProxyFactory}.
 * //from  ww  w  .  j  a v  a 2  s.c om
 * @param pjp
 *          The proceeding join point, representing the method in question.
 * @param wrap
 *          The {@link WrapTrackStateProxy} instance on annotated on the method.
 * @return Instance of the returning object form the <code>pjp.proceed()</code> proxied via the
 *         {@link #autoTrack(ProceedingJoinPoint)} if {@link TrackStateProxyStategy#PROXY}
 * @throws Throwable
 *           the throwable
 */
@Around("@annotation(wrap)")
public Object trackState(ProceedingJoinPoint pjp, WrapTrackStateProxy wrap) throws Throwable {

    Object target = pjp.proceed();
    Object[] args = pjp.getArgs();

    target = wrap(target, args, wrap);

    return target;
}