Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:io.micrometer.core.aop.TimedAspect.java

License:Apache License

@Around("execution (@io.micrometer.core.annotation.Timed * *.*(..))")
public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();
    Timed timed = method.getAnnotation(Timed.class);
    final String metricName = timed.value().isEmpty() ? DEFAULT_METRIC_NAME : timed.value();
    Timer.Sample sample = Timer.start(registry);
    String exceptionClass = "none";

    try {/* w  ww.java 2s.c o  m*/
        return pjp.proceed();
    } catch (Exception ex) {
        exceptionClass = ex.getClass().getSimpleName();
        throw ex;
    } finally {
        sample.stop(Timer.builder(metricName)
                .description(timed.description().isEmpty() ? null : timed.description()).tags(timed.extraTags())
                .tags(EXCEPTION_TAG, exceptionClass).tags(tagsBasedOnJoinPoint.apply(pjp))
                .publishPercentileHistogram(timed.histogram())
                .publishPercentiles(timed.percentiles().length == 0 ? null : timed.percentiles())
                .register(registry));
    }
}

From source file:io.micrometer.spring.scheduling.ScheduledMethodMetrics.java

License:Apache License

@Around("execution (@org.springframework.scheduling.annotation.Scheduled  * *.*(..))")
public Object timeScheduledOperation(ProceedingJoinPoint pjp) throws Throwable {
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();
    String signature = pjp.getSignature().toShortString();

    if (method.getDeclaringClass().isInterface()) {
        try {/*ww  w .j  a  va 2 s. c o m*/
            method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(),
                    method.getParameterTypes());
        } catch (final SecurityException | NoSuchMethodException e) {
            logger.warn("Unable to perform metrics timing on " + signature, e);
            return pjp.proceed();
        }
    }

    Timer shortTaskTimer = null;
    LongTaskTimer longTaskTimer = null;

    for (Timed timed : TimedUtils.findTimedAnnotations(method)) {
        if (timed.longTask())
            longTaskTimer = LongTaskTimer.builder(timed.value()).tags(timed.extraTags())
                    .description("Timer of @Scheduled long task").register(registry);
        else {
            Timer.Builder timerBuilder = Timer.builder(timed.value()).tags(timed.extraTags())
                    .description("Timer of @Scheduled task");

            if (timed.percentiles().length > 0) {
                timerBuilder = timerBuilder.publishPercentiles(timed.percentiles());
            }

            shortTaskTimer = timerBuilder.register(registry);
        }
    }

    if (shortTaskTimer != null && longTaskTimer != null) {
        final Timer finalTimer = shortTaskTimer;
        //noinspection NullableProblems
        return recordThrowable(longTaskTimer, () -> recordThrowable(finalTimer, pjp::proceed));
    } else if (shortTaskTimer != null) {
        //noinspection NullableProblems
        return recordThrowable(shortTaskTimer, pjp::proceed);
    } else if (longTaskTimer != null) {
        //noinspection NullableProblems
        return recordThrowable(longTaskTimer, pjp::proceed);
    }

    return pjp.proceed();
}

From source file:io.opencensus.contrib.spring.aop.CensusSpringAspect.java

License:Apache License

/**
 * trace handles methods executed with the `@Traced` annotation. A new span will be created with
 * an optionally customizable span name.
 *
 * @param call the join point to execute
 * @return the result of the invocation//ww  w  .  jav  a  2 s  . co  m
 * @throws Throwable if the underlying target throws an exception
 * @since 0.16.0
 */
@Around("@annotation(io.opencensus.contrib.spring.aop.Traced)")
public Object trace(ProceedingJoinPoint call) throws Throwable {
    MethodSignature signature = (MethodSignature) call.getSignature();
    Method method = signature.getMethod();

    Traced annotation = method.getAnnotation(Traced.class);
    if (annotation == null) {
        return call.proceed();
    }
    String spanName = annotation.name();
    if (spanName.isEmpty()) {
        spanName = method.getName();
    }

    return Handler.proceed(call, tracer, spanName);
}

From source file:io.opencensus.contrib.spring.aop.CensusSpringSqlAspect.java

License:Apache License

private static String makeSpanName(ProceedingJoinPoint call, String sql) {
    String hash = Integer.toHexString(hashCode(sql.toCharArray()));
    return call.getSignature().getName() + "-" + hash;
}

From source file:io.pcp.parfait.spring.MonitoringAspect.java

License:Apache License

public Object profileMethod(ProceedingJoinPoint pjp) throws Throwable {
    Timeable timeable = map.get(pjp.getTarget());
    if (timeable == null) {
        return pjp.proceed();
    }/*from w w w .  j  a va 2 s  . co  m*/
    EventMetricCollector collector = timer.getCollector();
    try {
        collector.startTiming(timeable, pjp.getSignature().getName());
        return pjp.proceed();
    } finally {
        collector.stopTiming();
    }
}

From source file:io.renren.common.aspect.SysLogAspect.java

License:Apache License

private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    SysLogEntity sysLog = new SysLogEntity();
    SysLog syslog = method.getAnnotation(SysLog.class);
    if (syslog != null) {
        //??/*from ww  w  .  j  ava 2s .co  m*/
        sysLog.setOperation(syslog.value());
    }

    //??
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    sysLog.setMethod(className + "." + methodName + "()");

    //?
    Object[] args = joinPoint.getArgs();
    try {
        String params = new Gson().toJson(args[0]);
        sysLog.setParams(params);
    } catch (Exception e) {

    }

    //?request
    HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
    //IP?
    sysLog.setIp(IPUtils.getIpAddr(request));

    //??
    String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
    sysLog.setUsername(username);

    sysLog.setTime(time);
    sysLog.setCreateDate(new Date());
    //?
    sysLogService.insert(sysLog);
}

From source file:io.servicecomb.tracing.zipkin.ZipkinSpanAspect.java

License:Apache License

@Around("execution(@io.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
    String spanName = spanAnnotation.spanName();
    String callPath = spanAnnotation.callPath();
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    LOG.debug("Generating zipkin span for method {}", method.toString());
    if ("".equals(spanName)) {
        spanName = method.getName();//from   w  w  w  .ja  v a 2 s . c o  m
    }
    if ("".equals(callPath)) {
        callPath = method.toString();
    }

    return adviser.invoke(spanName, callPath, joinPoint::proceed);

}

From source file:io.starter.security.securefield.SecureFieldAspect.java

@Around(FIELD_GET)
public Object getSecureField(ProceedingJoinPoint pjp) throws Throwable {
    String cnm = Thread.currentThread().getStackTrace()[8].getClassName();

    // System.err.println("Calling: " + cnm);
    // if iBatis is calling, do not decrypt
    if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) {
        return pjp.proceed(pjp.getArgs());
    }/*from w w w.j  a  v  a  2 s  .com*/

    Logger.debug("Get Secure Field for: " + pjp.toLongString());
    Object targetObject = pjp.getTarget();
    String secureFieldName = pjp.getSignature().getName();
    Field secureField = targetObject.getClass().getDeclaredField(secureFieldName);
    secureField.setAccessible(true);
    Object encryptedObject = secureField.get(targetObject);
    secureField.setAccessible(false);
    return SecureEncrypter.decrypt(String.valueOf(encryptedObject));
}

From source file:io.starter.security.securefield.SecureFieldAspect.java

@Around(FIELD_SET)
public Object setSecureField(ProceedingJoinPoint pjp) throws Throwable {
    String cnm = Thread.currentThread().getStackTrace()[8].getClassName();

    // System.err.println("Calling: " + cnm);
    // if iBatis is calling, do not encrypt
    if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) {
        return pjp.proceed(pjp.getArgs());
    }//from   w  w w  .  j a va  2 s  .com
    Logger.debug("Set Secure Field for: " + pjp.toLongString());
    String clearTextValue = String.valueOf(pjp.getArgs()[0]);
    String encryptedValue = SecureEncrypter.encrypt(clearTextValue);
    Object targetObject = pjp.getTarget();
    String secureFieldName = pjp.getSignature().getName();
    Field secureField = targetObject.getClass().getDeclaredField(secureFieldName);
    secureField.setAccessible(true);
    secureField.set(targetObject, encryptedValue);
    secureField.setAccessible(false);
    return null;
}

From source file:it.tidalwave.northernwind.aspect.DebugProfilingAspect.java

License:Apache License

@Nonnull
private static <T extends Annotation> T getAnnotation(final @Nonnull ProceedingJoinPoint pjp,
        final @Nonnull Class<T> annotationClass) throws NoSuchMethodException {
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    if (method.getDeclaringClass().isInterface()) // FIXME && annotation inheritance -- FIXME also ancestor class
    {// ww w .j  av  a 2s .  c  o m
        final String methodName = pjp.getSignature().getName();
        method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
    }

    return method.getAnnotation(annotationClass);
}