0

Here is the situation. I have a starter which performs checks on every request. I have performed it by creating such an aspect:

    @Around("execution(* (@org.springframework.web.bind.annotation.RestController *).*(..))")
    public Object check(final ProceedingJoinPoint joinPoint) {

        CheckResponse checkResponse = client.check();
        if (checkResponse.getDate().before(new Date())) {
             throw new CheckException("message");
        }
   
        try {
            return joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

Everything worked fine until I needed to use this CheckResponse in my rest controller. How can I get it inside there? I thought about creating request scoped beans inside my aspect and injecting it into controller with spring but I can't figure out how to do it programmatically. I guess another way can be using reflection but I am inclined to more elegant ways. Maybe you have any ideas?

P.S. The controller method has its own parameters such as @RequestParam, and using joinPoint.proceed() can override those parameters. I am trying to make this thing as much universal as possible.

0 Answers0