List elementProcessVariableList = completeWorkitemRequest.getChildren("processVariable", WORKFLOW_NAMESPACE);
HashMap processVariableMap = ElementToObject.makeProcessVariableMap(elementProcessVariableList);
ProcessManagerFactoryBean processManagerFactory = new ProcessManagerFactoryBean();
ProcessManagerRemote pm = null;
InitialContext context = new InitialContext();
UserTransaction tx = (GlobalContext.useManagedTransaction ? (UserTransaction) context.lookup(GlobalContext.USERTRANSACTION_JNDI_NAME) : null);
String completedTaskId = null;
List nextTaskList = null;
try {
pm = processManagerFactory.getProcessManager();
if (tx != null)
tx.begin();
completedTaskId = workflowService.completeWorkitem(endpoint, instanceId, taskId, tracingTag, processVariableMap, pm);
pm.applyChanges();
nextTaskList = workflowService.nextTask(instanceId);
if (tx != null && tx.getStatus() != Status.STATUS_NO_TRANSACTION)
tx.commit();
} catch (Exception e) {
try {
pm.cancelChanges();
} catch (Exception ex) {
}
if (tx != null && tx.getStatus() != Status.STATUS_NO_TRANSACTION)
tx.rollback();
} finally {
try {
pm.remove();
} catch (Exception e) {
}
}
Document doc = new Document(new Element(COMPLETE_WORKITEM_RESPONSE, WORKFLOW_NAMESPACE));