Why I am unable to wrap the execution of a request with an @Around advice?

39
June 22, 2022, at 12:30 PM

I work on a REST API, and I'd like to do some very simplistic tests to see how long it takes to process a request.

I could do this using curl, but I'd like to time the application only (and not latency, network etc.).

I've picked AspectJ to do this. I'm sure there are other tools, but I chose AspectJ to learn something new as well.

First; the below piece of code works. The beforeAdvice and afterAdvice runs fine, and outputs the execution time.

@Configuration
public class AOPConfig {
    @Aspect
    @Component
    public class ResourceAspect {
        @Before(value = "execution(public * com.example.api.web.resource..*.*(..))")
        public void beforeAdvice(JoinPoint joinPoint) {
            System.setProperty("now", System.currentTimeMillis() + "");
        }
        @After(value = "execution(public * com.example.api.web.resource..*.*(..))")
        public void afterAdvice(JoinPoint joinPoint) {
            long then = Long.parseLong(System.getProperty("now"));
            System.out.println(System.currentTimeMillis() - then);
        }
    }
}

Now, I would like to hook into the request handling as early as possible. So I figured I could wrap the execution of :

  • org.apache.coyote.http11.Http11Processor.process() or
  • org.apache.catalina.connector.CoyoteAdapter.service()

The below does not work (nothing gets printed) :

@Configuration
public class AOPConfig {
    @Aspect
    @Component
    public class ResourceAspect {
        //@Around(value = "execution(public * org.apache.coyote.http11.Http11Processor.process(..))")
        @Around(value = "execution(* org.apache.catalina.connector.CoyoteAdapter.service(..))")
        public Object around(final ProceedingJoinPoint joinPoint) throws Throwable {
            try {
                System.out.println("BEGIN");
                return joinPoint.proceed();
            } finally {
                System.out.println("END");
            }
        }
}

Looking at this stack trace, I figured I could wrap either Http11Processor or CoyoteAdapter with @Around.

Is there a limitation of which classes I can work with, or is there anything else I'm missing to get the @Around advice above to work?

READ ALSO
removeRow using XSSF libraries is not working

removeRow using XSSF libraries is not working

I tried the below code, but it's not working

71
WatchService watching files on distributed filesystem from multiple machines

WatchService watching files on distributed filesystem from multiple machines

I am trying to implement a WatchService that watches a filesystem for changesOnce files get created I want to create tasks for each new file and add that task to a distributed queue to let it get processed from multiple machines

36
Accessing local database from kubernetes cluster

Accessing local database from kubernetes cluster

I have a database running in local machine which i can access it using 1270

59
Handler in addValueEventListener running continuously

Handler in addValueEventListener running continuously

Im making a Uber clone app and whenever the driver receives a request he can accept it or decline it, but I want to add a feature where if the driver doesn't accept or decline the request within 8 second I want to decline it automatically

57