Search in sources :

Example 1 with SendTask

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;
        }
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ActivitiException(org.activiti.engine.ActivitiException) AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) DataAssociation(org.activiti.bpmn.model.DataAssociation) Operation(org.activiti.engine.impl.bpmn.webservice.Operation) WSOperation(org.activiti.engine.impl.webservice.WSOperation) ActivitiException(org.activiti.engine.ActivitiException) BpmnModel(org.activiti.bpmn.model.BpmnModel) MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) FlowElement(org.activiti.bpmn.model.FlowElement) IOSpecification(org.activiti.bpmn.model.IOSpecification) SendTask(org.activiti.bpmn.model.SendTask) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 2 with SendTask

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;
}
Also used : SendTask(org.activiti.bpmn.model.SendTask)

Example 3 with SendTask

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;
}
Also used : SendTask(org.activiti.bpmn.model.SendTask)

Example 4 with 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);
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) FieldExtension(org.activiti.bpmn.model.FieldExtension) SendTask(org.activiti.bpmn.model.SendTask) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Aggregations

SendTask (org.activiti.bpmn.model.SendTask)4 ServiceTask (org.activiti.bpmn.model.ServiceTask)2 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 DataAssociation (org.activiti.bpmn.model.DataAssociation)1 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 IOSpecification (org.activiti.bpmn.model.IOSpecification)1 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)1 ActivitiException (org.activiti.engine.ActivitiException)1 BpmnError (org.activiti.engine.delegate.BpmnError)1 AbstractDataAssociation (org.activiti.engine.impl.bpmn.data.AbstractDataAssociation)1 ItemInstance (org.activiti.engine.impl.bpmn.data.ItemInstance)1 MessageInstance (org.activiti.engine.impl.bpmn.webservice.MessageInstance)1 Operation (org.activiti.engine.impl.bpmn.webservice.Operation)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 WSOperation (org.activiti.engine.impl.webservice.WSOperation)1