Search in sources :

Example 41 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project nextprot-api by calipho-sib.

the class InstrumentationAspect method logService.

@Around("execution(* org.nextprot.api.*.service.*.*(..))")
public Object logService(ProceedingJoinPoint pjp) throws Throwable {
    if (enableInstrumentation) {
        serviceRequestId.set(serviceRequestIdCounter.incrementAndGet());
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations();
        Object[] arguments = pjp.getArgs();
        StringBuilder sb = new StringBuilder();
        sb.append("type=Service;");
        addMethodParameters(sb, methodSignature);
        addArgumentsParameters(sb, arguments, annotations);
        sb.append("serviceRequestId=");
        sb.append(serviceRequestIdCounter.get());
        sb.append(";");
        Long cId = serviceRequestId.get();
        if (cId != null) {
            sb.append("controllerRequestId=");
            sb.append(cId);
            sb.append(";");
        }
        long start = System.currentTimeMillis();
        try {
            Object result = pjp.proceed();
            // LOGGER.info("aspect=before;" + sb);
            addTimeElapsed(sb, System.currentTimeMillis() - start);
            addResultParameters(sb, result);
            serviceRequestId.remove();
            LOGGER.info("aspect=after;" + sb);
            return result;
        } catch (Exception e) {
            addTimeElapsed(sb, System.currentTimeMillis() - start);
            addExceptionParameters(sb, e);
            serviceRequestId.remove();
            LOGGER.info("aspect=after;" + sb);
            throw e;
        }
    } else {
        return pjp.proceed();
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) AtomicLong(java.util.concurrent.atomic.AtomicLong) Around(org.aspectj.lang.annotation.Around)

Example 42 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project trafficController by amitkhosla.

the class QueueAnnotationsHandler method getQueueName.

/**
 * Get queue name. If name is passed, the same is returned. In case name is not passed, it is created from join point.
 * For creation, producer's return type and consumer's parameter type is identified.
 * Also if the batch processing (batch put or batch consumer) type is identified from the type of collection.
 * @param name Queue name as passed in Queued or consumer
 * @param joinPoint Join point of the caller method
 * @param shouldVerifyBatch Batch?
 * @param producerOrConsumer Producer or consumer?
 * @return name of queue
 */
protected String getQueueName(String name, ProceedingJoinPoint joinPoint, boolean shouldVerifyBatch, String producerOrConsumer) {
    if (StringUtils.isEmpty(name)) {
        Class returnType = null;
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        String nameFromCache = queueNameMapping.get(method);
        if (!StringUtils.isEmpty(nameFromCache)) {
            return nameFromCache;
        }
        returnType = getTypeForAnnotatedMethodReturnOrFirstParameter(shouldVerifyBatch, producerOrConsumer, signature, method);
        String output = checkPrimitive(returnType);
        queueNameMapping.put(method, output);
        return output;
    }
    return name;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 43 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project trafficController by amitkhosla.

the class QueueAnnotationsHandler method processConsumerDetails.

/**
 * Process queue consumer if configured to.
 * @param queued Queued object
 * @param joinPoint Join point
 * @param obj Object which is sent to queue, to find the method in class
 * @param queueName Name of queue
 * @throws InstantiationException if no bean present in application context and we cannot create instance
 * @throws IllegalAccessException If method is not found
 */
protected void processConsumerDetails(Queued queued, ProceedingJoinPoint joinPoint, Object obj, String queueName) throws InstantiationException, IllegalAccessException {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    if (queueMethodsProcessedForConsumer.containsKey(method)) {
        return;
    }
    if (queued.consumerClass() == Queued.class) {
        queueMethodsProcessedForConsumer.put(method, false);
        return;
    }
    Method actualMethod = getActualConsumerMethod(queued, obj, signature, method);
    registerConsumerForQueued(queued, queueName, method, actualMethod);
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method)

Example 44 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project skeleton-commons by skeleton-software-community.

the class LoggingAspect method getRequestDescription.

private String getRequestDescription(ProceedingJoinPoint joinPoint) {
    String url = "";
    String method = "";
    Class<?> proxiedClass = joinPoint.getTarget().getClass();
    if (proxiedClass.isAnnotationPresent(RequestMapping.class)) {
        RequestMapping requestMapping = proxiedClass.getAnnotation(RequestMapping.class);
        if (requestMapping.value() != null && requestMapping.value().length > 0) {
            url += requestMapping.value()[0];
        }
    }
    Method proxiedMethod = ((MethodSignature) joinPoint.getSignature()).getMethod();
    RequestMapping requestMapping = proxiedMethod.getAnnotation(RequestMapping.class);
    if (requestMapping.value() != null && requestMapping.value().length > 0) {
        url += requestMapping.value()[0];
    }
    if (requestMapping.method() != null && requestMapping.method().length > 0) {
        method = requestMapping.method()[0].name();
    }
    return method + " " + url;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with MethodSignature

use of org.aspectj.lang.reflect.MethodSignature in project skeleton-commons by skeleton-software-community.

the class AccessControlAspect method getAccessControlType.

private AccessControlType getAccessControlType(ProceedingJoinPoint joinPoint) {
    AccessControlType accessControlType = AccessControlType.PRIVATE;
    Method proxiedMethod = ((MethodSignature) joinPoint.getSignature()).getMethod();
    AccessControl accessControl = proxiedMethod.getAnnotation(AccessControl.class);
    if (accessControl != null) {
        accessControlType = accessControl.value();
    }
    return accessControlType;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) AccessControlType(org.sklsft.commons.rest.security.access.AccessControlType) Method(java.lang.reflect.Method) AccessControl(org.sklsft.commons.rest.security.annotations.AccessControl)

Aggregations

MethodSignature (org.aspectj.lang.reflect.MethodSignature)116 Method (java.lang.reflect.Method)95 Around (org.aspectj.lang.annotation.Around)43 JoinPoint (org.aspectj.lang.JoinPoint)30 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 Test (org.junit.Test)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)24 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)13 Signature (org.aspectj.lang.Signature)13 Annotation (java.lang.annotation.Annotation)10 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 List (java.util.List)2 Tick (mysh.util.Tick)2 Ignite (org.apache.ignite.Ignite)2