All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.usf.inspect.rest.ControllerAdviceTracker Maven / Gradle / Ivy

Go to download

INtegrated System Performance Evaluation and Communication Tracking core libray

There is a newer version: 0.0.18
Show newest version
package org.usf.inspect.rest;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.usf.inspect.core.Helper.localTrace;
import static org.usf.inspect.core.Helper.warnNoActiveSession;

import java.util.stream.Stream;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.usf.inspect.core.ExceptionInfo;
import org.usf.inspect.core.RestSession;

/**
 * 
 * @author u$f
 *
 */
@Aspect 
public class ControllerAdviceTracker {

    @Around("within(@org.springframework.web.bind.annotation.ControllerAdvice *)")
    Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
		var session = (RestSession) localTrace.get();
		if(isNull(session)) {
			var sign = joinPoint.getSignature();
			warnNoActiveSession(sign.getName() + "::" + sign.getDeclaringTypeName()); //TD check this
		}
		else if(nonNull(joinPoint.getArgs())) {
			Stream.of(joinPoint.getArgs())
					.filter(Throwable.class::isInstance)
					.findFirst() //trying to find the exception argument
					.map(Throwable.class::cast)
					.map(ExceptionInfo::mainCauseException)
					.ifPresent(session::setException);
		}
		return joinPoint.proceed();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy