WebLogic Integration provides rich BPM APIs for creating custom configuration, design, and runtime management, and for monitoring clients . The business process engine consists of Session EJBs, Entity EJBs, and message-driven beans (MDBs). The session EJBs provide the primary interface to the business process engine. Both stateful and stateless session EJBs provide various functions. The session EJBs shown in Table 34.1 are available to the BPM API. Table 34.1. BPM Session EJBs
There are other useful classes in the following packages:
An Example of Using BPM APIsThe second example shows how to start a workflow and then execute a specific task within the workflow by using BPM APIs. A workflow (called MyWorkFlow ) has been created using Studio. This workflow is designed so that it can be started manually (see the manual option in Start Properties dialog in Figure 34.11). After the workflow is started, a task (called MyTask ) is activated. Refer to Figure 34.11. Figure 34.11. Example2: The MyWorkflow workflow.
MyTask is designed to send an XML response to the client including the date and time (see Figure 34.12). Figure 34.12. Example2: Properties for MyTask .
At this point, a command-line Worklist client has been created; it will start this workflow and execute the task named MyTask . Now you can establish a connection to the running BPM server and obtain a handle on the WorkList Session Bean, as shown in Listing 34.1. Listing 34.1 Connecting to BPM Serverprivate static boolean connect(String url, String userId, String password ) { Object result; try { ctx = getInitialContext(url, userId, password); result = ctx.lookup(WORKLIST_JNDI); WorklistHome wHome = (WorklistHome) PortableRemoteObject.narrow(result,WorklistHome.class); worklist = wHome.create(); return true; } catch(Exception e) { System.err.println("Caught Exception:" + e); } return false; } Start the workflow by using Worklist EJB, as shown in Listing 34.2. You can obtain a list of workflows that can be started manually by using the following method: public java.util.List getStartableWorkflows(java.lang.String orgID) throws java.rmi.RemoteException, WorkflowException From the list of startable workflows, you can choose and instantiate MyWorkFlow by using the following call: public java.lang.String instantiateWorkflow(java.lang.String orgID, java.lang.String templateID, java.lang.Object requestID) throws java.rmi.RemoteException, WorkflowException Listing 34.2 Starting the Workflow/** * Start a workflow */ public static String startWorkflow(String templateName) { String instanceId = null; try { String activeOrgId = worklist.getActiveOrganization(); List templates; templates = worklist.getStartableWorkflows(activeOrgId); for(int i = 0; i < templates.size(); i++) { TemplateInfo templateInfo = (TemplateInfo)templates.get(i); if (templateInfo.getName().equals(templateName) == true) { String response = worklist.instantiateWorkflow(activeOrgId, templateInfo.getId()); System.out.println("response:\n" + response); //parse instance id from response int j = response.indexOf("<instanceid>"); int k = response.indexOf("</instanceid>"); instanceId = response.substring(j + "<instanceid>".length(), k); } } } catch (Exception e) { System.err.println("Caught Exception : " + e.getMessage()); } finally { return instanceId; } } The response you will obtain is shown in the following code: <wlpiresponse> <instanceid>13001</instanceid> <templatedefinitionid>9001</templatedefinitionid> <root> <actionid>1029650142617</actionid> <DateOfMyWorkFlow>Sun Aug 18 01:16:34 MDT 2002</DateOfMyWorkFlow> </root> </wlpiresponse> The response is parsed to get the instanceid . This instanceid is used for executing a task. To execute a task, use the method shown in Listing 34.3. Listing 34.3 Executing a Task in a Given Workflowpublic TaskInfo getTask(java.lang.String taskName, java.lang.String instanceID) throws java.rmi.RemoteException, WorkflowException /** * Execute task of a given workflow */ public static boolean executeTask(String taskName, String instanceId) { try { TaskInfo taskInfo = worklist.getTask(taskName, instanceId); String response = worklist.taskExecute (taskInfo.getTemplateDefinitionId(), taskInfo.getInstanceId(), taskInfo.getTaskId()); System.out.println("response:\n" + response); return true; } catch (Exception e) { return false; } } The following is the response you will obtain: <wlpiresponse> <instanceid>15002</instanceid> <templatedefinitionid>9001</templatedefinitionid> </wlpiresponse> You can then run Example2 as follows :
|