use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.
the class WebServiceUELTest method testWebServiceInvocationWithDataFlowUEL.
@Deployment
public void testWebServiceInvocationWithDataFlowUEL() throws Exception {
ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {
public ProcessDefinitionEntity execute(CommandContext commandContext) {
return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("webServiceInvocationWithDataFlowUEL");
}
});
ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
ItemInstance itemInstance = itemDefinition.createInstance();
FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
structureInstance.setFieldValue("prefix", "The counter has the value ");
structureInstance.setFieldValue("suffix", ". Good news");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("dataInputOfProcess", itemInstance);
ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithDataFlowUEL", variables);
waitForJobExecutorToProcessAllJobs(10000L, 250L);
String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "dataOutputOfProcess");
assertEquals("The counter has the value -1. Good news", response);
}
use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.
the class WebServiceUELTest method testAsyncInvocationWithDataFlowUEL.
@Deployment
public void testAsyncInvocationWithDataFlowUEL() throws Exception {
assertEquals(-1, webServiceMock.getCount());
ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {
public ProcessDefinitionEntity execute(CommandContext commandContext) {
return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("asyncWebServiceInvocationWithDataFlowUEL");
}
});
ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
ItemInstance itemInstance = itemDefinition.createInstance();
FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
structureInstance.setFieldValue("newCounterValue", 23);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("dataInputOfProcess", itemInstance);
processEngine.getRuntimeService().startProcessInstanceByKey("asyncWebServiceInvocationWithDataFlowUEL", variables);
waitForJobExecutorToProcessAllJobs(10000L, 250L);
assertEquals(23, webServiceMock.getCount());
}
use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.
the class WebServiceActivityBehavior method execute.
/**
* {@inheritDoc}
*/
public void execute(ActivityExecution execution) throws Exception {
MessageInstance message;
try {
if (ioSpecification != null) {
this.ioSpecification.initialize(execution);
ItemInstance inputItem = (ItemInstance) execution.getVariable(this.ioSpecification.getFirstDataInputName());
message = new MessageInstance(this.operation.getInMessage(), inputItem);
} else {
message = this.operation.getInMessage().createInstance();
}
execution.setVariable(CURRENT_MESSAGE, message);
this.fillMessage(message, execution);
ProcessEngineConfigurationImpl processEngineConfig = Context.getProcessEngineConfiguration();
MessageInstance receivedMessage = this.operation.sendMessage(message, processEngineConfig.getWsOverridenEndpointAddresses());
execution.setVariable(CURRENT_MESSAGE, receivedMessage);
if (ioSpecification != null) {
String firstDataOutputName = this.ioSpecification.getFirstDataOutputName();
if (firstDataOutputName != null) {
ItemInstance outputItem = (ItemInstance) execution.getVariable(firstDataOutputName);
outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
}
}
this.returnMessage(receivedMessage, execution);
execution.setVariable(CURRENT_MESSAGE, null);
leave(execution);
} catch (Exception exc) {
Throwable cause = exc;
BpmnError error = null;
while (cause != null) {
if (cause instanceof BpmnError) {
error = (BpmnError) cause;
break;
}
cause = cause.getCause();
}
if (error != null) {
ErrorPropagation.propagateError(error, execution);
} else {
throw exc;
}
}
}
use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.
the class WebServiceActivityBehavior method execute.
public void execute(DelegateExecution execution) {
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());
FlowElement flowElement = execution.getCurrentFlowElement();
IOSpecification ioSpecification = null;
String operationRef = null;
List<DataAssociation> dataInputAssociations = null;
List<DataAssociation> dataOutputAssociations = null;
if (flowElement instanceof SendTask) {
SendTask sendTask = (SendTask) flowElement;
ioSpecification = sendTask.getIoSpecification();
operationRef = sendTask.getOperationRef();
dataInputAssociations = sendTask.getDataInputAssociations();
dataOutputAssociations = sendTask.getDataOutputAssociations();
} else if (flowElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) flowElement;
ioSpecification = serviceTask.getIoSpecification();
operationRef = serviceTask.getOperationRef();
dataInputAssociations = serviceTask.getDataInputAssociations();
dataOutputAssociations = serviceTask.getDataOutputAssociations();
} else {
throw new ActivitiException("Unsupported flow element type " + flowElement);
}
MessageInstance message = null;
fillDefinitionMaps(bpmnModel);
Operation operation = operationMap.get(operationRef);
try {
if (ioSpecification != null) {
initializeIoSpecification(ioSpecification, execution, bpmnModel);
if (ioSpecification.getDataInputRefs().size() > 0) {
String firstDataInputName = ioSpecification.getDataInputRefs().get(0);
ItemInstance inputItem = (ItemInstance) execution.getVariable(firstDataInputName);
message = new MessageInstance(operation.getInMessage(), inputItem);
}
} else {
message = operation.getInMessage().createInstance();
}
execution.setVariable(CURRENT_MESSAGE, message);
fillMessage(dataInputAssociations, execution);
ProcessEngineConfigurationImpl processEngineConfig = Context.getProcessEngineConfiguration();
MessageInstance receivedMessage = operation.sendMessage(message, processEngineConfig.getWsOverridenEndpointAddresses());
execution.setVariable(CURRENT_MESSAGE, receivedMessage);
if (ioSpecification != null && ioSpecification.getDataOutputRefs().size() > 0) {
String firstDataOutputName = ioSpecification.getDataOutputRefs().get(0);
if (firstDataOutputName != null) {
ItemInstance outputItem = (ItemInstance) execution.getVariable(firstDataOutputName);
outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
}
}
returnMessage(dataOutputAssociations, execution);
execution.setVariable(CURRENT_MESSAGE, null);
leave(execution);
} catch (Exception exc) {
Throwable cause = exc;
BpmnError error = null;
while (cause != null) {
if (cause instanceof BpmnError) {
error = (BpmnError) cause;
break;
}
cause = cause.getCause();
}
if (error != null) {
ErrorPropagation.propagateError(error, execution);
} else if (exc instanceof RuntimeException) {
throw (RuntimeException) exc;
}
}
}
Aggregations