9 Replies Latest reply on Oct 13, 2011 5:27 AM by Jaiyachandhiran Thangaraju

    How to add Java code to the jbpm process

    Jaiyachandhiran Thangaraju Newbie

      Hi

       

      I am using jbpm-jpdl-3.2.GA. I need an example to add java code to the NODE [ Node Action] How to add node action handler. Is there any guide or examples to do it.?   I need to write  a java code to connect to database? Please help me out

        • 1. Re: How to add Java code to the jbpm process
          Al Daher Newbie

          Hi,

           

          well if you are definig the proces through the diagram, you can do the following steps:

           

          1. Create a class under the following Package com.xxx.yyy.workflow.action.  call it MyClassHandler
          2. MyClassHandler should implement org.jbpm.graph.def.ActionHandler.
          3. in execute Method you should implement what you like to do (call EJB,  orsystem.out, call database, change process variables....)
          4. Go to your processdefinition.xml diagram
          5. Select the node to which you want to assign an action
          6. under Properties View, select Action tab
          7. select Configure Action
          8. go to Details and add the class name that implements your node action. For example : com.xxx.yyy.workflow.action.MyClassHandler
          9. choose  "Field" as a Config Type
          10. select Handler in the dropdown list
          11. Save the process Definition

           

          This description is for a simple node. Some changes mut be done for Decision nodes or other components.

          Hopefully it helped

           

          Regards

          • 2. Re: How to add Java code to the jbpm process
            Jaiyachandhiran Thangaraju Newbie

            Hi

             

            Thanks for ur reply

             

            I just wrote system.out.println for testing. I just used 2 activties one is start state and other is the node in which i have called the action handler.

             

            i just deployed the process and when i start the process using jbpm console , i am unable to move too next node from start.

             

            In jpmn console it asks for me to Choose Target Node but i am unable to choose? why

             

            How to check the code written inside the action handler?

             

             

            • 3. Re: How to add Java code to the jbpm process
              Jaiyachandhiran Thangaraju Newbie

              Hi

               

              I am having another doubt. Where i will see the action output? For e.g, I have written system.out.println("Hello"), Where i will get this output

              • 4. Re: How to add Java code to the jbpm process
                Al Daher Newbie

                Well i am not familiar with JBPM, but as a hint can you try to debug. Normally you should see sysout output in the run console.

                 

                Can you post more information about your process maybe the xml and a screenshot of the process definition.

                 

                Regards

                • 5. Re: How to add Java code to the jbpm process
                  Jaiyachandhiran Thangaraju Newbie

                  Hi

                   

                  Thanks for ur reply.  Now i have created a simple process and wrote a simple java code.

                   

                  Java Code

                   

                  public void execute(ExecutionContext executionContext) throws Exception {
                    // TODO Auto-generated method stub
                      String query = "SELECT login_name from rs_users";

                    System.out.println("Testing JAVA Code");
                       Class.forName("oracle.jdbc.driver.OracleDriver");
                       Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","resonancedev","resonancedev");
                       Statement stmt = con.createStatement();
                       ResultSet rs = stmt.executeQuery(query);
                       while (rs.next()) {
                         String message = rs.getString("login_name");
                             System.out.println("name-->" +message);
                             }
                           con.close();

                    //executionContext.getContextInstance().setVariable("message", message);
                   
                  }

                   

                   

                   

                   

                   

                   

                  I tried to start the process from console and i get the below error.

                   

                   

                    Failed to start process: class 'oracle.jdbc.driver.OracleDriver' could not be found by the process classloader

                   

                  I have added the jar file to the project, I need to know where to add this jar file?

                   

                  Please reply me

                  • 6. Re: How to add Java code to the jbpm process
                    Al Daher Newbie

                    Well now you are jumping to another problem.

                    Try to add the jar file to the class path of your project.

                     

                    If you are facing further problems which are not related ot jbpm, make sure to post a new thread and in the right place.

                     

                    p.s.

                    1. Try to add an end state to you process, cause you "may"  face further problems.
                    2. executionContext.leaveNode(); // to leave the node after action execution

                     

                    Regards

                    • 7. Re: How to add Java code to the jbpm process
                      Jaiyachandhiran Thangaraju Newbie

                      Hi

                      Sorry for the late reply, Sorry for jumping from one problem to another,

                      The Same Error  Failed to start process: class 'oracle.jdbc.driver.OracleDriver' could not be found by the process classloader is coming

                       

                      I added the appropriate jar in the classpath,

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <classpath>

                      <classpathentry kind="src" path="src/main/java"/>

                      <classpathentry kind="src" path="src/main/config"/>

                      <classpathentry kind="src" path="src/main/jpdl"/>

                      <classpathentry kind="src" path="src/test/java"/>

                      <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

                      <classpathentry kind="con" path="JBPM/JBoss jBPM 3.2.GA"/>

                      <classpathentry exported="true" kind="lib" path="E:/Softwares/jbpm-jpdl-3.2.GA/ojdbc14.jar"/>

                      <classpathentry kind="output" path="bin"/>

                      </classpath>

                       

                      and also i have attached the screen shot of properties tab of that project. I have added the jar there also. But i don't know where i need to add these jar

                       

                      Please help me out

                      • 9. Re: How to add Java code to the jbpm process
                        Jaiyachandhiran Thangaraju Newbie

                        Hi

                         

                        Thanks for ur reply

                         

                        The problem is resolved. The solution is Put the ojdbc14.jar in jbpm-jpdl-3.2.GA\server\server\jbpm\deploy folder. Now it works

                         

                        Thanks