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(Object[] args) throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation.

Usage

From source file:com.netflix.genie.web.aspect.HealthCheckMetricsAspect.java

License:Apache License

/**
 * Intercept call to the Health endpoint publish a timer tagged with error, status.
 *
 * @param joinPoint joinPoint for the actual call to invoke()
 * @return Health, as returned by the actual invocation
 * @throws Throwable as thrown by joinPoint.proceed()
 *///from   w  w w . j  av a  2 s  .c o  m
@Around("execution(" + "  org.springframework.boot.actuate.health.Health"
        + "  org.springframework.boot.actuate.health.HealthEndpoint.health()" + ")")
@SuppressWarnings("checkstyle:IllegalThrows") // For propagating Throwable from joinPoint.proceed()
public Health healthEndpointInvokeMonitor(final ProceedingJoinPoint joinPoint) throws Throwable {
    final long start = System.nanoTime();
    final Health health;
    Status status = Status.UNKNOWN;
    final Set<Tag> tags = Sets.newHashSet();
    try {
        health = (Health) joinPoint.proceed(joinPoint.getArgs());
        status = health.getStatus();
    } catch (final Throwable t) {
        tags.add(Tag.of(MetricsConstants.TagKeys.EXCEPTION_CLASS, t.getClass().getCanonicalName()));
        throw t;
    } finally {
        final long turnaround = System.nanoTime() - start;
        tags.add(Tag.of(MetricsConstants.TagKeys.STATUS, status.toString()));
        log.debug("HealthEndpoint.invoke() completed in {} ns", turnaround);
        this.registry.timer(HEALTH_ENDPOINT_TIMER_NAME, tags).record(turnaround, TimeUnit.NANOSECONDS);
    }
    return health;
}

From source file:com.netflix.genie.web.aspect.HealthCheckMetricsAspect.java

License:Apache License

/**
 * Intercept call to HealthIndicator beans loaded and publish a timer tagged with error, if any.
 *
 * @param joinPoint joinPoint for the actual call to health()
 * @return Health, as returned by the actual invocation
 * @throws Throwable as thrown by joinPoint.proceed()
 *///from  ww w  .  ja  va  2 s .c  om
@Around("execution(" + "  org.springframework.boot.actuate.health.Health"
        + "  org.springframework.boot.actuate.health.HealthIndicator.health()" + ")")
@SuppressWarnings("checkstyle:IllegalThrows") // For propagating Throwable from joinPoint.proceed()
public Health healthIndicatorHealthMonitor(final ProceedingJoinPoint joinPoint) throws Throwable {
    final long start = System.nanoTime();
    final Health h;
    Throwable throwable = null;
    try {
        h = (Health) joinPoint.proceed(joinPoint.getArgs());
    } catch (final Throwable t) {
        throwable = t;
        throw t;
    } finally {
        final long turnaround = System.nanoTime() - start;
        recordHealthIndicatorTurnaround(turnaround, joinPoint, throwable);
    }
    return h;
}

From source file:com.netflix.genie.web.aspect.HealthCheckMetricsAspect.java

License:Apache License

/**
 * Intercept call to AbstractHealthIndicator beans loaded and publish a timer tagged with error, if any.
 * This interception is required because these beans are not captured by HealthIndicator.doHealthCheck(),
 * even tho they implement that interface.
 *
 * @param joinPoint joinPoint for the actual call to doHealthCheck()
 * @throws Throwable as thrown by joinPoint.proceed()
 *///w  w w . ja  v  a2 s  .  c o m
@Around("execution(" + "  void org.springframework.boot.actuate.health.AbstractHealthIndicator.doHealthCheck("
        + "      org.springframework.boot.actuate.health.Health.Builder" + "  )" + ")")
@SuppressWarnings("checkstyle:IllegalThrows") // For propagating Throwable from joinPoint.proceed()
public void abstractHealthIndicatorDoHealthCheckMonitor(final ProceedingJoinPoint joinPoint) throws Throwable {
    final long start = System.nanoTime();
    Throwable throwable = null;
    try {
        joinPoint.proceed(joinPoint.getArgs());
    } catch (final Throwable t) {
        throwable = t;
        throw t;
    } finally {
        final long turnaround = System.nanoTime() - start;
        recordHealthIndicatorTurnaround(turnaround, joinPoint, throwable);
    }
}

From source file:com.newtranx.util.monitoring.MonitorAspect.java

License:Apache License

@Around("@annotation(com.newtranx.util.monitoring.Monitoring)")
public Object around(final ProceedingJoinPoint pjp) throws Throwable {
    final MethodSignature signature = (MethodSignature) pjp.getSignature();
    final Method method = getMethod(signature, pjp);
    final long begin = System.currentTimeMillis();
    MonitorContext monitorContext = new MonitorContext() {

        @Override//from w  w w.j  av  a  2 s  . c om
        public void doReport() {
            long end = System.currentTimeMillis();
            String name = method.getAnnotation(Monitoring.class).value().trim();
            Optional<String> optName = StringUtils.isEmpty(name) ? Optional.empty() : Optional.of(name);
            for (Reporter r : reporters) {
                try {
                    r.report(method, end - begin, optName);
                } catch (Throwable t) {
                    t.printStackTrace(System.err);
                }
            }
        }

    };
    Object[] args = pjp.getArgs();
    AsyncHandler asyncHandler = null;
    for (AsyncHandler a : getAsyncHandlers()) {
        Object[] processedArgs = a.preProcess(method, args, monitorContext);
        if (monitorContext.isAsync()) {
            args = processedArgs;
            asyncHandler = a;
            break;
        }
    }
    Object result = pjp.proceed(args);
    if (monitorContext.isAsync()) {
        return asyncHandler.postProcess(result, monitorContext);
    } else {
        monitorContext.doReport();
        return result;
    }
}

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

License:Apache License

/**
 * Check post values on create method./*from  w w  w .  j a  v  a2 s .  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./* w  ww . j  av  a  2 s .  c  om*/
 * 
 * @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  w w  . java  2s .  c o m
 * @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 ww .  j  a v  a  2  s  . c  om
 * 
 * @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  w  w . ja  v a2s .c om*/
 * 
 * @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.
 * //from  w  w w .  j  a  va  2 s . c o 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;
}