In the previous post, I described how different participant types work when we use Named User, Approval Group, Application Role etc in the assignment. Now we will see how to use BPM Java APIs in a series of post. I used 12.2.1.2.0 release for demonstration. This article assumes basic working knowledge of Human Workflows and does not get into finer details of the same.
SOA/BPM exposes number of human workflow services as listed below and all these services can be invoked either using SOAP or remote interface with an exception of Identity service which can be invoked only through SOAP interface. You can refer to url for more information on accessing the service and functionality exposed by each. In this post, we will see how to use Task Service to create a human task from java code.
- Task service
- Task query service
- Identity service
- Task metadata service
- User metadata service
- Task report service
- Runtime config service
- Evidence store service
Steps:
- Create a Human Workflow in a SOA composite and deploy to SOA Server.
- Create a java project in Jdeveloper with a java class having main method.
- Add BPM Workflow library by navigating to Project properties -> Libraries and Classpath. This jar will have necessary classes to work with human workflow services mentioned above. Note that the libraries Oracle XML Parser V2 and JAX-WS client also need to be added.
- To call any of the human workflow services, we need to get workflow service client as the first step which can either SOAP or REMOTE. Following snippet of code shows how to get a SOAP based workflow service client.
private IWorkflowServiceClient getWfServiceClient() { IWorkflowServiceClient wfSvcClient = null; wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.SOAP_CLIENT, getClientProp(WorkflowServiceClientFactory.SOAP_CLIENT),null); return wfSvcClient; } private Map<CONNECTION_PROPERTY, String> getClientProp(String clientType) { Map<CONNECTION_PROPERTY, String> properties = new HashMap<CONNECTION_PROPERTY, String>(); if (WorkflowServiceClientFactory.REMOTE_CLIENT.equals(clientType)) { properties.put(CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); //soa-infra url properties.put(CONNECTION_PROPERTY.EJB_PROVIDER_URL, soaInfraURL); //admin use properties.put(CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, wlsUser); //admin pwd properties.put(CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS, wlsPassword); } else if (WorkflowServiceClientFactory.SOAP_CLIENT.equals(clientType)) { properties.put(CONNECTION_PROPERTY.SOAP_END_POINT_ROOT, "http://host:soaPort"); properties.put(CONNECTION_PROPERTY.SOAP_IDENTITY_PROPAGATION, "non-saml"); } return properties; }
- Use the following code to create a task using Task service. You can get task namespace from .task file and is the targetNamespace mentioned there. The Task payload preparation should be as per payload defined in Data section of the human task. Note the usage of workflow service client to get the task service.
private Element getTaskPayload() throws Exception { String payloadStr = " <payload xmlns=\"http://xmlns.oracle.com/bpel/workflow/task\">" + "<EmployeeExpenseInput xmlns=\"http://xmlns.oracle.com/expenses/approval/schema\">" + " <employeeId></employeeId> " + " <firstName></firstName> " + " <lastName></lastName>" + " <expenseType></expenseType>" + " <expenseDescription></expenseDescription>" + " <expenseLocation></expenseLocation>" + " <expenseDate></expenseDate>" + " <amount></amount>" + "</EmployeeExpenseInput>" + " </payload>"; Document doc = null; try { doc = XMLUtil.parseDocumentFromXMLString(payloadStr); } catch (Exception e) { throw new Exception("Exception in parsing string to xml"); } return doc.getDocumentElement(); } public String createHumanTask() { String taskId = null; IInitiateTaskResponse taskResponse = null; try { ObjectFactory of = new ObjectFactory(); Task newTask = of.createTask(); //set required attribute before calling BPM task api newTask.setTaskDefinitionId(taskNameSpace); newTask.setPayloadAsElement(getTaskPayload()); newTask.setCreator(wlsUser); newTask.setTitle("BPM API TESTING USING CREATE HUMAN TASK"); newTask.setCategory("TESTING"); newTask.setIdentificationKey("587776676"); taskResponse = getWfServiceClient().getTaskService().initiateTask(newTask); if (taskResponse != null) { newTask = taskResponse.getTask(); taskId = newTask.getSystemAttributes().getTaskId(); } } catch (Exception e) { e.printStackTrace(); } return taskId; }
- Similarly, other human workflow services can be accessed using workflow service client. Note that you may not be able to test the remote client from java main method. You need to deploy this to WLS to see it in action.
- You can download the java project from here.