use of org.activiti.bpmn.model.SendTask 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.bpmn.model.SendTask in project Activiti by Activiti.
the class SendTaskXMLConverter method writeExtensionChildElements.
@Override
protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
SendTask sendTask = (SendTask) element;
didWriteExtensionStartElement = FieldExtensionExport.writeFieldExtensions(sendTask.getFieldExtensions(), didWriteExtensionStartElement, xtw);
return didWriteExtensionStartElement;
}
use of org.activiti.bpmn.model.SendTask in project Activiti by Activiti.
the class SendTaskXMLConverter method convertXMLToElement.
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
SendTask sendTask = new SendTask();
BpmnXMLUtil.addXMLLocation(sendTask, xtr);
sendTask.setType(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TYPE));
if ("##WebService".equals(xtr.getAttributeValue(null, ATTRIBUTE_TASK_IMPLEMENTATION))) {
sendTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE);
sendTask.setOperationRef(parseOperationRef(xtr.getAttributeValue(null, ATTRIBUTE_TASK_OPERATION_REF), model));
}
parseChildElements(getXMLElementName(), sendTask, model, xtr);
return sendTask;
}
use of org.activiti.bpmn.model.SendTask in project Activiti by Activiti.
the class FieldExtensionParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (!accepts(parentElement))
return;
FieldExtension extension = new FieldExtension();
BpmnXMLUtil.addXMLLocation(extension, xtr);
extension.setFieldName(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_NAME));
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING))) {
extension.setStringValue(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING));
} else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION))) {
extension.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION));
} else {
boolean readyWithFieldExtension = false;
try {
while (readyWithFieldExtension == false && xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) {
extension.setStringValue(xtr.getElementText().trim());
} else if (xtr.isStartElement() && ATTRIBUTE_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
extension.setExpression(xtr.getElementText().trim());
} else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
readyWithFieldExtension = true;
}
}
} catch (Exception e) {
LOGGER.warn("Error parsing field extension child elements", e);
}
}
if (parentElement instanceof ActivitiListener) {
((ActivitiListener) parentElement).getFieldExtensions().add(extension);
} else if (parentElement instanceof ServiceTask) {
((ServiceTask) parentElement).getFieldExtensions().add(extension);
} else if (parentElement instanceof SendTask) {
((SendTask) parentElement).getFieldExtensions().add(extension);
} else if (parentElement instanceof MessageEventDefinition) {
((MessageEventDefinition) parentElement).getFieldExtensions().add(extension);
}
}
Aggregations