Interceptors and obtaining interceptor bindings

77 views
Skip to first unread message

Arjan Tijms

unread,
Oct 13, 2017, 9:34:46 AM10/13/17
to Eclipse MicroProfile
MicroProfile defines several CDI interceptor bindings for use with Interceptors. E.g. @BulkHead: https://microprofile.io/project/eclipse/microprofile-fault-tolerance/spec/src/main/asciidoc/bulkhead.asciidoc

At Payara we're implementing these now, but hit an implementation impediment where it's actually not really possible to obtain the interceptor binding annotations in such a way that it works for all cases.

The default way of getting the interceptor binding annotation from the target method fails when the annotation has been dynamically added via either a CDI extension or an interceptor factory.

E.g. 

interceptionFactory
            .configure()
            .filterMethods(am -> am.getJavaMember().getName().equals("foo"))
            .forEach(
                amc -> amc.add(new BulkHeadLiteral(5)));


Unfortunately there's no standard way to get the interceptor binding annotation here from the interceptor, so no way to get the '5' that the interceptor needs to do its work.

This problem has been recognised by the CDI spec: https://issues.jboss.org/browse/CDI-468 however no action has been taken for it for now.

A somewhat similar problem occurs when the annotation is part of a stereotype. In that case one needs to recurse into the stereotype in order to get to the actual interceptor binding annotation.

It's, more or less, implied that the interceptor should 'just work' in all cases, but I wonder how the other implementations approach this problem.

As many of us here are also involved with the CDI spec, maybe CDI-468 should be given somewhat more priority, so that it at least will be easier for newer versions?

John D. Ament

unread,
Oct 13, 2017, 1:15:42 PM10/13/17
to Eclipse MicroProfile
Arjan,

I saw your messages on the CDI EG and OWB JIRA.  I'm a bit confused by what you're trying to do.

When you mention InterceptionFactory, are you referring to the CDI 2.0 class or something else?

John

Arjan Tijms

unread,
Nov 6, 2017, 7:20:25 AM11/6/17
to Eclipse MicroProfile
Hi,


On Friday, October 13, 2017 at 6:15:42 PM UTC+1, John D. Ament wrote:
Arjan,

I saw your messages on the CDI EG and OWB JIRA.  I'm a bit confused by what you're trying to do.

When you mention InterceptionFactory, are you referring to the CDI 2.0 class or something else?

Indeed, the CDI 2.0 class. But the same holds for adding the annotation dynamically via a CDI extension.

John D. Ament

unread,
Nov 6, 2017, 5:24:48 PM11/6/17
to Eclipse MicroProfile
Arjan,

Yes, I noted your use case on the open CDI spec issue.  Basically, anytime an interceptor is added with non-binding nature, its actual runtime information is unavailable to you.  This happens for:

- extension added annotations
- factory (as you noted)
- stereotypes

The only reliable way is if its directly annotated.  You can work around with stereotype by interrogating each annotation to find it.  I don't even believe that it will work in a non-portable way either, I think it just doesn't exist.

for the record, this was one of the reasons why I didn't want these to be interceptor bindings, instead just configuration.

I do hope we'll resolve this in CDI 2.1.

John

Arjan Tijms

unread,
Dec 16, 2017, 5:57:31 AM12/16/17
to Eclipse MicroProfile
So the question is, how to best solve it.

Since the Interceptor Spec is frozen for the moment, two solutions may be:

- Retrieve the bindings via a standardised key, such as Weld already does with its own key
- Inject an extra extended, CDI specific context, similar as to how @Inject @Intercepted basically injects extended info about the target

Thoughts?

Kind regards,
Arjan Tijms
Reply all
Reply to author
Forward
0 new messages