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

Martin Kouba mkouba at redhat.com
Mon Aug 28 03:41:07 EDT 2017


Hi Arjan,

comments inline...

Dne 21.8.2017 v 13:45 arjan tijms napsal(a):
> Hi,
> 
> Normally a workaround to get the interceptor bindings from within an 
> Interceptor is to inspect the target and/or the injected intercepted bean.
> 
> However, when adding an interceptor via the new CDI 2.0 interception 
> factory, things become a bit more muddy.
> 
> See e.g.
> 
> https://github.com/javaee-samples/javaee8-samples/blob/master/cdi/interception-factory/src/main/java/org/javaee8/cdi/interception/factory/MyGreetingProducer.java#L34
> 
> 
> Weld has the following method to get the bindings from the 
> InvocationContext:
> 
> Set<Annotation> bindings = (Set<Annotation>) 
> invocationContext.getContextData().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.

> 
> But this is obviously non-standard.

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

> 
> 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/licenses/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


More information about the cdi-dev mailing list