[GLASSFISH-21407] CDI Interceptors packaged in jar does are not read Created: 06/Aug/15  Updated: 28/Sep/15  Resolved: 28/Sep/15

Status: Closed
Project: glassfish
Component/s: cdi
Affects Version/s: 4.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: fmateo Assignee: jjsnyder83
Resolution: Works as designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
  • OS : Windows 7 - 32 bits
  • Java 8_31

Tags: beans.xml, cdi, discovery


I am developing a web application. It is deployed as a WAR file.
This application is implemented using JEE 7: CDI and REST.

I have a requirement for caching certain web service calls. To do this, I use JCache standard and the reference CDI jcache annotations implementation (cache-annotations-ri-cdi-1.0.0.jar).

cache-annotations-ri-cdi-1.0.0.jar contains a beans.xml file in the META-INF directory which should be discovered by the container automatically. But it doesn't. The beans.xml in the jar looks like this

<beans xmlns="http://java.sun.com/xml/ns/javaee"

In my application WEB-INF directory I have placed an empty beans.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">


I placed an annotation @CacheResult over a business method which should be intercepted by the registered jCache interceptors.
It didn't work in my initial test.
The only way to make it works I found was to register jsr107 interceptors in the WEB-INF/beans.xml of the application.

As far as I understand CDI spec, the discovery should be done automatically.

Comment by jjsnyder83 [ 06/Aug/15 ]

Try adding @Priority to the interceptor.

Comment by fmateo [ 07/Aug/15 ]

The problem is that the interceptor is packaged into the Jcache cdi reference implementation (cache-annotations-ri-cdi-1.0.0.jar). I'm just a client of this RI using the jar so I can not annotate the interceptor.

If you are suggesting that there's some bug in the RI, I can download source code and try that modification.

Comment by jjsnyder83 [ 07/Aug/15 ]

No I don't think there's a bug. If the interceptor is not annotated with @Priority then you must enable it via beans.xml.

Comment by fmateo [ 07/Aug/15 ]

Looking at interceptor source code from Jcache ri :

public class CacheResultInterceptor extends AbstractCacheResultInterceptor<InvocationContext> {


The interceptor is not annotated with @Priority. But it is declared into META-INF/beans.xml in the jar file.
Shouldn't the container discover it anyway?

Comment by jjsnyder83 [ 08/Aug/15 ]

Iirc you have to put it in all beans.xml of the jars in which the interceptor is used. So if a class in jar a is using an interceptor in jar b then jar a's beans.xml must have the interceptor enabled in it.

Comment by fmateo [ 08/Aug/15 ]

Thank you, you are completely right.
I checked out the Bean discovery section in CDI spec 1.2 . Interceptors and Decorators are only enabled for the bean archive which defines them. The application need to explicity enable them.

Generated at Sun Oct 04 10:42:35 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.