0 Replies Latest reply on Sep 22, 2014 5:17 PM by Matías Blasi

    How to make EJB2 available for CDI @Inejction in a Servlet

    Matías Blasi Newbie

      Hi,

       

      We have a big application, originally written with EJB2.

      Nowdays we are migrating them to EJB3, and using CDI for dependency injection.

       

      Currently we need some old EJB2 to be @Injected in a Servlet. To being able to @Inject old EJBs into the Servlet, we are trying to use @Producer method the instances, by doing a jndi lookup.

       

      It initially worked, but sometimes jboss faield to start because of the EJB was not already deployed when CDI tried to look for it.

       

      We tried to solve that by ensuring the ejb-module is deployed before the web-module: Manifest module information - JBoss Modules - Project Documentation Editor

       

      It seem to be more stable, but we got the same jboss initialization error a couple of times.

       

      Then we moved to add the servlet dynamicaly in ServletContextListener::contextInitialized.

      We did that hoping that everything has been deployed and ready for our @Producer method.

      And we got the application stable for a longer time, but a couple of days ago, we were seeing this initialization exception during jboss startup, in a couple of servers:

       

      2014-09-19 06:11:03,120 INFO  [org.jboss.ejb.client] (MSC service thread 1-3) JBoss EJB Client version 1.0.5.Final

      2014-09-19 06:11:03,260 ERROR [org.jboss.ejb3.invocation] (MSC service thread 1-3) JBAS014134: EJB Invocation failed on component SfMain for method public abstract api.sfmain.SfMainLocal api.sfmain.SfMainLocalHome.create() throws javax.ejb.CreateException: javax.ejb.EJBException: java.lang.IllegalStateException

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ejb3.component.interceptors.EjbExceptionTransformingInterceptorFactories$2.processInvocation(EjbExceptionTransformingInterceptorFactories.java:89) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

        at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

        at api.sfmain.SfMainLocalHome$$$view381.create(Unknown Source) [saturn.jar:]

       

       

      Then I found this thread: Re: Get IllegalStateException when lookup EJB in ContextListener of web module, where someone says "There's not guarantee that the correct dependency will be setup for the EJB to be available"

      Then, we are really not sure about where to put the ejb jndi lookup to get our @Producer method working properly.

       

      Let me know if is there some other technique for making CDI+PRODUCE+JNDI EJB LOOKUP working properly.

       

      Best regards,

      Matías.