[jboss-user] [JBoss jBPM] - Re: Invoke jBPM workflow from external app
hmuller
do-not-reply at jboss.com
Tue Jul 8 04:30:04 EDT 2008
Hi there,
I wrote the following class, which will invoke a workflow process. I use this from a servlet which takes normal xml over http (not soap) and then calls the process with the parameters.
| /**
| *
| */
| public class WFProcessFactory {
|
| JbpmConfiguration jbpmConfig = null;
|
| /**
| *
| * @param processId
| * @param processName
| * @param key
| * @param processVariables
| * @param signalStart
| * @return
| */
| public long startProcess(long processId, String processName, String key, HashMap processVariables, boolean signalStart) {
| long tokenId = 0;
|
| if (jbpmConfig == null) {
| jbpmConfig = JbpmConfiguration.getInstance();
| }
| JbpmContext jbpmContext = jbpmConfig.createJbpmContext();
| try {
| // get the session and process definition according to the process id
| GraphSession graphSession = jbpmContext.getGraphSession();
|
| ProcessDefinition processDefinition = null;
| if (processName.length() > 0) {
| processDefinition = graphSession.findLatestProcessDefinition(processName);
| } else {
| processDefinition = graphSession.getProcessDefinition(processId);
| }
|
| // if there are no process variables, then create an empty variable list
| if (processVariables == null) {
| processVariables = new HashMap();
| }
| // startup the process, set its business key (for correlation purposes, and
| // signal it to start going with the flow
| ProcessInstance processInstance = processDefinition.createProcessInstance(processVariables);
|
| processInstance.setKey(key);
| tokenId = processInstance.getRootToken().getId();
| if (signalStart) {
| processInstance.signal();
| }
| } finally {
| jbpmContext.close();
| }
| return tokenId;
| }
| }
|
The XML that I post to my servlet looks something like this.
| Input:
|
| <launch_workflow>
| <process_id>401</process_id> OPTIONAL if process_name is specified
| <process_name>SomeProcessName</process_name> OPTIONAL if process_id is specified
| <process_key>401_00001</process_key>
| <process_input>
| <process_var>
| <var_name>item1</var_name>
| <var_value>value1</var_value>
| </process_var>
| <process_var>
| <var_name>item2</var_name>
| <var_value>value2</var_value>
| </process_var>
| <process_var>
| <var_name>item3</var_name>
| <var_value>value3</var_value>
| </process_var>
| <process_var>
| <var_name>item4</var_name>
| <var_value>value4</var_value>
| </process_var>
| </process_input>
| </launch_workflow>
|
|
| Output:
|
| <launch_result>
| <token_id>499</token_id>
| </launch_result>
|
One thing to take note of: Don't re-instantiate the JBPMConfiguration object with each call, as this causes the server to run out of memory really quickly.
I hope that this helps.
Regards
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4163014#4163014
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4163014
More information about the jboss-user
mailing list