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:at.ac.tuwien.infosys.jcloudscale.server.aspects.StaticFieldAspect.java

License:Apache License

@Around("get(@at.ac.tuwien.infosys.jcloudscale.annotations.CloudGlobal static * *.*)")
public Object readStaticValueFromClient(ProceedingJoinPoint pjp) throws Throwable {

    if (!JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    Object returned = null;/*  ww  w.j  a  v  a2 s.  c o  m*/

    try (IMQWrapper mq = JCloudScaleConfiguration.createMQWrapper()) {

        FieldSignature sig = (FieldSignature) pjp.getSignature();
        Field field = sig.getField();

        GetStaticValueObject req = new GetStaticValueObject();
        req.setClassName(field.getDeclaringClass().getCanonicalName());
        req.setField(field.getName());

        mq.createQueueProducer(
                JCloudScaleConfiguration.getConfiguration().server().getStaticFieldReadRequestQueueName());
        UUID corrId = UUID.randomUUID();
        mq.createTopicConsumer(
                JCloudScaleConfiguration.getConfiguration().server().getStaticFieldReadResponsesQueueName(),
                "JMSCorrelationID = '" + corrId.toString() + "'");
        GetStaticValueReturnObject ret = (GetStaticValueReturnObject) mq.requestResponse(req, corrId);

        ClassLoader classLoader = field.getDeclaringClass().getClassLoader();
        returned = SerializationUtil.getObjectFromBytes(ret.getValue(), classLoader);
        returned = JCloudScaleReferenceManager.getInstance().processField(field, returned);
        returned = CgLibUtil.replaceRefWithProxy(returned, classLoader);

    } catch (JCloudScaleException e) {
        // this should happen if the by-ref type did not have a default constructor
        e.printStackTrace();
        throw e;
    } catch (JMSException | NamingException | TimeoutException | ClassNotFoundException | IOException e) {
        e.printStackTrace();
        log.severe("Could not write static field: " + e.getMessage());
    }

    return returned;
}

From source file:au.com.funkworks.jmp.MiniProfilerAspect.java

License:Open Source License

@Around("anyPublicMethod() && @annotation(profiler)")
public Object profiler(ProceedingJoinPoint pjp, Profiler profiler) throws Throwable {
    String desc = profiler.value();
    if (desc == null || desc.equals("")) {
        desc = pjp.getSignature().toShortString();

        if (desc.endsWith("()")) {
            desc = desc.substring(0, desc.length() - 2);
        } else if (desc.endsWith("(..)")) {
            desc = desc.substring(0, desc.length() - 4);
        }//w  w w . jav a  2 s.  co m
    }
    Step step = MiniProfiler.step(desc);
    try {
        return pjp.proceed();
    } finally {
        step.close();
    }
}

From source file:au.id.wolfe.stormcloud.core.interceptor.DAOInterceptor.java

License:Apache License

@Around("execution(* au.id.wolfe.stormcloud.core.dao..*.*(..))")
public Object logHibernateQueryTimes(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    final String targetClass = ClassUtils
            .getShortClassName(proceedingJoinPoint.getTarget().getClass().getName());
    final String methodName = proceedingJoinPoint.getSignature().getName();

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();//from www  .  j  a  v a2  s . com
    Object retVal = proceedingJoinPoint.proceed();
    stopWatch.stop();

    StringBuilder sb = new StringBuilder();
    sb.append(targetClass).append(" - ").append(methodName).append(": ").append(stopWatch.getTime())
            .append(" ms");

    log.debug(sb.toString());

    return retVal;
}

From source file:be.nille.jwt.aspect.JWTAspect.java

private String replacePlaceholdersInExpression(final ProceedingJoinPoint joinPoint, String expression) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    Object[] args = joinPoint.getArgs();
    final Annotation[][] parameterAnnotations = method.getParameterAnnotations();

    for (int i = 0; i < parameterAnnotations.length; i++) {
        final Annotation[] annotations = parameterAnnotations[i];
        AnnotationService annotationService = new AnnotationServiceImpl();
        final ClaimValue claimAnnotation = annotationService.getAnnotationByType(annotations, ClaimValue.class);

        if (claimAnnotation != null) {
            String claimValue = claimAnnotation.value();
            String argument = (String) args[i];
            expression = expression.replace("#" + claimValue, argument);
            log.debug(claimValue);/*from www . j  a va 2  s.co m*/
            break;
        }
    }
    return expression;
}

From source file:br.com.itw.commons.aop.OnSuccessAdvice.java

License:Apache License

@Around("execution(public * br.com.itw.qopsearch.api.**.*.*(..)) && @annotation(requestMapping)")
public HttpEntity onSuccess(ProceedingJoinPoint pjp, RequestMapping requestMapping) throws Throwable {

    int length = requestMapping.method().length;
    if (length == 0) {
        throw new IllegalArgumentException(ERRO_SEM_METODO_DEFINIDO);
    }//from   w  w  w.ja  v  a 2s . c  o  m

    boolean containsGet = Arrays.asList(requestMapping.method()).contains(RequestMethod.GET);
    if (containsGet && length > 1) {
        throw new IllegalArgumentException(ERRO_GET);
    }

    Object object = null;
    Object objectBody = null;
    HttpStatus httpStatus = HttpStatus.OK;

    String methodName = pjp.getSignature().getName();

    if (!containsGet && !methodName.startsWith("find") && !methodName.startsWith("search")) {

        object = pjp.proceed();

        HttpEntity httpEntity;
        ResponseEntity responseEntity;

        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        String prefixCode = ON_SUCCESS + pjp.getTarget().getClass().getSimpleName() + "." + methodName;

        String titleCode = prefixCode + "." + TITLE;
        String messageCode = prefixCode + "." + MESSAGE;

        if (!pjp.getSignature().toString().startsWith("void")) {

            if (object instanceof ResponseEntity) {
                responseEntity = (ResponseEntity) object;
                httpStatus = responseEntity.getStatusCode();
                objectBody = responseEntity.getBody();
            } else if (object instanceof HttpEntity) {
                httpEntity = (HttpEntity) object;

                httpStatus = httpEntity == null ? HttpStatus.NO_CONTENT : HttpStatus.CREATED;
                if (HttpStatus.CREATED.equals(httpStatus))
                    objectBody = httpEntity.getBody();
            }

            String title = messageSource.getMessage(titleCode, null, SUCESSO_TITLE, Locale.getDefault());
            headers.add(TITLE, title);

            String sucessoDefault = messageSource.getMessage(SUCESSO_MSG, null, Locale.getDefault());
            String message = messageSource.getMessage(messageCode, null, sucessoDefault, Locale.getDefault());
            headers.add(MESSAGE, message);

            return new ResponseEntity(objectBody, headers, httpStatus);
        } else {
            //Mtodos do tipo void, no tem como fazer nada, o desenvolvedor decidiu retornar 200
            return null;
        }

    }

    return httpGetEntity(pjp, objectBody, httpStatus);

}

From source file:callcount.lib.probe.AbstractStartEndAspect.java

License:Apache License

@Around("monitoredOperation() && notWithinKieker()")
public Object operation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    final String signature = thisJoinPoint.getSignature().toLongString();
    if (!CTRLINST.isProbeActivated(signature)) {
        return thisJoinPoint.proceed();
    }//from   w w w.  java  2s. c  o m
    // collect data
    final boolean entrypoint;
    final String hostname = VMNAME;
    final String sessionId = SESSIONREGISTRY.recallThreadLocalSessionId();
    final int eoi; // this is executionOrderIndex-th execution in this trace
    final int ess; // this is the height in the dynamic call tree of this execution
    long traceId = CFREGISTRY.recallThreadLocalTraceId(); // traceId, -1 if entry point
    if (traceId == -1) {
        entrypoint = true;
        traceId = CFREGISTRY.getAndStoreUniqueThreadLocalTraceId();
        CFREGISTRY.storeThreadLocalEOI(0);
        CFREGISTRY.storeThreadLocalESS(1); // next operation is ess + 1
        eoi = 0;
        ess = 0;
    } else {
        entrypoint = false;
        eoi = CFREGISTRY.incrementAndRecallThreadLocalEOI(); // ess > 1
        ess = CFREGISTRY.recallAndIncrementThreadLocalESS(); // ess >= 0
        if ((eoi == -1) || (ess == -1)) {
            LOG.error("eoi and/or ess have invalid values:" + " eoi == " + eoi + " ess == " + ess);
            CTRLINST.terminateMonitoring();
        }
    }
    // measure before
    final long tin = TIME.getTime();
    CTRLINST.newMonitoringRecord(
            new OperationExecutionStartRecord(signature, sessionId, traceId, tin, hostname, eoi, ess));
    // execution of the called method
    final Object retval;
    try {
        retval = thisJoinPoint.proceed();
    } finally {
        // measure after
        final long tout = TIME.getTime();
        CTRLINST.newMonitoringRecord(
                new OperationExecutionStopRecord(sessionId, traceId, tout, hostname, eoi, ess));
        // cleanup
        if (entrypoint) {
            CFREGISTRY.unsetThreadLocalTraceId();
            CFREGISTRY.unsetThreadLocalEOI();
            CFREGISTRY.unsetThreadLocalESS();
        } else {
            CFREGISTRY.storeThreadLocalESS(ess); // next operation is ess
        }
    }
    return retval;
}

From source file:ch.icclab.cyclops.util.LogAspect.java

License:Open Source License

@Around("execution(* *(..)) && @annotation(Loggable)")
public void around(ProceedingJoinPoint point) {
    System.out.println(MethodSignature.class.cast(point.getSignature()).getMethod().getName());
    logger.trace("BEGIN ASPECT " + MethodSignature.class.cast(point.getSignature()).getMethod().getName());
    logger.trace("END ASPECT " + MethodSignature.class.cast(point.getSignature()).getMethod().getName());
}

From source file:cn.com.esrichina.gcloud.commons.LicenseLevelCheckAspect.java

@Around("execution(* cn.com.esrichina.gcloud.*.web.resources.*.*(..))")
public Object doCheck(ProceedingJoinPoint pjp) throws Throwable {
    Object target = pjp.getTarget();
    String methodName = pjp.getSignature().getName();
    Class[] parameterTypes = ((MethodSignature) pjp.getSignature()).getMethod().getParameterTypes();
    Method method = target.getClass().getMethod(methodName, parameterTypes);
    LicenseLevelCheck licenseLevelCheck = null;
    if (method != null) {
        licenseLevelCheck = method.getAnnotation(LicenseLevelCheck.class);
    }/*ww  w  .  j a  va 2s  .  co  m*/

    if (licenseLevelCheck == null) {
        try {
            return pjp.proceed();
        } catch (Exception e) {
            throw e;
        }
    } else {
        String needLevel = licenseLevelCheck.level();
        GCloudLicense license = LicenseContext.getInstance().getLicense();
        // if (license == null || license.getLicenseLevel() == null) {
        // throw new
        // RuntimeException(Messages.getMessage("license_not_load"));
        // }

        if (needLevel.equals(GCloudLicense.LEVEL_ADVANCED) && !license.isAdvanced()) {
            throw new RuntimeException(Messages.getMessage("license_level_adv_limit"));
        } else if (needLevel.equals(GCloudLicense.LEVEL_STANDARD) && license.isBasic()) {
            throw new RuntimeException(Messages.getMessage("license_level_adv_limit"));
        }
        try {
            return pjp.proceed();
        } catch (Exception e) {
            throw e;
        }
    }
}

From source file:cn.com.xl.core.aop.BeforeAop.java

License:Apache License

@Around("cutBefore()")
public Object doBefore(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = HttpKit.getRequest();
    MethodSignature ms = (MethodSignature) point.getSignature();
    Method method = ms.getMethod();
    Object[] args = point.getArgs();
    Class<?> clazz = point.getTarget().getClass();
    Before before = method.getAnnotation(Before.class);
    Interceptor ic = before.value().newInstance();
    Object result = ic.intercept(new Invocation(clazz, method, args, request));
    if (null == result) {
        return point.proceed();
    } else {//from w  ww .j av  a 2 s. c o m
        return result;
    }
}

From source file:cn.com.xl.core.aop.PermissionAop.java

License:Apache License

@Around("cutPermission()")
public Object doPermission(ProceedingJoinPoint point) throws Throwable {
    MethodSignature ms = (MethodSignature) point.getSignature();
    Method method = ms.getMethod();
    Permission permission = method.getAnnotation(Permission.class);
    Object[] permissions = permission.value();
    if ((permissions.length == 1 && Func.toStr(permissions[0]).equals("ALL")) || permissions == null
            || permissions.length == 0) {
        //// w  w w .j a va 2  s .  c  om
        boolean result = PermissionCheckManager.checkAll();
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    } else {
        //
        boolean result = PermissionCheckManager.check(permissions);
        if (result) {
            return point.proceed();
        } else {
            throw new NoPermissionException();
        }
    }

}