[cdi-dev] Interceptor bindings from interceptor when using 2.0 interception factory

arjan tijms arjan.tijms at gmail.com
Tue Sep 19 07:37:43 EDT 2017


Hi,

On Mon, Aug 28, 2017 at 9:41 AM, Martin Kouba <mkouba at redhat.com> wrote:

> Set<Annotation> bindings = (Set<Annotation>) invocationContext.getContextDa
>> ta().get("org.jboss.weld.interceptor.bindings");
>>
>
> In fact, a more safe way is to use the Weld API, cast the invocation
> context to org.jboss.weld.interceptor.WeldInvocationContext and use the
> appropriate methods.


Looking in the code that seems to do the same thing, at least in Weld 3.0.1.

Going via getContextData() is much easier though for code that has to
support both Weld and OWB.



>
>> Yes. There is already a spec issue: https://issues.jboss.org/brows
> e/CDI-468 but this would require a change in interceptors spec.


I read the issue, thanks for the pointer. I do wonder if the entry in the
context data isn't the easiest option regardless. That might only require
an update in the CDI spec. Essentially, just standardise the key being used?

Currently the interceptor factory is an absolutely fantastic feature, but
its usefulness is greatly diminished by the fact that no interceptor at
this moment can (reliably) retrieve the interceptor bindings for all CDI
implementations.

The spec even uses dynamically adding @Transactional as an example;

 * <pre>
 * &#64;Produces
 * &#64;RequestScoped
 * public MyClass produceMyClass(InterceptionFactory<MyClass> factory) {
 *     factory.configure().add(new AnnotationLiteral<Transactional>() {
 *     });
 *     return factory.createInterceptedInstance(new MyClass());
 * }


But all the current interceptor implementations backing @Transactional do
something like:

public Object proceed(InvocationContext ctx) throws Exception {
        Transactional transactionalAnnotation =
                ctx.getMethod().getAnnotation(Transactional.class);

So that clearly won't work.

The spec text for InterceptionFactory also doesn't mention this caveat at
all. So I wonder, what was the intended approach for   InterceptionFactory
and intercepter bindings with attributes?

Or was InterceptionFactory solely intended for intercepter bindings without
(non-binding) attributes?

Kind regards,
Arjan Tijms




>
>
>
>> Is there a standard way to get the bindings? Perhaps getting hold of the
>> Bean<T> that represents the current Interceptor?
>>
>
> You can inject a bean with scope @Dependent, qualifier @Default and type
> Interceptor into any interceptor instance. However, this will not help for
> @Nonbinding value members of an interceptor binding.
>
>
>> Kind regards,
>> Arjan Tijms
>>
>>
>> _______________________________________________
>> cdi-dev mailing list
>> cdi-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>>
>> Note that for all code provided on this list, the provider licenses the
>> code under the Apache License, Version 2 (http://www.apache.org/license
>> s/LICENSE-2.0.html). For all other ideas provided on this list, the
>> provider waives all patent and other intellectual property rights inherent
>> in such information.
>>
>>
> --
> Martin Kouba
> Senior Software Engineer
> Red Hat, Czech Republic
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20170919/bf71e020/attachment-0001.html 


More information about the cdi-dev mailing list