Search in sources :

Example 1 with RequestInfo

use of org.nextprot.api.core.aop.requests.RequestInfo in project nextprot-api by calipho-sib.

the class ConcurrentRequestInterceptor method checkNumberOfConcurrentRequest.

/**
 * Checks the number of concurrent requests
 * @param requestInfo
 */
private void checkNumberOfConcurrentRequest(HttpServletRequest request) {
    Object remoteAddr = request.getRemoteAddr();
    if (remoteAddr == null) {
        LOGGER.warn("Can't determine remoteAddr from request");
    } else {
        String addr = remoteAddr.toString();
        int cnt = 0;
        for (RequestInfo r : clientRequestManager.getRequests()) {
            String radr = r.getRemoteAddr();
            if (radr != null && radr.equalsIgnoreCase(addr)) {
                cnt++;
                if (cnt > MAX_CONCURRENT_REQUESTS_NUMBER_PER_USER) {
                    throw TOO_MANY_CONCURRENT_REQUESTS_EXCEPTION;
                }
            }
        }
    }
}
Also used : RequestInfo(org.nextprot.api.core.aop.requests.RequestInfo)

Example 2 with RequestInfo

use of org.nextprot.api.core.aop.requests.RequestInfo in project nextprot-api by calipho-sib.

the class InstrumentationAspect method logServiceInformaton.

@Around("execution(* org.nextprot.api.*.controller.*.*(..))")
public Object logServiceInformaton(ProceedingJoinPoint pjp) throws Throwable {
    if (enableInstrumentation) {
        controllerRequestId.set(controllerRequestIdCounter.incrementAndGet());
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations();
        Object[] arguments = pjp.getArgs();
        RequestInfo request = RequestInfoFactory.createRequestInfo(methodSignature.getDeclaringType().getSimpleName() + "#" + methodSignature.getName());
        request.putAll(extractSecurityInfo());
        request.putAll(extractHttpInfo());
        clientRequestManager.startMonitoringClientRequest(request);
        StringBuilder sb = new StringBuilder();
        sb.append("type=Controller;");
        addMethodParameters(sb, methodSignature);
        addArgumentsParameters(sb, arguments, annotations);
        sb.append("controllerRequestId=");
        sb.append(controllerRequestIdCounter.get());
        sb.append(";");
        for (String key : request.keySet()) {
            sb.append(key);
            sb.append("=");
            sb.append(request.get(key));
            sb.append(";");
        }
        long start = System.currentTimeMillis();
        // Proceed to method invocation
        try {
            // LOGGER.info("aspect=before;" + sb);
            Object result = pjp.proceed();
            addTimeElapsed(sb, System.currentTimeMillis() - start);
            addResultParameters(sb, result);
            LOGGER.info("aspect=after;" + sb);
            clientRequestManager.stopMonitoringCurrentRequestInfo();
            controllerRequestId.remove();
            return result;
        } catch (Exception e) {
            addTimeElapsed(sb, System.currentTimeMillis() - start);
            addExceptionParameters(sb, e);
            LOGGER.info("aspect=after;" + sb);
            clientRequestManager.stopMonitoringCurrentRequestInfo(e);
            controllerRequestId.remove();
            throw e;
        }
    } else {
        return pjp.proceed();
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) RequestInfo(org.nextprot.api.core.aop.requests.RequestInfo) Around(org.aspectj.lang.annotation.Around)

Aggregations

RequestInfo (org.nextprot.api.core.aop.requests.RequestInfo)2 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1