Search in sources :

Example 1 with MessageInstance

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;
        }
    }
}
Also used : MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 2 with MessageInstance

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;
        }
    }
}
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 3 with MessageInstance

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;
}
Also used : MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) MessageDefinition(org.activiti.engine.impl.bpmn.webservice.MessageDefinition)

Aggregations

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