4 Replies Latest reply on Feb 13, 2013 3:39 PM by Jose Miguel Loor

    Not able to start a process through the Java API

    Jose Miguel Loor Apprentice

      I have succesfully created and deployed a process in BRMS 5.3 standalone server, following this: https://community.jboss.org/message/796593#796593

       

      But now i am facing another problem. I am doing this to obtain a session:

       

      private KnowledgeBase getKnowledgeBuilderKBase(final String changeSetUrl)

                                    throws ProcessRulesException {

                          try {

                                    Properties properties = new Properties();

                                    properties.setProperty("drools.dialect.java.compiler", "JANINO");

                                    PackageBuilderConfiguration cfg = new PackageBuilderConfiguration(

                                                        properties);

                                    JavaDialectConfiguration javaConf = (JavaDialectConfiguration) cfg

                                                        .getDialectConfiguration("java");

       

       

                                    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

                                                        .newKnowledgeBuilder(cfg);

       

       

                                    kbuilder.add(ResourceFactory.newUrlResource(changeSetUrl),

                                                        ResourceType.CHANGE_SET);

       

       

                                    if (kbuilder.hasErrors()) {

                                              System.err.println(kbuilder.getErrors().toString());

                                    }

       

       

                                    return kbuilder.newKnowledgeBase();

                          } catch (Exception e) {

                                    throw new ProcessRulesException(e);

                          }

                }

       

      private KnowledgeBase getKBase(final String changeSetUrl) throws ProcessRulesException {

           return getKnowledgeBuilderKBase(changeSetUrl);

      }

       

      private StatefulKnowledgeSession getKSession(final String changeSetUrlthrows ProcessRulesException {

           StatefulKnowledgeSession ksession = getKBase(changeSetUrl).newStatefulKnowledgeSession();

            ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());

           return ksession;

      }

       

       

      After getting the session, i am trying to start a process instance with this:

       

      public ProcessInstance startProcess(final String processName, final Map<String, Object> variables) throws ProcessRulesException {

           return getKSession(SOME_CHANGESET_URL).startProcess(processName, variables);

      }

       

      I am not getting any errors in my junit test, or in the server log; but i always get the same result:

       

      Executing work item WorkItem 1 [name=Human Task, state=0, processInstanceId=1, parameters{TaskName=ResultTask}]

      >>>> instance process: VacationRequest Vacation Request

      >>>> instance: 1

      >>>> instance state 2

       

       

      But, the process instance is not showing in the jbpm-console, nor is anything created in the database i am using to persist the brms data

       

      If i create a process instance via the jbpm-console, it is created fine, but not via the Java API

       

      What can be happening ?? Am i missing something ??

        • 1. Re: Not able to start a process through the Java API
          Maciej Swiderski Master

          Jose Miguel Loor wrote:

           

           

          private StatefulKnowledgeSession getKSession(final String changeSetUrl)  throws ProcessRulesException {

               StatefulKnowledgeSession ksession = getKBase(changeSetUrl).newStatefulKnowledgeSession();

                ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());

               return ksession;

          }

           

          Here you have two issues:

          1. you create non persistence session and thus nothing ends up in data base
          2. use SystemOutWorkItemHandler as handler for human tasks so it will simply print its properties and move on with the next nodes, most likely ending up as completed process instance

           

          Take a look in the docs on how to setup persistent sessions and make sure that it's configured towards the same db as console.

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: Not able to start a process through the Java API
            Jose Miguel Loor Apprentice

            Hi Maciej

             

            Thanks for the answer. I found this article:

             

            https://access.redhat.com/knowledge/docs/en-US/JBoss_Enterprise_BRMS_Platform/5/html/BRMS_Business_Process_Management_Guide/Configure_the_Engine_to_use_Persistence.html

             

            As you said, i had to create a persistent session in order to store the data in the database, and as you said, the process started and ended at once.

             

            So, i am asuming that i have to register other Handlers for the Human Task; but the bottom line is this:

             

            • It seems to me that my application is doing the job that the server should be doing; i am connecting to the database and the guvnor repository, and persisting all needed data; wich i think is the jbpm's server job
            • I had to add a bunch of jars to my app; this might not be meaninful for a desktop application, but in a web application i think they are excessive. True enough, they would not be necessary if the application is deployed in the same server as the brms server, but what if it doesn't ?? In this case, some of those jars are already present in the jboss server, but still, my web app has to deal with the database persistence of the jbpm data, wich, again, i think it is a job for the jbpm server. Am i wrong ??

             

            Finally, the brms server provides a REST api to interact with the server. For a web app, could this be a more feasible solution ??

             

            And again, this approach presents problems by itself. In order to use the REST api with an external java client, i have to change the login-method of the bussiness-central-server, from FORM to BASIC. With this change, i can consume the REST api ok, but the business-central gui, in the brms server, stops working. Any recomendation about this ???

             

            Thanks a lot

            • 3. Re: Not able to start a process through the Java API
              Maciej Swiderski Master

              Jose, all depends on your requirements. There are two main usage scenarios for jbpm (brms):

              • as a service - using the deployed version of console
              • embedded

               

              As you already noticed that imposes different ways of managing the runtime engine. In as a service it provides you with basic capabilities like starting a process, signal a process instance, etc over REST interface. In embedded mode you have full access to all the API so you have much more options to chose from. But that flexibility comes with a need to include all dependencies of jbpm into your application.

              With that said, is up to you what will be best fit for your application. Either way you'll have dependency on the jbpm regardless if that is bundled into your application or runtime dependency on the service exposed by brms/jbpm.

               

              HTH

              1 of 1 people found this helpful
              • 4. Re: Not able to start a process through the Java API
                Jose Miguel Loor Apprentice

                Thanks for your help and clarifications Maciej