Discussion:
[jboss-user] [jBPM] - Example of simple process of executing a service task in JBPM Console.
David Harris
2013-04-30 18:05:51 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811009#811009

--------------------------------------------------------------
Hi, I'm looking for examples on creating a simple process (start->service task->end)  that executes Java code in the JBPM Console, not Eclipse.  The examples I've seen don't show adding Java code to service tasks or they refer to executing the BPMN2 process in Eclipse, instead of the JBPM Console. I'm using JBPM5.4.  I'm sure someone's done this many times over, I'm just trying to get some ideas.  Thanks!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811009#811009]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Demian Calcaprina
2013-04-30 18:45:28 UTC
Permalink
Demian Calcaprina [https://community.jboss.org/people/calca] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811017#811017

--------------------------------------------------------------
I guess you have to:
- Create work item definition with some name, for example "MyTask".
- Add a jar file with your WorkItemHandler implementation.
- Create a session template attaching your custom work item handler to "My task".
https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-gwt/jbpm-gwt-core/src/test/resources/default.session.template https://github.com/droolsjbpm/jbpm/blob/5.4.x/jbpm-gwt/jbpm-gwt-core/src/test/resources/default.session.template

This will make that the Knowledge Session is able to execute the My Task node.

But I think, to write your own work item handlers, you should have to use eclipse or some other IDE.

HTH

Demian
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811017#811017]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-04-30 19:23:38 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811021#811021

--------------------------------------------------------------
Post by Demian Calcaprina
to write your own work item handlers, you should have to use eclipse or some other IDE.
Well, that's where I'm confused.  I created the work item definitions with the Process Designer's built-in editor and the work items show up as tasks in the Process Designer.  The JBPM Console sees the BPMN2 process created in Process Designer, as its supposed to.

If the BPMN2 process contains the work item definitions and the JBPM Console executes the BPMN2 process, shouldn't the work items also be executed by the Console?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811021#811021]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Demian Calcaprina
2013-04-30 19:48:13 UTC
Permalink
Demian Calcaprina [https://community.jboss.org/people/calca] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811023#811023

--------------------------------------------------------------
What does your own work item definition do? Could you please mention an example of what you are trying to achieve?

For example, if you have a custom work item definition, "Ping Server". Then, you will have to have some code that pings a server. You can have it inside the Console classpath, using it as I explained in the previuos comment. Or maybe calling a webservice?

Demian
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811023#811023]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-04-30 20:14:03 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811026#811026

--------------------------------------------------------------
What I really want to do, as a first step, is to insert Java code into a Service task and run it in the JBPM Console. Using work item definitions is secondary.

For example, executing Java code in a Script task is easy.  I simple put the code in the script attribute, save the process and run the process containing the Script task in the JBPM Console.  

Service tasks are less obvious.  Setting aside the issue of work items, how do you insert Java code into a Service task in the way you can with a Script task? I'm just looking first to get a simple process containing one service task to run in the JBPM Console.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811026#811026]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Mauricio Salatino
2013-04-30 20:27:07 UTC
Permalink
Mauricio Salatino [https://community.jboss.org/people/salaboy21] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811029#811029

--------------------------------------------------------------
Hi David,
As Demian mention, the only other way (and recommended way) to add your custom Java code is via a WorkItemHandler implementation. For that you will need a Java class. Once you have your java class you will need to create a Jar file (container of compiled java classes) and add that jar file to the jbpm console class path in order to use it. This means that the jbpm console needs to have access to your compiled class, in the same ways as any other application.

This is a really common way of accepting extensions for any other java application, so it should be simple for you to create that.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811029#811029]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-04-30 20:42:52 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/811031#811031

--------------------------------------------------------------
Ok, thanks, Mauricio and Demian.  I'm seeing now how this all fits.  Thanks!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/811031#811031]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sumeru Saha
2013-05-18 13:55:35 UTC
Permalink
Sumeru Saha [https://community.jboss.org/people/sumerus] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/818341#818341

--------------------------------------------------------------
Hi David,

Was your problem resolved? I'm doing things similar to what you were doing ... i wanted to create a Domain Specific service task called "CallaJava" for that i wrote the below workietm definition (WID)

[
  "name" : "CallJava",
  "parameters" : [
    "Interface" : new StringDataType(),
    "Operation" : new StringDataType(),
    "ParameterType" : new StringDataType(),
    "Parameter" : new ObjectDataType("com.sample.service.Student")
  ],
  "results" : [
    "Result" : new ObjectDataType("java.util.Map")
  ],
  "displayName" : "CallJava",
  "icon" : " http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/java-icon/binary http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/java-icon/binary" ,
  "defaultHandler" : "com.sample.service.ExtendedServiceTaskHandler"
  ]

I've put the jar containing my custom WorkItemHandler, a class called "com.sample.service.ExtendedServiceTaskHandler" witin *jbpm-gwt-console-server.war/WEB-INF/lib*

I've added an entry in the *jbpm-gwt-console-server.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf* (like below)

[
  "Log": new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler(),
  "CallJava": new com.sample.service.ExtendedServiceTaskHandler(ksession),
]

Now i can get this handler invoked with parameters that i mentioned in the WID, i can have any java code invoked from within the handler, BUT my problem is that i can't pass any variables from the process flow (defined in the BPMN process in designer) into this handler - i can only pass literal values (of primitive types like String, int etc.). Have you been able to do that?


Thanks
Sumeru
---
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/818341#818341]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-05-31 14:26:27 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/820698#820698

--------------------------------------------------------------
Thanks Sumeru.   I haven't gotten this far, yet.  Do you have to put the default handler in the work item definition?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820698#820698]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
alvinuw
2013-05-31 19:40:24 UTC
Permalink
alvinuw [https://community.jboss.org/people/alvinuw] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/820747#820747

--------------------------------------------------------------
I developed the process in eclipse. Let's say I generate a "process.jar" from eclipse. It contains the main file and also the handler class "ExtendedServiceTaskHandler.class".
If I just put "process.jar", instead of "com.sample.service.ExtendedServiceTaskHandler.jar", can it work?

Actually, I tried this way. It seems it doesn't work.
Does it mean we have to jar the handler class, then put it in war, instead of the project jar?
Thanks.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820747#820747]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sumeru Saha
2013-06-03 08:30:49 UTC
Permalink
Sumeru Saha [https://community.jboss.org/people/sumerus] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/820913#820913

--------------------------------------------------------------
Hi David - thanks for your reply. I've got this problem resolved of creating Domain specific service handlers.

@Alvinuw - I'm not sure if you're also trying the same stuff as i was doing but below are the steps i did for getting a domain specific handler working in jBPM 5.4 & jBoss BRMS 5.3

1. Modify the Work definition in Guvnor
2. Upload the icon image for your new Domain specific service (for my case CallJava) into Guvnor

** After these 2 steps done successfully, the new Service Task icon will start appearing in your component pallete of the designer under the section Service Task

3. Put the jar containing custom work item handler class into jbpm-gwt-console-server.war (for jbpm 5.4) or jbpm-business-central-server.war (for jboss brms) -> WEB-INF/lib
4. Modify and added an entry in the *(...)-server.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf* (like below)
[
  "Log": new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler(), // this was existing from before
  "CallJava": new com.sample.service.ExtendedServiceTaskHandler(ksession),
]
5. If the drools.session.conf file is present in *(...)-server.war/WEB-INF/classes/META-INF/,* *make sure it has the below line. (In BRMS, these 2 files drools.sssion.conf & CustomWorkItemhandler.conf  are not there initially, you need to create them in brms. jBPM 5.4 already had these files)*
*
*
*drools.workItemHandlers = CustomWorkItemHandlers.conf
*
6. Include the service task in your BPMN2 flow and do proper Parameter Mapping (Data Input Assignments) to pass in Process Variables. Make sure whatever values you want to pass into the handler's "execute" method, they're already set into kcontext by executing the kcontext.setVariable("someProcessVar", someProcessVar)

Hope these help.

Thanks
Sumeru
---
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820913#820913]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
alvinuw
2013-06-03 13:22:17 UTC
Permalink
alvinuw [https://community.jboss.org/people/alvinuw] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/820992#820992

--------------------------------------------------------------
Hi Sumeru,

Thank you for your information.

For your 6th point, I do have two variables to pass into my handler.
Which file should I add "kcontext.setVariable("someProcessVar", someProcessVar)"
Actually, I use eclipse to develop the process, I have one main.java, and two handler.java.

Thanks.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/820992#820992]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-06-03 15:15:06 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/821036#821036

--------------------------------------------------------------
Thanks Sumeru,

I came to the same solution over this weekend.  Your original response helped a lot.

Thanks again,
Dave
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/821036#821036]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
David Harris
2013-06-08 22:53:30 UTC
Permalink
David Harris [https://community.jboss.org/people/dmwpepper] created the discussion

"Re: Example of simple process of executing a service task in JBPM Console."

To view the discussion, visit: https://community.jboss.org/message/822144#822144

--------------------------------------------------------------
Hi Mauricio, I've tried the update to the jbpm-gwt-console-server.war file with mixed results.  I've narrowed the problem down to jbpm-gwt-console-server.war not being "accepted" by the application server (AS 7.1) once the customer .jar file has been added.  It may be that I opened and/or closed the .war file incorrectly or perhaps the same with the .jar file.  Some people have said they user 7zip, others "jar ....".  Can you suggest the commands to be used to create the .jar file of custom work items as well as the command/utilities to open and close the ...server.war file?  Thanks, much.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/822144#822144]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...