2 Replies Latest reply on Jul 17, 2011 8:03 PM by ozizka

    weld-se-core + weld-servlet-core -> interceptor not working

    ozizka
      Hi all,

      I have a non-typical application, which uses weld-se-core, and one of it's modules uses weld-servlet-core in embedded Jetty 6.

      1) Debugging reveals that BeanManager is initialized twice. Which means, methods like addBeans() are called twice. First when the app boots up, then when Jetty boots, with this call stack:

      ****************

      Is that ok?


      2) I have an intercepted class, @JpaTransactional, which works when used without weld-servlet-core (in other module which does not have weld-servlet-core, and the web module is not on classpath at all).
      When used from a servlet, the interceptor does not work - seems like it's not called at all.

      I think I have it properly configured.
      My suspicion is that the problem is that BeanManager is initialized twice and somehow they don't cooperate. I'm not sure how this should work, but intuitively, I guess only one BeanManager per JVM should exist and should be looked up everywhere it's needed.

      Log snippets:

      ------------------------------
      Specialized beans: 0
      : [<class>org.jboss.weld.environment.se.jpa.JpaTransactionInterceptor</class> in jar:file:/mnt/ssd1/data/.m2/repository/org/jboss/jawabot/JawaBot-core/2.0.0-SNAPSHOT/JawaBot-core-2.0.0-SNAPSHOT.jar!/META-INF/beans.xml@11]

      // This is when app's core starts
      08:34:03.259 DEBUG [main] org.jboss.weld.Bootstrap  WELD-000107 Interceptor: Interceptor [class org.jboss.weld.environment.se.jpa.JpaTransactionInterceptor intercepts @JpaTransactional]

      08:34:03.557 DEBUG [main] org.jboss.weld.Bootstrap  WELD-000106 Bean: Managed Bean [class org.jboss.jawabot.plugin.pastebin.JpaPasteBinManager] with qualifiers [@Any @Default]

      /// This is when Jetty starts / inits context
      08:50:34.301 DEBUG [main] org.jboss.weld.Bootstrap  WELD-000107 Interceptor: Interceptor [class org.jboss.weld.environment.se.jpa.JpaTransactionInterceptor intercepts @JpaTransactional]

      08:50:34.322 DEBUG [main] org.jboss.weld.Bootstrap  WELD-000106 Bean: Managed Bean [class org.jboss.jawabot.plugin.pastebin.JpaPasteBinManager] with qualifiers [@Any @Default]
      ------------------------------

      Code snippets:

      ------------------------------
      @Interceptor
      @JpaTransactional
      public class JpaTransactionInterceptor {
        ...
        @AroundInvoke public Object runInTransaction( InvocationContext ic ) throws Exception { ... }
      }

      ------------------------------
      public class PasteBinPage extends BaseLayoutPage
      {
         // This works fine.
         @Inject private JpaPasteBinManager pbManager;

         init() {
           List<PasteBinEntry> entries = pbManager.getLastPastes(100);
         }
      }
      ------------------------------
      @ApplicationScoped
      public class JpaPasteBinManager implements IPasteBinManager, EntitiesPackagesProvider
      {
         // This works fine - injects org$jboss$weld$bean-flat-ManagedBeanclass_org$jboss$weld$environment$se$jpa$EntityManagerDelegate_$$_WeldClientProxy
         @Inject private EntityManager em;

         @JpaTransactional
         public synchronized boolean addEntry( PasteBinEntry e ) {
            em.persist(e);
            return true;
         }
      }
      ------------------------------
      @InterceptorBinding
      @Inherited
      @Target({ElementType.METHOD, ElementType.TYPE})
      @Retention(RetentionPolicy.RUNTIME)
      public @interface JpaTransactional { }
      ------------------------------

      Thanks for any tips.
      Ondra