0

I would like to intercept calls to methods conversation.begin() and conversation.end().

To do this, I have developed an interceptor binding that I aim to dynamically assign to the Conversation class through a CDI portable extension.

However, I can not find how to access to the Conversation class since it is not observed in the ProcessAnnotatedType event where usually i do this process to my defined beans.

See the code as an example:

public class MethodCallsInterceptorExt implements Extension {
        
    void processAnnotatedType(@Observes ProcessAnnotatedType<?> event) {  
        if (isConvesationBean(event)) { // This condition is never true
            event.configureAnnotatedType().add(new MyInterceptorBinding());
        }
    }
}

Is this solution at least partially correct? Is there any viable way to do this?

1 Answers1

0

You could do something like this:

public class ConversationObserver {

    public void onStart(@Observes @Initialized(ConversationScoped.class) ServletRequest request) {}

    public void onEnd(@Observes @Destroyed(ConversationScoped.class) ServletRequest request) {}
}

See https://docs.jboss.org/cdi/api/2.0/javax/enterprise/context/ConversationScoped.html

Xavier Dury
  • 1,530
  • 1
  • 16
  • 23