use of org.activiti.engine.impl.bpmn.webservice.MessageInstance 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.webservice.MessageInstance 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;
}
}
}
use of org.activiti.engine.impl.bpmn.webservice.MessageInstance in project Activiti by Activiti.
the class WSOperation method createResponseMessage.
private MessageInstance createResponseMessage(Object[] results, Operation operation) {
MessageInstance message = null;
MessageDefinition outMessage = operation.getOutMessage();
if (outMessage != null) {
message = outMessage.createInstance();
message.getStructureInstance().loadFrom(results);
}
return message;
}
Aggregations