8 Replies Latest reply on Aug 16, 2013 3:23 AM by Pavan Kumar Mantha

    jBPM5 running via a Web Interface

    Ally Jarrett Newbie

      Hello all,

       

      I am new to JBoss & BPM. I have successfully created a quick demo for myself of a very simplistic insurance quote and a small jUnit test to pass in some basic parameters.

       

      However I am struggling to understand how I can Implement jBPM from a web interface. I've had a quick search around and havent really found any conclusive information about how this is done. I understand that jBPM can be accessed via REST calls or the jBPM API, I was hoping someone had a quick 'hello world' type demo which adequately shows/explains the relationship between the jBPM and a Web Interface (JSPs, JSF etc...) and how they can talk to each other.

       

      Thanks

       

      Ally

        • 1. Re: jBPM5 running via a Web Interface
          Mauricio Salatino Master

          Hi Alistair,

          You can use jBPM5 directly inside your web application. Do you know how to use JSP and JSF? For example if you are using JSP you will probably want to create a Servlet which will contain the logic for your presentation (MVC fashion). That servlet can use the same APIs that you are using on the test to interact with the processes and then propagate the results to your JSP as in any JSP application.

          Cheers

          1 of 1 people found this helpful
          • 2. Re: jBPM5 running via a Web Interface
            Ally Jarrett Newbie

            Mauricio,

             

            This is what I was hoping/expecting of jBPM5. I am familiar with using both JSP's & JSF, but the whole concept of business rules & processes is relatively new to me (in the programming stack), I was hoping someone had a basic demo working that I could take a look at, just so 1. I know how to instantiate jBPM5 properly ? and 2. I know how to instantiate/handle processes properly.

             

            Any help would be great.

             

            Cheers

            • 3. Re: jBPM5 running via a Web Interface
              Mauricio Salatino Master

              The best way of getting used to something new is to start using it in your applications, that's why we are expecting you to use the framework inside your web app in the same way that you were using it in your tests. Try adding the same code that you have in your tests inside a Servlet and see what happens. If you have more concrete questions at that point we are here to help.

              If you wait for an example, and that example was created based on different assumptions or different requirements you will get confused and probably follow a wrong lead.

              So, based on your requirements try what you already are doing in the tests into a servlet and try to create some user interface with JSP to display the process information that you need to show..

              Cheers

              • 4. Re: jBPM5 running via a Web Interface
                Ally Jarrett Newbie

                Ok cool I'll graft my junit test into JSF then post it here to see if I've used jBPM5 properly!

                 

                Cheers

                • 5. Re: jBPM5 running via a Web Interface
                  Mauricio Salatino Master

                  That sounds as a good plan! Good Luck!

                  Keep us posted about your progress!

                  • 6. Re: jBPM5 running via a Web Interface
                    Khaleel Shaik Newbie

                    Hi All,

                     

                    I am also coming with lot of Oracle Fusion Middleware experience on BPEL and all so looking for the answer for this question.  To put this question in different format, I hope the question of this post is how to invoke a process from a Servlet/JSP page?  All the examples talks about the API, but the example expecting is where to mention the HOST, PORT , and the PATH to connect the JBPM Flow?

                     

                    1.  The example (Evaluation)  show how to execute on the same mechine where the server and eclipse together exist.

                    2.  The documentation guides (chapter 16) gives the idea how to register the process with repository, basically how to deploy it by connecting to a drools server.

                     

                    However If there are two developers one is working on JBPM5 process and deploys to server  A. and nother developer is working on Web application he deploys his web application on server B?

                    Now how to submit the request (or invokes the JBPM Process) from server B ?

                     

                     

                    If any body has any sample how to setup the ksession in web application by calling the JBPM repository URL or some other URS of JBPM

                    For example I tried it as follows but error is comming:

                    private static KnowledgeBase readKnowledgeBase() throws Exception {

                                        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                                        //kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);

                                        kbuilder.add(ResourceFactory.newUrlResource(new java.net.URL("http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav/packages/defaultPackage/Evaluation.bpmn")), ResourceType.BPMN2);

                                        return kbuilder.newKnowledgeBase();

                              }

                     

                              private static StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {

                                        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                        HornetQHTWorkItemHandler humanTaskHandler = new HornetQHTWorkItemHandler(ksession);

                                        humanTaskHandler.setIpAddress("127.0.0.1");

                                        humanTaskHandler.setPort(5445);

                                        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

                                        return ksession;

                              }

                     

                     

                     

                    The Error it shows is:

                     

                    ProcessLoadError: Unable to load process. : Exception class java.io.IOException : Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav/packages/defaultPackage/Evaluation.bpmn

                    java.lang.IllegalArgumentException: Could not parse knowledge.

                              at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:73)

                              at com.sample.ProcessTest.readKnowledgeBase(ProcessTest.java:43)

                              at com.sample.ProcessTest.main(ProcessTest.java:24)

                     

                     

                    Note: 

                    I can browse the URL http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/webdav/packages/defaultPackage/Evaluation.bpmn  with  krisv user authentication,  I guess we need to see how to pass the authentication information if the above URL is correct.

                     


                    Any help is appreciated?

                     

                    If the JBOSS Community can maintain one chapter on  "Deployment " will be great.

                     

                    -- Khaleel

                    • 7. Re: jBPM5 running via a Web Interface
                      Khaleel Shaik Newbie

                      Hi,

                       

                      I hope now I am able to find out  a way and understand the scenario,  if any body can provide more details it would be great.

                       

                      1.  Build your Process in Eclipse.

                      2.  Register this process with Drools repository  (see how to do it in the Chapter 16 http://docs.jboss.org/jbpm/v5.3/userguide/ch.process-repository.html ).

                                (Right click on   your  Evaluation.bpmn process choose  Guvnor and then add   (provide the host and port and authentication credentials.)

                      3. Now you can browse the to see your deployed process at  bpmn-console  http://localhost:8080/jbpm-console/

                      4. Also you can see the same process in the govnor  http://localhost:8080/drools-guvnor

                      5. Invoke the process from the Web application Copy all the process  in some folder say  html-public/jbpmflows/ <Evalution.bpmn>  (you can copy all others flows here)

                      6. Use the following code with the URL that you can point to the process file as a simple static file

                       

                           private static KnowledgeBase readKnowledgeBase() throws Exception {

                                          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                                          //kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);

                                          //kbuilder.add(ResourceFactory.newUrlResource("file:///D:/Evaluation.bpmn"), ResourceType.BPMN2);

                                          kbuilder.add(ResourceFactory.newUrlResource(new java.net.URL("http://<yourwebhost>:8080/webcontextroot/jbpm/Evaluation.bpmn")),         ResourceType.BPMN2);

                                          return kbuilder.newKnowledgeBase();

                                }

                      7. submit your flow request to the host system where your flows were registered

                       

                            private static StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {

                                          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                          HornetQHTWorkItemHandler humanTaskHandler = new HornetQHTWorkItemHandler(ksession);

                                          humanTaskHandler.setIpAddress("127.0.0.1");  //govnor host

                                          humanTaskHandler.setPort(5445); //govnor port

                                          ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

                                          return ksession;

                                }

                       

                       

                      Thanks

                      -- Khaleel

                      • 8. Re: jBPM5 running via a Web Interface
                        Pavan Kumar Mantha Newbie

                        Hello all

                         

                        i want to call the jBPM process from servlet so i did it in the following way

                         

                        my servlet class:

                        /**

                        *

                        */

                        package com.spark.jbpm.servlet;

                         

                        import java.io.IOException;

                         

                        import javax.servlet.ServletException;

                        import javax.servlet.http.HttpServlet;

                        import javax.servlet.http.HttpServletRequest;

                        import javax.servlet.http.HttpServletResponse;

                         

                        /**

                        * @author Sony

                        *

                        */

                        public class JbpmServlet extends HttpServlet {

                         

                            @Override

                            protected void service(HttpServletRequest request, HttpServletResponse response)

                                    throws ServletException, IOException {

                                JBPMDao jbpmDao = new JBPMDao();

                                try {

                                    jbpmDao.runJbpmProcess();

                                } catch (Exception e) {

                                    // TODO Auto-generated catch block

                                    e.printStackTrace();

                                }

                            }

                        }

                         

                        my dao class:

                        /**

                        *

                        */

                        package com.spark.jbpm.servlet;

                         

                        import org.drools.KnowledgeBase;

                        import org.drools.builder.KnowledgeBuilder;

                        import org.drools.builder.KnowledgeBuilderFactory;

                        import org.drools.builder.ResourceType;

                        import org.drools.io.ResourceFactory;

                        import org.drools.io.impl.UrlResource;

                        import org.drools.runtime.StatefulKnowledgeSession;

                         

                        /**

                        * @author Sony

                        *

                        */

                        public class JBPMDao {

                         

                            public void runJbpmProcess() throws Exception{

                               

                                KnowledgeBase kbase = readKnowledgeBase();

                               

                                StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                               

                                ksession.startProcess("defaultPackage.HelloWorld");

                               

                            }

                           

                            private KnowledgeBase readKnowledgeBase() throws Exception {

                                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                                String url = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/defaultPackage/SimpleProcess";

                                System.out.println("Going: " + url);

                         

                                UrlResource resource = (UrlResource) ResourceFactory.newUrlResource(url);

                                resource.setBasicAuthentication("enabled");

                                resource.setUsername("krisv");

                                resource.setPassword("krisv");

                               

                                kbuilder.add(resource, ResourceType.PKG);

                               

                                if(kbuilder.hasErrors()){

                                    throw new RuntimeException(kbuilder.getErrors().toString());

                                }

                                KnowledgeBase knowledgeBase = kbuilder.newKnowledgeBase();

                                knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

                                return knowledgeBase;

                            }

                        }

                         

                        my web.xml file:

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

                        <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                            xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

                            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

                            id="WebApp_ID" version="2.5">

                         

                            <welcome-file-list>

                                <welcome-file>index.jsp</welcome-file>

                            </welcome-file-list>

                         

                            <servlet>

                                <servlet-name>jBPMServlet</servlet-name>

                                <servlet-class>com.spark.jbpm.servlet.JbpmServlet</servlet-class>

                            </servlet>

                         

                            <servlet-mapping>

                                <servlet-name>jBPMServlet</servlet-name>

                                <url-pattern>/jBPMServlet</url-pattern>

                            </servlet-mapping>

                         

                        </web-app>

                         

                        now when i deply and run the project i get the below error:

                        HTTP Status 500 -


                        type Exception report

                        message

                        description The server encountered an internal error () that prevented it from fulfilling this request.

                        exception

                        javax.servlet.ServletException: Error instantiating servlet class com.spark.jbpm.servlet.JbpmServlet org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) java.lang.Thread.run(Thread.java:662) 

                        root cause

                        java.lang.ClassNotFoundException: com.spark.jbpm.servlet.JbpmServlet from [Module "deployment.Servlet-jBPM.war:main" from Service Module Loader] org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) java.lang.Thread.run(Thread.java:662) 

                        can any one tell me the exact cause of this issue. i am also trying to resolve but not able to get the exact reason

                        Thanks

                        Pavan Kumar