Well, if you know the target class is going to be a CDI bean, then you can use CDI
extension with ProcessAnnotatedType.
There you modify the annotations by adding an interceptor binding of whichever interceptor
you want.
E.g. in your CDI extension, you are going to have something along these lines:
public void observePAT(@Observes ProcessAnnotatedType<?> pat) {
// with <?> the event is fired for all annotated types, you need to do filtering
if (isPatOfTheTypeWeWantToIntercept(pat)) {
pat.configureAnnotatedType().add(interceptorBindingAnnotation);
}
}
Once that is in place and the interceptor has the same binding and is enabled (has
priority), then you should be good.
Matej
----- Original Message -----
From: "Rebecca Searls" <rsearls(a)redhat.com>
To: "Matej Novotny" <manovotn(a)redhat.com>
Cc: weld-dev(a)lists.jboss.org
Sent: Tuesday, July 23, 2019 2:13:04 PM
Subject: Re: [weld-dev] Creating default interceptor for EJBs
It is true the customer code has no interceptor binging. We have no
control over the EJB
definition the user provides. We do know that any interceptor class the
customer provides
in the @Interceptors annontation will have a @PostConstruct annotation. Is
it possible to
programmatically associate an interceptor with that?
On Tue, Jul 23, 2019 at 4:06 AM Matej Novotny <manovotn(a)redhat.com> wrote:
> Hello,
>
> I am not quite sure I follow what are you trying to achieve here.
>
> I can see you are trying to register a synthetic interceptor via
> WeldAfterBeanDiscovery.addInterceptor().
> What I am missing is how do you bind this interceptor to your
> PostConstructInjectionEJBResource?
> Because interceptors registered via WeldAfterBeanDiscovery are those that
> work on based on interceptor bindings and there is no binding on your
> Resource class.
>
> Could you elaborate a little please?
> Matej
>
> ----- Original Message -----
> > From: "Rebecca Searls" <rsearls(a)redhat.com>
> > To: weld-dev(a)lists.jboss.org
> > Sent: Monday, July 22, 2019 8:37:16 PM
> > Subject: [weld-dev] Creating default interceptor for EJBs
> >
> >
> > Resteasy would like to address the following scenario with a default
> > interceptor
> > that is executed after classes defined in an @Interceptors stmt are
> executed.
> >
> > For example a customer provides an EJB with a defined @Interceptors stmt.
> >
> > @Path("/ejb")
> > @Stateless
> > @Interceptors ({PostConstructInjectionEJBInterceptor.class})
> > public class PostConstructInjectionEJBResource {
> > @Size(max=3)
> > private String t = "yz";
> >
> > @Path("get")
> > @GET
> > public String get() {
> > return t;
> > }
> >
> > public void setT(String t) {
> > this.t = t;
> > }
> > }
> >
> > Resteasy provides a CDI extension class, ResteasyCdiExtension. This is
> where
> > I am trying to made the addition. I've reviewed the Weld docs and tried
> > wrapping the class with an @Interceptor both with and without @Priority;
> > using WeldAfterBeanDiscovery's addInterceptor method all without success.
> >
> > Would you provide advise as to how best to address this?
> >
> > _______________________________________________
> > weld-dev mailing list
> > weld-dev(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/weld-dev
>