3 Replies Latest reply on Dec 10, 2013 2:25 AM by Maciej Swiderski

    CDI-based WorkItemHandler deployment using KIE Workbench

    Jay Guidos Novice

      Hi All,

       

      I am making good progress in understanding the new architecture of jBPM6. The new Workbench is excellent, and the move to Git and Maven projects has been great! We use IntelliJ and any hard Eclipse requirements would make jBPM a non-starter in our organization. Trying to use Guvnor for project publishing in jBPM was just painful.

       

      So I am trying to figure out how to use CDI to deploy work item handlers.  I am very familiar with Spring, but a noob using CDI. Here is what I have done so far:

       

      1. Used KIE Workbench to create a project

      2. Created a business process that used a domain specific process via a custom work item definition

      3. Saved the project

      4. Cloned the project in IntelliJ

       

      Ok, great! I now want to make a KJar that contains my java code for the domain process and hook it into the project via a workitemhandler. There is no RunTimeMananger, EnvironmentProducer or ProcessEngineService automatically in the project. How do I get the workitemhandler registered and the KJar deployed using CDI? I also would like to have access to a RunTimeManager, as my KieSession needs to be pre-configured with facts and globals before the process runs.

       

      Do I create my own RuntimeManager (as in the very helpful examples in https://github.com/mswiderski/jbpm-examples.git do?), and then push it back into KIE Workbench? The aforementioned examples show how to use CDI to register a work item handler, but not how to get all that stuff into KIE Workbench. Can you walk me through how to from KIE Workbench:

       

      1. Gain access to my RuntimeManager to preconfigure the KieSession

      2. Register the workitem handler

      3. Deploy the domain process jar that the work item handler calls

       

      Jay

        • 1. Re: CDI-based WorkItemHandler deployment using KIE Workbench
          Maciej Swiderski Master

          in general, I would recommend following approach:

          1. have the kjar that contains only the business assets

          2. have separate jar that contains the handler which is considered technical asset

          3. both should be maven based modules to simplify usage of them

          4. for CDI based handlers add beans.xml into the handlers jar and provide WorkItemHandlerProducer to create instances of the handler when asked by the workbench. when you look at the producer interface you'll see it provides some parameters and one of the parameters will be runtime manager so you can use it within your handler

          5. use maven to build the modules (clean install)

          6. place you handler jar on workbench classpath (WEB-INF/lib)

          7. use deployments view to deploy kjar into workbench by specifying GAV

           

          and that should allow you to successfully run your processes with CDI based handlers. Please note that you can use non CDI based handler as well where you would use the "old" way to register handlers via conf file (drools.session.conf and CustomWorkItemHandlers.conf).

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: CDI-based WorkItemHandler deployment using KIE Workbench
            Jay Guidos Novice

            Hi Maciej!

             

            Steps 1-5 make perfect sense, I had already guessed that, which is a good indication of how intuitive the new deployment approach is.

             

            For step 6, how do I put my KJars on the workbench classpath?  I was going to just make them dependencies of my main project POM, which I am allowed to edit directly from the workbench.  That isn't good enough?

             

            For 7, I have already tried deploying into the workbench manually via its GAV, and that works OK.  If I use the same GAV twice (i.e. do a redeploy) it does not do a replace, it appends something to the jar name and I get two deployments with the same GAV.  How does the workbench decide which one to use?  And also, there doesn't seem to be any way to delete a deployment via the GUI, how to delete old deployments?

             

            Also, I thought it would be good to have my work hander jar deploy itself to the workbench maven repo during my builds.  I added the repo location to my pom and added a <server> entry in my settings.xml, but I always get a permission denied error from Maven.  Is this supported? I was using krisv/krisv, which works from the GUI.

             

            Jay

            • 3. Re: CDI-based WorkItemHandler deployment using KIE Workbench
              Maciej Swiderski Master

              Jay Guidos wrote:

               

              Hi Maciej!

               

              Steps 1-5 make perfect sense, I had already guessed that, which is a good indication of how intuitive the new deployment approach is.

               

              For step 6, how do I put my KJars on the workbench classpath?  I was going to just make them dependencies of my main project POM, which I am allowed to edit directly from the workbench.  That isn't good enough?

               

              I mentioned two jars involved here:

              1. kjar that consists fo business assets like processes and rules, etc

              2. handler that consists of technical components like work item handler, listeners, etc

               

              so the first is deployed in maven repo and then you use deployments view to put it on jbpm runtime, second usually is directly placed on classpath of jbpm console (jbpm-console.war/WEB-INF/lib). Alternatively you can make a reference to it via pom as well, although it makes it only scoped to the given kjar only and you cannot use "global" ways to register handler on the ksession - like using CDI producer or conf files.

               

              Jay Guidos wrote:

               

               

              For 7, I have already tried deploying into the workbench manually via its GAV, and that works OK.  If I use the same GAV twice (i.e. do a redeploy) it does not do a replace, it appends something to the jar name and I get two deployments with the same GAV.  How does the workbench decide which one to use?  And also, there doesn't seem to be any way to delete a deployment via the GUI, how to delete old deployments?

              on deployments view there are icons on the right hand side where one of them allows to remove deployments, with limitation that no active process instances can be present while removing it.

               

              Jay Guidos wrote:

               

              Also, I thought it would be good to have my work hander jar deploy itself to the workbench maven repo during my builds.  I added the repo location to my pom and added a <server> entry in my settings.xml, but I always get a permission denied error from Maven.  Is this supported? I was using krisv/krisv, which works from the GUI.

               

              Jay

              there seems to be an issue with security settings for internal (jbpm) maven repo. Just for tests (and if that is ok from your project point of view) you could disable maven repo security in web.xml of jbpm-console web app.

               

              HTH

              1 of 1 people found this helpful