Uploaded image for project: 'Red Hat Process Automation Manager'
  1. Red Hat Process Automation Manager
  2. RHPAM-4843

ClassCastException in Spring integration when using ejb timer.

XMLWordPrintable

    • False
    • None
    • False
    • -
    • Hide

      I've attached a reproducer.
      kjar - test03644977
      Spring Web app - spring-jbpm-web.war

      To reproduce the issue:

      1. install the kjar
      mvn install

      2. deploy the spring-jbpm-web.war to jboss eap 7.4

      3. a. open browser to access http://localhost:8080/spring-jbpm-web
      b. click New deployment
      c. fill com.redhat.rhpam:test03644977:1.0.0-SNAPSHOT
      d. click Deploy
      e. click Process Definitions
      f. click testTimer2
      g. fill 0 in the Value field
      h. click Start process instance
      You should see the ClassCastException in eap log file

      Show
      I've attached a reproducer. kjar - test03644977 Spring Web app - spring-jbpm-web.war To reproduce the issue: 1. install the kjar mvn install 2. deploy the spring-jbpm-web.war to jboss eap 7.4 3. a. open browser to access http://localhost:8080/spring-jbpm-web b. click New deployment c. fill com.redhat.rhpam:test03644977:1.0.0-SNAPSHOT d. click Deploy e. click Process Definitions f. click testTimer2 g. fill 0 in the Value field h. click Start process instance You should see the ClassCastException in eap log file
    • ---
    • ---

      HTML draft:

      https://file.emea.redhat.com/~emmurphy/RHPAM-4843/#spring-runtime-manager-con_process-engine

      Pull request:

      https://github.com/kiegroup/kie-docs/pull/10/files

       

       

      The ClassCastException is received in a Spring integration project when ejb timer is used. The following is the full stack trace:

      2023-11-07 11:02:49,110 WARN [org.drools.persistence.PersistableRunner] (default task-34) Could not commit session: java.lang.RuntimeException: Unable to load session snapshot
      at deployment.spring-jbpm-web.war//org.drools.persistence.api.SessionMarshallingHelper.loadSnapshot(SessionMarshallingHelper.java:104)
      at deployment.spring-jbpm-web.war//org.drools.persistence.PersistableRunner.initExistingKnowledgeSession(PersistableRunner.java:254)
      at deployment.spring-jbpm-web.war//org.drools.persistence.PersistableRunner.<init>(PersistableRunner.java:192)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
      at deployment.spring-jbpm-web.war//org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:122)
      at deployment.spring-jbpm-web.war//org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadKieSession(KnowledgeStoreServiceImpl.java:104)
      at deployment.spring-jbpm-web.war//org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadKieSession(KnowledgeStoreServiceImpl.java:36)
      at deployment.spring-jbpm-web.war//org.kie.internal.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(JPAKnowledgeService.java:144)
      at deployment.spring-jbpm-web.war//org.jbpm.runtime.manager.impl.factory.JPASessionFactory.findKieSessionById(JPASessionFactory.java:61)
      at deployment.spring-jbpm-web.war//org.jbpm.runtime.manager.impl.SingletonRuntimeManager.init(SingletonRuntimeManager.java:122)
      at deployment.spring-jbpm-web.war//org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newSingletonRuntimeManager(RuntimeManagerFactoryImpl.java:59)
      at deployment.spring-jbpm-web.war//org.kie.spring.manager.SpringRuntimeManagerFactoryImpl.newSingletonRuntimeManager(SpringRuntimeManagerFactoryImpl.java:58)
      at deployment.spring-jbpm-web.war//org.jbpm.kie.services.impl.AbstractDeploymentService.commonDeploy(AbstractDeploymentService.java:137)
      at deployment.spring-jbpm-web.war//org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:216)
      at deployment.spring-jbpm-web.war//org.jbpm.spring.web.DeploymentController.deployUnit(DeploymentController.java:31)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at deployment.spring-jbpm-web.war//org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
      at deployment.spring-jbpm-web.war//org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
      at javax.servlet.api@2.0.0.Final-redhat-00001//javax.servlet.http.HttpServlet.service(HttpServlet.java:523)
      at deployment.spring-jbpm-web.war//org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
      at javax.servlet.api@2.0.0.Final-redhat-00001//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
      at org.wildfly.security.elytron-web.undertow-server@1.9.3.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.lambda$handleRequest$1(ElytronRunAsHandler.java:68)
      at org.wildfly.security.elytron-private@1.15.16.Final-redhat-00001//org.wildfly.security.auth.server.FlexibleIdentityAssociation.runAsFunctionEx(FlexibleIdentityAssociation.java:103)
      at org.wildfly.security.elytron-private@1.15.16.Final-redhat-00001//org.wildfly.security.auth.server.Scoped.runAsFunctionEx(Scoped.java:161)
      at org.wildfly.security.elytron-private@1.15.16.Final-redhat-00001//org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:73)
      at org.wildfly.security.elytron-web.undertow-server@1.9.3.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.ElytronRunAsHandler.handleRequest(ElytronRunAsHandler.java:67)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
      at org.wildfly.security.elytron-web.undertow-server-servlet@1.9.3.Final-redhat-00001//org.wildfly.elytron.web.undertow.server.servlet.CleanUpHandler.handleRequest(CleanUpHandler.java:38)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:275)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1555)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1555)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1555)
      at org.wildfly.extension.undertow@7.4.10.GA-redhat-00002//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1555)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:255)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79)
      at io.undertow.servlet@2.2.23.SP2-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.Connectors.executeRootHandler(Connectors.java:393)
      at io.undertow.core@2.2.23.SP2-redhat-00001//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852)
      at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
      at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
      at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
      at org.jboss.xnio@3.8.7.SP1-redhat-00001//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
      at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: java.lang.ClassCastException: class org.kie.spring.persistence.KieSpringTransactionManager cannot be cast to class org.drools.persistence.jta.JtaTransactionManager (org.kie.spring.persistence.KieSpringTransactionManager and org.drools.persistence.jta.JtaTransactionManager are in unnamed module of loader 'deployment.spring-jbpm-web.war' @7296d344)
      at deployment.spring-jbpm-web.war//org.jbpm.services.ejb.timer.EjbSchedulerService.getTimerMappingInfo(EjbSchedulerService.java:174)
      at deployment.spring-jbpm-web.war//org.jbpm.services.ejb.timer.EjbSchedulerService.getTimerMappinInfo(EjbSchedulerService.java:157)
      at deployment.spring-jbpm-web.war//org.jbpm.services.ejb.timer.EjbSchedulerService.getTimerJobInstance(EjbSchedulerService.java:134)
      at deployment.spring-jbpm-web.war//org.jbpm.services.ejb.timer.EjbSchedulerService.scheduleJob(EjbSchedulerService.java:81)
      at deployment.spring-jbpm-web.war//org.jbpm.process.core.timer.impl.GlobalTimerService.registerJobHandle(GlobalTimerService.java:168)
      at deployment.spring-jbpm-web.war//org.jbpm.process.core.timer.impl.GlobalTimerService.scheduleJob(GlobalTimerService.java:117)
      at deployment.spring-jbpm-web.war//org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate.scheduleJob(RegisteredTimerServiceDelegate.java:68)
      at deployment.spring-jbpm-web.war//org.jbpm.process.instance.timer.TimerManager$ProcessTimerInputMarshaller.deserialize(TimerManager.java:291)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufInputMarshaller.readTimer(ProtobufInputMarshaller.java:729)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufInputMarshaller.readSession(ProtobufInputMarshaller.java:290)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufInputMarshaller.readSession(ProtobufInputMarshaller.java:165)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufMarshaller.unmarshallWithMessage(ProtobufMarshaller.java:144)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufMarshaller.unmarshall(ProtobufMarshaller.java:95)
      at deployment.spring-jbpm-web.war//org.drools.serialization.protobuf.ProtobufMarshaller.unmarshall(ProtobufMarshaller.java:53)
      at deployment.spring-jbpm-web.war//org.drools.persistence.api.SessionMarshallingHelper.loadSnapshot(SessionMarshallingHelper.java:99)
      ... 78 more

      This issue only occurs in the latest version 7.13.4 (7.67.0.Final-redhat-00024).
      The issue seems to be coming from the SpringRuntimeManagerFactoryImpl [1]:

      System.setProperty(TX_FACTORY_CLASS, SPRING_TX_FACTORY_CLASS);
      TransactionManagerFactory.resetInstance();
      TransactionManagerFactory transactionManagerFactory = TransactionManagerFactory.get();
      if (transactionManagerFactory instanceof KieSpringTransactionManagerFactory)

      { ((KieSpringTransactionManagerFactory) transactionManagerFactory).setGlobalTransactionManager(applicationContext.getBean(AbstractPlatformTransactionManager.class)); }

      It sets the KieSpringTransactionManager as the global transaction manager.

      However, the ejb timer requires a jta transaction manager [2]:

      JtaTransactionManager tm = (JtaTransactionManager) TransactionManagerFactory.get().newTransactionManager();

      This line of the code is where the ClassCastException is thrown.

      How to make ejb timer work with the Spring integration? In another word, how can SpringRuntimeManagerFactoryImpl work with a jta transaction manager required by the ejb timer?

      The following are some considerations about the possible solution:

      1. Simply remove this highlighted line from method SpringRuntimeManagerFactoryImpl(ApplicationContext applicationContext)
      System.setProperty(TX_FACTORY_CLASS, SPRING_TX_FACTORY_CLASS);

      And for setting this variable to be left to user by passing in the jvm for which TransactionManagerFactory to be used, default being "org.drools.persistence.jta.JtaTransactionManagerFactory"

      OR

      2. String factoryClassName = System.getProperty("org.kie.txm.factory.class", "org.drools.persistence.jta.JtaTransactionManagerFactory");

      &

      Providing a setter variable for SPRING_TX_FACTORY_CLASS in class SpringRuntimeManagerFactoryImpl, to be passed as bean property will be helpful or leaving it to user for setting this system property.

      [1] https://github.com/kiegroup/droolsjbpm-integration/blob/main/kie-spring/src/main/java/org/kie/spring/manager/SpringRuntimeManagerFactoryImpl.java#L45-L53

      [2] https://github.com/kiegroup/jbpm/blob/main/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EjbSchedulerService.java#L173

        1. spring-jbpm-web.war
          88.49 MB
          Gary Hu

              ftirados Francisco Javier Tirado Sarti
              rhn-support-ghu Gary Hu
              Gonzalo Muñoz Fernández Gonzalo Muñoz Fernández
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: