Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AroundInvoke not called with Quarkus

Tags:

quarkus

I created the following invoking class, which should be invoked, when an intercepted method is called:

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@Interceptor
class TestAspect {

    @AroundInvoke
    public Object log(InvocationContext context) throws Exception {
        System.out.println("AroundInvoke method called");
        return context.proceed();
    }
}

and this resource:

import javax.interceptor.Interceptors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/test")
@Interceptors(TestAspect.class)
public class TestResource {

    @GET
    @Path("/")
    public String test() {
        System.out.println("Resource method called");
        return new String("test");
    }
}

But I only get the log line from the resouce.

like image 599
yogiginger Avatar asked Mar 02 '20 10:03

yogiginger


2 Answers

Per the Quarkus CDI Reference Guide,

  • @Interceptors is not supported

You'll need to add the @Priority, @Interceptor, and your binding annotation to your Interceptor class. See here for an example

like image 195
Keith Herbert Avatar answered Dec 18 '22 17:12

Keith Herbert


You need to activate your interceptor either by defining it in beans.xml or adding @Priority(number) on your interceptor.

like image 38
Serkan Avatar answered Dec 18 '22 18:12

Serkan