4 Replies Latest reply on Dec 16, 2010 6:31 AM by jaikiran

    Can not access EJB from a Quartz job-class in JBoss 6.0.0CR1 - Quartz service is a MBean

    jbossuser71

      Hi All,
      I am using JBoss 6.0.0.CR1 release (in default configuration) and Quartz1.8.4 library - I have configurred Quartz as MBean Service.
      As per Jboss/Quartz integration tutorial  I have removed existing Quartz libraries from ${jboss}/server/common/lib and replace them with quartz-1.8.4.jar and quartz-jboss-1.8.4.jar

      I have also removed "quartz-ra.rar" from the "${jboss}/server/default/deploy" folder and put the quartz service definition xml file in ${jboss}/default/deploy directory.

       

      My workflow is: from my Startup-Servlet (WAR) I invoke an EJB which  accesses Quartz scheduler service and creates jobs in quartz scheduler.

      The Quartz service comes up fine and I can schedule jobs as long as my job class does not access any EJB.
      But if my job class tries to access any of the EJBs deployed in JBoss, I get following error.
      ====================================
      2010-12-15 14:43:17,623 ERROR [org.quartz.core.JobRunShell] (EdmQuartzScheduler_Worker-1) Job DEFAULT.EdmHoldJob threw an unhandled Exception: : java.lang.RuntimeException: Specified calling class, com.im.server.edm.api.HoldRemote could not be found for BaseClassLoader@100c0aa{vfs:///C:/Workspace/DM1.0/dependencies/repository/appserver/server/default/deploy/edm-quartz-service.xml}
          at org.jboss.ejb3.common.lang.SerializableMethod.getClassFromName(SerializableMethod.java:311) [:1.0.2]
          at org.jboss.ejb3.common.lang.SerializableMethod.getClassType(SerializableMethod.java:282) [:1.0.2]
          at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:233) [:1.0.2]
          at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:220) [:1.0.2]
          at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:178) [:1.0.11]
          at $Proxy199.issueHold(Unknown Source)    at com.im.server.edm.jobs.EdmHoldJob.execute(EdmHoldJob.java:52)
          at org.quartz.core.JobRunShell.run(JobRunShell.java:216) [:]
          at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [:]
      Caused by: java.lang.ClassNotFoundException: com.im.server.edm.api.HoldRemote from BaseClassLoader@100c0aa{vfs:///C:/Workspace/DM1.0/dependencies/repository/appserver/server/default/deploy/edm-quartz-service.xml}
          at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.Alpha9]
          at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_18]
          at java.lang.Class.forName0(Native Method) [:1.6.0_18]
          at java.lang.Class.forName(Class.java:247) [:1.6.0_18]
          at org.jboss.ejb3.common.classloader.util.PrimitiveClassLoadingUtil.loadClass(PrimitiveClassLoadingUtil.java:99) [:1.0.2]
          at org.jboss.ejb3.common.lang.SerializableMethod.getClassFromName(SerializableMethod.java:307) [:1.0.2]
          ... 8 more

      =============================================

       

      I understand it is a class loader issue and since the Quartz MBean is loaded by BaseClassLoader and the EJBs are by different classloader, I can not access EJB from the job-class loaded by Quartz.
      I found the following useful tutorial link, which is applicable for JBoss 4.2.2.GA. It has information for the similar classloading issue with Quartz.
      http://community.jboss.org/wiki/HowtoconfigureaQuartzservice

       

      Since my Job definition class does access other classes in  ear, I need to deploy Quartz service after my ear is deployed.
      So I have edited the quartz service definition as shown below.
      =======================
      <?xml version="1.0" encoding="UTF-8"?> <server>
         <mbean code="org.quartz.ee.jmx.jboss.QuartzService"
                name="user:service=QuartzService,name=QuartzService">
         <depends>jboss.j2ee:service=EARDeployment,url='myapp.ear'</depends>      

          <attribute name="JndiName">Quartz</attribute>    
          <attribute name="Properties">       
               org.quartz.scheduler.instanceName = QuartzScheduler
               org.quartz.scheduler.rmi.export = false
               org.quartz.scheduler.rmi.proxy = false
               org.quartz.scheduler.xaTransacted = false
               org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool 
               org.quartz.threadPool.threadCount = 5
               org.quartz.threadPool.threadPriority = 4
               org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 
           </attribute>    
         </mbean>
      </server> 
      =======================
      But still with this modification, when I am trying to access 'Qartz' from my WAR module, I get following NameNotFoundException.
      =======================
      15:13:32,962 ERROR [[/edm]] StandardWrapper.Throwable: javax.ejb.EJBException: java.lang.IllegalStateException: javax.naming.NameNotFoundException: Quartz not bound

       

              at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:183) [:0.0.1]
              at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:251) [:0.0.1]
              at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.required(CMTTxInterceptor.java:349) [:0.0.1]
              at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invoke(CMTTxInterceptor.java:209) [:0.0.1]
              at org.jboss.ejb3.tx2.aop.CMTTxInterceptorWrapper.invoke(CMTTxInterceptorWrapper.java:52) [:0.0.1]
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.Alpha3]
              at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) [:1.0.0.GA]
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.Alpha3]

      ========================

       

      In the same tutorial link, author talks about changing folowing line in ${jboss.server}/deploy/jboss-web.deployer/META-INF/jboss-service.xml file.
          <attribute name="UseJBossWebLoader">false</attribute>
         
      But in 6.0.0.CR1 release I could not locate this file.
      Can anyone pls. tell me where this file is now being packaged in JBoss 6.x - or how can I resolve this issue?

       

      Wondering if I instantiate Quartz as a Servlet, I may not face this classloading issue - am I right?

       

      Thanks in advance.
      - Kuntal

        • 1. Re: Can not access EJB from a Quartz job-class in JBoss 6.0.0CR1 - Quartz service is a MBean
          jbossuser71

          I found (probably)  the related file in JBoss 6x - it is:

          {JBOSS}\server\default\deployers\jbossweb.deployer\META-INF\war-deployers-jboss-beans.xml

           

          But this file is now structured in completely different way - the 'UseJBossWebLoader' property does not exist here.

          Wondering what will be the appropriate property to set.

           

          =======================

          Okay - if I package  the Quartz service as a ".sar" file and deploy as part of my EAR deployment then the classloader problem is resolved, and I can at least invoke the EJB.

          But I am now getting a different error - I am not using JAAS for user authentication, rather using Spring Security.

          Within my EJB I have a check for SessionContext::getCallerPrincipal() for verifying user's access and in such case user principal is null since the job-class has invoked EJB.

           

          So can anyone pls. suggest how to set the credential for such EJB call (i.e. in SessionContext) ?

          The job class needs to invoke the EJB - but job class is invoked from Quartz scheduler.

           

          18:20:58,770 ERROR [STDERR] javax.ejb.EJBException: java.lang.IllegalStateException: No valid security context for the caller identity
          18:20:58,775 ERROR [STDERR]     at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:183)
          18:20:58,776 ERROR [STDERR]     at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:251)
          18:20:58,776 ERROR [STDERR]     at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.required(CMTTxInterceptor.java:349)
          18:20:58,777 ERROR [STDERR]     at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invoke(CMTTxInterceptor.java:209)
          18:20:58,777 ERROR [STDERR]     at org.jboss.ejb3.tx2.aop.CMTTxInterceptorWrapper.invoke(CMTTxInterceptorWrapper.java:52)
          18:20:58,778 ERROR [STDERR]     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          18:20:58,778 ERROR [STDERR]     at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
          18:20:58,779 ERROR [STDERR]     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
          18:20:58,779 ERROR [STDERR]     at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
          18:20:58,779 ERROR [STDERR]     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

          • 2. Re: Can not access EJB from a Quartz job-class in JBoss 6.0.0CR1 - Quartz service is a MBean
            jbossuser71

            Okay - I found the way to set the SessionContext - so my problem is resolved (so far - touchwood !).

            But if  anyone has other recommendation, pls. let me know.

             

            Cheers,

            • 3. Re: Can not access EJB from a Quartz job-class in JBoss 6.0.0CR1 - Quartz service is a MBean
              jbossuser71

              By the way can anyone tell me if JBoss uses Quartz service for its internal purpose?

              Because I have packaged quartz library as part of my EAR deployment and thus this library is no longer in {JBOSS}\common\lib directory.

              • 4. Re: Can not access EJB from a Quartz job-class in JBoss 6.0.0CR1 - Quartz service is a MBean
                jaikiran

                Kuntal Mondal wrote:

                 

                By the way can anyone tell me if JBoss uses Quartz service for its internal purpose?

                No, JBoss AS doesn't use Quartz for anything.