10 Replies Latest reply: Apr 2, 2012 10:27 AM by Lars Fischer RSS

Interceptor from other EAR?

Lars Fischer Newbie

Hello,

 

I need to partition an JEE app into multiple .EARs. One of them acts as a kind on lib and provides base classes etc for the other EARs.

 

Now I would like to use some interceptors and tried to place the interceptor implementation in the base .EAR. The other .EARs have a manifest.mf defining a dependency to the base .EAR and a

beans.xml using this interceptor as entry.

 

Trying to deploy such .EAR, I only get an "org.jboss.weld.exceptions.DeploymentException", that the configured interceptor "is neither annotated @Interceptor nor registered through a portable extension". But my implementation uses the @Interceptor annotation.

 

Do I have to create a portable CDI extension? Can my base .EAR act so, that I only have one .EAR containing this class without the need to copy it as lib into all other .EARs?

 

 

Regards,

Lars

  • 1. Re: Interceptor from other EAR?
    Ales Justin Master

    Is this the right @Interceptor annotation?

  • 2. Re: Interceptor from other EAR?
    Lars Fischer Newbie

    Hello Ales,

    Ales Justin schrieb:

     

    Is this the right @Interceptor annotation?

     

    I use "javax.interceptor.Interceptor".

     

    If I copy the Interceptor-class into the other .EARs, then they can be deployed, but not, if the class comes from the one base .EAR.

     

    The class itself is visible to the other EARs, I tryied to access the class and this also works fine. So it its no dependency problem.

     

    Regards,

    Lars

  • 3. Re: Interceptor from other EAR?
    Ales Justin Master

    Did you enable this interceptor in (the right) beans.xml?

  • 4. Re: Interceptor from other EAR?
    Marko Lukša Apprentice

    Lars, so your setup looks like this:

    ear1:

        MyInterceptor.class

        beans.xml

     

    ear2:

        MyInterceptedBean.class

        beans.xml (contains: <interceptor>MyInterceptor</interceptor>)

     

    And ear2 has a dependency on ear1?

  • 5. Re: Interceptor from other EAR?
    Ales Justin Master

    This is the code that throws this:

     

        private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager) {

            Set<Class<?>> interceptorBeanClasses = new HashSet<Class<?>>();

            for (Interceptor<?> interceptor : beanManager.getAccessibleInterceptors()) {

                interceptorBeanClasses.add(interceptor.getBeanClass());

            }

            for (Metadata<Class<?>> enabledInterceptorClass : beanManager.getEnabled().getInterceptors()) {

                if (!interceptorBeanClasses.contains(enabledInterceptorClass.getValue())) {

                    throw new DeploymentException(INTERCEPTOR_NOT_ANNOTATED_OR_REGISTERED, enabledInterceptorClass);

                }

            }

        }

     

    So, imo, it looks like class-loading issue ...

     

    As "interceptorBeanClasses" map doesn't contain your enabled interceptor class,

    which looks strange, as I would expect that accessible interceptors would be the same.

  • 6. Re: Interceptor from other EAR?
    Lars Fischer Newbie

    Ales Justin schrieb:

     

    Did you enable this interceptor in (the right) beans.xml?

     

    I enabled the interceptor inside the dependent other .EARs. not in the base .EAR.

    Is this the right place?

  • 7. Re: Interceptor from other EAR?
    Lars Fischer Newbie

    Hello Marko,

     

    yes this is how I tried it:

     

    BASE.ear:

      - BASE.ejb

        -- MyInterceptor.class 

     

    OTHER.ear:

      - OTHER.ejb

        -- MyInterceptedBean.class

        -- beans.xml (contains: <interceptor>MyInterceptor</interceptor>)

        -- MANIFEST.MF (Dependencies: deployment.BASE.ear.BASE.ejb)

     

    Regards,

    Lars

  • 8. Re: Interceptor from other EAR?
    Marko Lukša Apprentice

    As Aleš said, it's probably a class-loading thing. Are you bundling weld jars with your app?

  • 9. Re: Interceptor from other EAR?
    Ales Justin Master

    OK, I think I know where the problem is.

    The code + msg actually tell us whatr's wrong. ;-)

     

    The classes are all fine, it's simply that your dependant app doesn't have that interceptor as bean.

    It does see the class and all, but it's not a bean, as we didn't scan it in the right app nor it was added via extension.

     

    So, yes, you need an explicit extension, and register the interceptor there.

  • 10. Re: Interceptor from other EAR?
    Lars Fischer Newbie

    Marko Lukša schrieb:

     

    As Aleš said, it's probably a class-loading thing. Are you bundling weld jars with your app?

     

    I build my files with maven and all dependencies to CDI come from the jboss-javaee-6.0 spec with scope=provided.

    There are no weld libs in my artefacts.

     

    It may be a class-loading problem, but I don't know how to solve it. As said: trying to access the interceptor class directly in the dependent .EARs code, works fine. They can reach the class. Only the CDI context can not use them.

     

    Should this work, if I create a JBoss module containing the interceptor class? From my knowledge, this is similar than declaring a "deployment" dependency to the contents of the BASE.ear.

     

    Regards,

    Lars