0 Replies Latest reply on Apr 9, 2015 11:49 PM by chiaan Hung

    How can I create dynamic RuntimeEnvironment in web application?

    chiaan Hung Novice

      My web application, using jbpm 6.0.0.Final, can run on wildfly-8.1.0.Final.

       

      @Inject
      @PerRequest
      private RuntimeManager manager;
      
      
      

       

      @Inject
      TaskService taskService;
      
      
      

       

       

      @Produces
          @Singleton
          @PerProcessInstance
          @PerRequest
          public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {
          
                      KieServices ks = KieServices.Factory.get();
                      KieContainer kContainer = ks.getKieClasspathContainer();
             
                      KieBase kbase = kContainer.getKieBase();
            
                      AbstractAuditLogger auditlogger = null;
           
              RuntimeEnvironmentBuilder a  = RuntimeEnvironmentBuilder
                      .getDefault()
                      .persistence(true)
                      .entityManagerFactory(emf)
                      .userGroupCallback(usergroupCallback)
                      .registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditlogger));
                     
              a.addAsset(ResourceFactory.newClassPathResource("rewards.bpmn"),ResourceType.BPMN2);
             
              
              RuntimeEnvironment environment = a.get();
             
            
              ((SimpleRegisterableItemsFactory) environment.getRegisterableItemsFactory()).addWorkItemHandler("xx", handler.TestWorkItemHandler1.class);
            
              return environment;
          }
      
      
      

      Now I want to use Kiebase to create RuntimeEnvironment, so I did a little change at function produceEnvironment.

       

      @Produces
          @Singleton
          @PerProcessInstance
          @PerRequest
          public RuntimeEnvironment produceEnvironment(EntityManagerFactory emf) {
          
              KieServices ks = KieServices.Factory.get();
              KieContainer kContainer = ks.getKieClasspathContainer();
              KieBase kbase = kContainer.getKieBase();
            
              AbstractAuditLogger auditlogger = null;
           
              RuntimeEnvironmentBuilder a  = RuntimeEnvironmentBuilder
                      .getDefault()
                      .persistence(true)
                      .entityManagerFactory(emf)
                      .userGroupCallback(usergroupCallback)
                      .knowledgeBase(kbase)
                      .registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditlogger));
                    
                      
              RuntimeEnvironment environment = a.get();
             
            
              ((SimpleRegisterableItemsFactory) environment.getRegisterableItemsFactory()).addWorkItemHandler("xx", handler.TestWorkItemHandler1.class);
            
              return environment;
          }
      
      
      

      I did put kmodule.xml under /META-INF.

      <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"></kmodule>
      
      
      

       

      However, I got error

      "{\"JBAS014671: Failed services\" => {\"jboss.deployment.unit.\\\"jbpm-demo-rewards-basic.war\\\".component.ProcessBean.START\" => \"org.jboss.msc.service.StartException in service jboss.deployment.unit.\\\"jbpm-demo-rewards-basic.war\\\".component.ProcessBean.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

          Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

          Caused by: javax.ejb.EJBException: java.lang.RuntimeException: Cannot find a default KieBase

          Caused by: java.lang.RuntimeException: Cannot find a default KieBase\"}}"

       

      Moreover, Can kContainer auto scan new bpmn or drl file I add when this web application is already running?

      Full server log attached. Thanks!