1 Reply Latest reply on Apr 24, 2014 4:36 AM by Wolf-Dieter Fink

    Using interceptor from another deployed module

    Samuli Saarinen Newbie

      Hi,

       

      On Wildfly 8.1.CR1 I'm trying to use Interceptor that is part of another deployment (ejb module within an ear) and use it on and ejb that is being deployed as separate war (not part of the ear). I have arquillian test that try to simulate the situation. I'll post relevant parts of the code below to show the situation better.

       

      Interceptor is as follows:

      public class ProfilingInterceptor {
      
          public static int postConstructs;
        
          @PostConstruct
          public void aroundPostConstruct(final InvocationContext invocation) {
              postConstructs++;
              invocation.proceed();
          }
      }
      
      

       

      EJB that should be intercepted

      @Singleton @Startup
      public class DummyService {
      
          @PostConstruct
          public void init() {
              System.out.println("Start");
          }
      }
      
      

       

      Arquillian deployment

      @Deployment(name = "app", order = 1, testable = false)
      public static Archive<?> createDependencyEar() {
          JavaArchive javaArchive = ShrinkWrap
                  .create(JavaArchive.class, "dep.jar")
                  .addClass(ProfilingInterceptor.class)
                  .addAsManifestResource("jandex.idx");
      
          EnterpriseArchive archive = ShrinkWrap.create(EnterpriseArchive.class,
                  "app.ear")
                  .addAsModule(javaArchive)
                  .addAsApplicationResource("application.xml");
      
          return archive;
      
      }
      
      @Deployment(name = "test", order = 2)
      public static Archive<?> createDeployment5() {
          WebArchive archive = ShrinkWrap.create(WebArchive.class, "test2.war")
                  .addClass(DummyService.class)
                  .addAsWebInfResource("ejb-jar.xml", "ejb-jar.xml")
                  .addAsWebInfResource("jboss-deployment-structure.xml");
          System.out.println(archive.toString(true));
          return archive;
      }
      

       

      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd"
          version="3.2">
          <interceptors>
              <interceptor>
                  <interceptor-class>com.test.ProfilingInterceptor</interceptor-class>
              </interceptor>
          </interceptors>
      
          <assembly-descriptor>
              <interceptor-binding>
                  <ejb-name>*</ejb-name>
                  <interceptor-class>com.test.ProfilingInterceptor</interceptor-class>
              </interceptor-binding>
          </assembly-descriptor>
      </ejb-jar>
      

       

      jboss-deployment-structure.xml

      <?xml version='1.0' encoding='UTF-8'?>
      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
          <deployment>
              <dependencies>
                  <module name="deployment.app.ear.dep.jar" export="true" />
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      

       

      I have tried to use jandex as described in some other questions but so far no luck. Also I can specify annotations="true" for the dependent module but that makes the deployment fail. and meta-inf="import" or "export" makes no difference. Only way I can get it to work is if I define the post-construct method in the ejb-jar.xml like so

      ...
      <post-construct>
          <lifecycle-callback-method>aroundPostConstruct</lifecycle-callback-method>
      </post-construct>
      ...
      

       

      This leads me to the conclusion that the annotations are not being picked up from the interceptor. Is there anyone that might have this working and could guide me to the right direction?

       

      Thanks,

       

      Samuli