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:com.haulmont.cuba.core.sys.ServiceInterceptor.java

License:Apache License

protected void validateMethodParameters(ProceedingJoinPoint ctx,
        @Nullable ValidateServiceMethodContext validatedContext) {
    if (validatedContext != null) {
        log.trace("Validating service call params: {}", ctx.getSignature());

        ExecutableValidator validator = validatedContext.getValidator();

        Class[] constraintGroups = validatedContext.getGroups();
        if (constraintGroups.length == 0) {
            constraintGroups = new Class[] { Default.class, ServiceParametersChecks.class };
        }//from  www  .jav  a 2 s .co  m

        Set<ConstraintViolation<Object>> violations = validator.validateParameters(validatedContext.getTarget(),
                validatedContext.getMethod(), validatedContext.getArgs(), constraintGroups);

        if (!violations.isEmpty()) {
            Class serviceInterface = ctx.getSignature().getDeclaringType();
            Set<ConstraintViolation<Object>> resultViolations = violations.stream()
                    .map(violation -> new ServiceMethodConstraintViolation(serviceInterface, violation))
                    .collect(Collectors.toSet());

            throw new MethodParametersValidationException("Service method parameters validation failed",
                    resultViolations);
        }
    }
}

From source file:com.haulmont.cuba.core.sys.ServiceInterceptor.java

License:Apache License

protected void validateMethodResult(ProceedingJoinPoint ctx, ValidateServiceMethodContext validatedContext,
        Object methodResult) {/*from   w  w  w  .  j  a  v  a2  s  . c  o m*/
    if (validatedContext != null) {
        ExecutableValidator validator = validatedContext.getValidator();

        log.trace("Validating service call result: {}", ctx.getSignature());

        Class[] constraintGroups = validatedContext.getGroups();
        if (constraintGroups.length == 0) {
            constraintGroups = new Class[] { Default.class, ServiceResultChecks.class };
        }

        Set<ConstraintViolation<Object>> violations = validator.validateReturnValue(
                validatedContext.getTarget(), validatedContext.getMethod(), methodResult, constraintGroups);

        if (!violations.isEmpty()) {
            Class serviceInterface = ctx.getSignature().getDeclaringType();
            Set<ConstraintViolation<Object>> paramsViolations = violations.stream()
                    .map(violation -> new ServiceMethodConstraintViolation(serviceInterface, violation))
                    .collect(Collectors.toSet());

            throw new MethodResultValidationException("Service method result validation failed",
                    paramsViolations);
        }
    }
}

From source file:com.haulmont.cuba.core.sys.ServiceInterceptor.java

License:Apache License

protected void logException(Throwable e, ProceedingJoinPoint ctx) {
    if (e instanceof NoUserSessionException) {
        // If you don't want NoUserSessionException in log, set level higher than INFO for ServiceInterceptor logger
        log.info("Exception in {}: {}", ctx.getSignature().toShortString(), e.toString());
    } else if (e instanceof MethodParametersValidationException) {
        log.info("MethodParametersValidationException in {}: {}, violations:\n{}",
                ctx.getSignature().toShortString(), e.toString(),
                ((MethodParametersValidationException) e).getConstraintViolations());
    } else if (e instanceof MethodResultValidationException) {
        log.error("MethodResultValidationException in {}: {}, violations:\n{}",
                ctx.getSignature().toShortString(), e.toString(),
                ((MethodResultValidationException) e).getConstraintViolations());
    } else {/*from w  w  w .  j a v a 2  s . co m*/
        Logging annotation = e.getClass().getAnnotation(Logging.class);
        if (annotation == null || annotation.value() == Logging.Type.FULL) {
            log.error("Exception: ", e);
        } else if (annotation.value() == Logging.Type.BRIEF) {
            log.error("Exception in {}: {}", ctx.getSignature().toShortString(), e.toString());
        }
    }
}

From source file:com.haulmont.cuba.core.sys.TransactionalInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    Method method = ((MethodSignature) ctx.getSignature()).getMethod();
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, ctx.getTarget().getClass());
    Transactional transactional = specificMethod.getAnnotation(Transactional.class);
    if (transactional == null)
        throw new IllegalStateException("Cannot determine data store of the current transaction");

    String storeName = Strings.isNullOrEmpty(transactional.value()) ? Stores.MAIN : transactional.value();

    log.trace("Entering transactional method, store='{}'", storeName);

    ((PersistenceImpl) persistence).registerSynchronizations(storeName);

    return ctx.proceed();
}

From source file:com.haulmont.cuba.security.sys.AuthenticationInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    if (log.isTraceEnabled())
        log.trace("Authenticating: ", ctx.getSignature());

    try {//from w  w  w  .ja v a  2 s  .  co m
        authentication.begin();
        Object res = ctx.proceed();
        return res;
    } finally {
        authentication.end();
    }
}

From source file:com.haulmont.cuba.security.sys.TrustedServiceInterceptor.java

License:Apache License

/**
 * Check if the client is permitted to call the service method.
 *
 * @param ctx context/*from   w  w w . j a v a  2 s  .  c o m*/
 */
protected void checkTrustedAccess(ProceedingJoinPoint ctx) {
    RemoteClientInfo remoteClientInfo = RemoteClientInfo.get();

    if (remoteClientInfo != null && ctx instanceof MethodInvocationProceedingJoinPoint) {
        if (!trustedLoginHandler.checkAddress(remoteClientInfo.getAddress())) {
            log.warn("Client is not allowed to call '{}' since IP '{}' is not trusted",
                    ctx.getSignature().toShortString(), remoteClientInfo.getAddress());

            throw new TrustedAccessRequiredException();
        }
    }
}

From source file:com.heliosmi.portal.aspect.LoggingAspect.java

License:Apache License

@Around("allBeans()")
public Object profiler(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.nanoTime();
    String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
    log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs()));

    Object returnValue = null;// ww  w . ja  v a 2s.  c o  m
    try {
        returnValue = pjp.proceed();
    } catch (Exception exception) {
        log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception)));
        log.error(ExceptionUtils.getStackTrace(exception));
        throw exception;
    }

    long end = System.nanoTime();
    log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. ");

    return returnValue;
}

From source file:com.helpinput.profaop.AspectProfiler.java

License:Apache License

@Around("notSelf() && notProfiler() && notAspectJ() && allMethods()")
public Object exeAround(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Monitor.startMonitor(signature.getMethod());
    Throwable error = null;/*  w  w  w .  j  a va2 s.  c o  m*/
    try {
        Object result = joinPoint.proceed();
        return result;
    } catch (Throwable e) {
        error = e;
        throw error;
    } finally {
        Monitor.stopMonitor(error);
    }
}

From source file:com.himanshu.um.impl.aop.performance.monitor.DBPerformanceMonitorAOP.java

License:Apache License

@Around("execution(@com.himanshu.um.api.performance.annotation.MonitorPerformance * *(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    long startTime = System.currentTimeMillis();
    /*LOG.debug("logAround() is running!");
    LOG.debug("hijacked method : " + joinPoint.getSignature().getName());
    LOG.debug("hijacked arguments : " + Arrays.toString(joinPoint.getArgs()));
    LOG.debug("Around before is running!");
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("Around after is running!");
    LOG.debug("******");*///from ww  w  .  ja va  2 s  .  c o m
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("{}, {}, {}", new Object[] { joinPoint.getTarget().getClass().getName(),
            joinPoint.getSignature().getName(), System.currentTimeMillis() - startTime });
}

From source file:com.hipercube.springstudy.aspect.Ch13Aspect.java

License:Open Source License

@Around("runtimeCheck()")
public Object runtimeCheckAdvice(ProceedingJoinPoint joinPoint) {
    // Before/*from   w  ww.j  av  a  2 s.c om*/
    String signatureString = joinPoint.getSignature().toShortString();
    logger.info(signatureString + " Start");
    long start = System.nanoTime();
    Object result = null;

    // Method Execution
    try {
        result = joinPoint.proceed();
    } catch (Throwable ignored) {
    }

    // After
    long finish = System.nanoTime();
    logger.info(signatureString + " End");
    long runtime = finish - start;
    logger.info(signatureString + " Execution time: " + runtime + "ns");

    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    requestAttributes.setAttribute("runtime", runtime, RequestAttributes.SCOPE_REQUEST);

    return result;
}