public override void Execute(IExecutionEntity execution) { try { bool isSkipExpressionEnabled = SkipExpressionUtil.IsSkipExpressionEnabled(execution, skipExpression); if (!isSkipExpressionEnabled || (isSkipExpressionEnabled && !SkipExpressionUtil.ShouldSkipFlowElement(execution, skipExpression))) { if (Context.ProcessEngineConfiguration.EnableProcessDefinitionInfoCache) { JToken taskElementProperties = Context.GetBpmnOverrideElementProperties(serviceTaskId, execution.ProcessDefinitionId); if (taskElementProperties != null && taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_EXPRESSION] != null) { string overrideExpression = taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_EXPRESSION].ToString(); if (!string.IsNullOrWhiteSpace(overrideExpression) && !overrideExpression.Equals(expression.ExpressionText)) { expression = Context.ProcessEngineConfiguration.ExpressionManager.CreateExpression(overrideExpression); } } } object value = expression.GetValue(execution); if (resultVariable is object) { execution.SetVariable(resultVariable, value); } } Leave(execution); } catch (Exception exc) { Exception cause = exc; BpmnError error = null; while (cause != null) { if (cause is BpmnError) { error = (BpmnError)cause; break; } cause = cause.InnerException; } if (error != null) { ErrorPropagation.PropagateError(error, execution); } else { throw new ActivitiException("Could not execute service task expression", exc); } } }
/// <summary> /// Decides how to propagate the exception properly, e.g. as bpmn error or "normal" error. </summary> /// <param name="execution"> the current execution </param> /// <param name="ex"> the exception to propagate </param> /// <exception cref="Exception"> if no error handler could be found </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static void propagateException(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution execution, Exception ex) throws Exception public static void propagateException(ActivityExecution execution, Exception ex) { BpmnError bpmnError = checkIfCauseOfExceptionIsBpmnError(ex); if (bpmnError != null) { propagateBpmnError(bpmnError, execution); } else { propagateExceptionAsError(ex, execution); } }
public virtual void BpmnError(string errorCode) { EnsureActive(); IActivityExecution activityExecution = GetExecution(); BpmnError bpmnError = new BpmnError(errorCode); try { ExternalTaskActivityBehavior behavior = ((ExternalTaskActivityBehavior)activityExecution.Activity.ActivityBehavior); behavior.PropagateBpmnError(bpmnError, activityExecution); } catch (System.Exception ex) { throw ProcessEngineLogger.CmdLogger.ExceptionBpmnErrorPropagationFailed(errorCode, ex); } }
public virtual void testConnectorBpmnErrorThrownInScriptResourceNoAsyncAfterJobIsCreated() { // given IDictionary <string, object> variables = new Dictionary <string, object>(); variables["throwInMapping"] = "in"; variables["exception"] = new BpmnError("error"); // when runtimeService.startProcessInstanceByKey("testProcess", variables); // then // we will only reach the user task if the BPMNError from the script was handled by the boundary event Task task = taskService.createTaskQuery().singleResult(); assertThat(task.Name, @is("User Task")); // no job is created assertThat(Convert.ToInt64(managementService.createJobQuery().count()), @is(0l)); }
private void ExecuteDebugMode(IExecutionEntity execution) { execution.CurrentFlowElement.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> pElements); if (pElements != null) { var parameter = new WebApiParameter(execution, pElements); string dataObj = parameter.VariableName; if (!string.IsNullOrEmpty(dataObj)) { try { execution.SetVariable(dataObj, parameter.MockData); } catch (Exception ex) { logger.LogError($"调用服务失败MockData=${dataObj}\r\n${ex.Message}${ex.StackTrace}"); string errorCode = execution.CurrentFlowElement.GetExtensionElementAttributeValue("errorCode"); BpmnError error; if (string.IsNullOrWhiteSpace(errorCode) == false) { error = new BpmnError(errorCode, ex.Message); } else { error = new BpmnError(Context.CommandContext.ProcessEngineConfiguration.WebApiErrorCode, ex.Message); } ErrorPropagation.PropagateError(error, execution); } } } }
public override void Execute(IExecutionEntity execution) { BpmnModel bpmnModel = ProcessDefinitionUtil.GetBpmnModel(execution.ProcessDefinitionId); FlowElement flowElement = execution.CurrentFlowElement; IOSpecification ioSpecification; string operationRef; IList <DataAssociation> dataInputAssociations; IList <DataAssociation> dataOutputAssociations; if (flowElement is SendTask sendTask) { ioSpecification = sendTask.IoSpecification; operationRef = sendTask.OperationRef; dataInputAssociations = sendTask.DataInputAssociations; dataOutputAssociations = sendTask.DataOutputAssociations; } else if (flowElement is ServiceTask serviceTask) { ioSpecification = serviceTask.IoSpecification; operationRef = serviceTask.OperationRef; dataInputAssociations = serviceTask.DataInputAssociations; dataOutputAssociations = serviceTask.DataOutputAssociations; } else { throw new ActivitiException("Unsupported flow element type " + flowElement); } MessageInstance message = null; FillDefinitionMaps(bpmnModel); Webservice.Operation operation = operationMap[operationRef]; try { if (ioSpecification != null) { InitializeIoSpecification(ioSpecification, execution, bpmnModel); if (ioSpecification.DataInputRefs.Count > 0) { string firstDataInputName = ioSpecification.DataInputRefs[0]; ItemInstance inputItem = (ItemInstance)execution.GetVariable(firstDataInputName); message = new MessageInstance(operation.InMessage, inputItem); } } else { message = operation.InMessage.CreateInstance(); } execution.SetVariable(CURRENT_MESSAGE, message); FillMessage(dataInputAssociations, execution); ProcessEngineConfigurationImpl processEngineConfig = Context.ProcessEngineConfiguration; MessageInstance receivedMessage = operation.SendMessage(message, processEngineConfig.WsOverridenEndpointAddresses); execution.SetVariable(CURRENT_MESSAGE, receivedMessage); if (ioSpecification != null && ioSpecification.DataOutputRefs.Count > 0) { string firstDataOutputName = ioSpecification.DataOutputRefs[0]; if (!(firstDataOutputName is null)) { ItemInstance outputItem = (ItemInstance)execution.GetVariable(firstDataOutputName); outputItem.StructureInstance.LoadFrom(receivedMessage.StructureInstance.ToArray()); } } ReturnMessage(dataOutputAssociations, execution); execution.SetVariable(CURRENT_MESSAGE, null); Leave(execution); } catch (Exception exc) { Exception cause = exc; BpmnError error = null; while (cause != null) { if (cause is BpmnError) { error = (BpmnError)cause; break; } cause = cause.InnerException; } if (error != null) { ErrorPropagation.PropagateError(error, execution); } else if (exc is Exception) { throw (Exception)exc; } } }
public static void PropagateError(BpmnError error, IExecutionEntity execution) { PropagateError(error.ErrorCode, execution); }
/// <summary> /// Overrides the propagateBpmnError method to made it public. /// Is used to propagate the bpmn error from an external ITask. /// </summary> /// <param name="error"> the error which should be propagated </param> /// <param name="execution"> the current activity execution </param> /// <exception cref="exception"> throwsn an exception if no handler was found </exception> protected internal override void PropagateBpmnError(BpmnError error, IActivityExecution execution) { base.PropagateBpmnError(error, execution); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static void propagateBpmnError(org.camunda.bpm.engine.delegate.BpmnError error, org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution execution) throws Exception public static void propagateBpmnError(BpmnError error, ActivityExecution execution) { propagateError(error.ErrorCode, error.Message, null, execution); }
/// <summary> /// /// </summary> /// <param name="execution"></param> public override void Execute(IExecutionEntity execution) { execution.CurrentFlowElement.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> pElements); _ = bool.TryParse(execution.GetVariableInstance(DynamicBpmnConstants.PORCESS_DEBUGMODE_VARIABLE)?.Value?.ToString(), out var debugMode); WebApiParameter parameter = new WebApiParameter(execution, pElements); if (parameter.IsMock.HasValue ? parameter.IsMock.Value : debugMode) { ExecuteDebugMode(execution); } else { if (pElements != null) { Stopwatch sw = new Stopwatch(); string url = null; object request = null; try { sw.Start(); url = parameter.Url; string dataObj = parameter.VariableName; request = parameter.Request; string method = parameter.Method; var httpProxy = ProcessEngineServiceProvider.Resolve <IHttpClientProxy>(); HttpContext httpContext = ProcessEngineServiceProvider.Resolve <IHttpContextAccessor>()?.HttpContext; if (httpContext == null) { var uid = string.IsNullOrWhiteSpace(execution.StartUserId) ? Guid.NewGuid().ToString() : execution.StartUserId; httpProxy.SetHttpClientRequestAccessToken(uid, execution.TenantId, isSessionHeader: false); } switch (method?.ToLower()) { default: case "get": ExecuteGet(execution, url, request, dataObj, httpProxy); break; case "post": ExecutePost(execution, url, request, dataObj, httpProxy); break; } sw.Stop(); logger.LogInformation($"调用外部服务共计({sw.ElapsedMilliseconds}ms) url={url} request={(request is null ? "" : JsonConvert.SerializeObject(request))}"); } catch (Exception ex) { sw.Stop(); logger.LogError($"调用外部服务失败({sw.ElapsedMilliseconds}ms) url={url} request={(request is null ? "" : JsonConvert.SerializeObject(request))}:\r\n" + ex.Message + ex.StackTrace); string errorCode = execution.CurrentFlowElement.GetExtensionElementAttributeValue("errorCode"); BpmnError error; if (string.IsNullOrWhiteSpace(errorCode) == false) { error = new BpmnError(errorCode, ex.Message); } else { error = new BpmnError(Context.CommandContext.ProcessEngineConfiguration.WebApiErrorCode, ex.Message); } ErrorPropagation.PropagateError(error, execution); } } } Leave(execution); }
protected internal virtual void PropagateBpmnError(BpmnError error, IActivityExecution execution) { PropagateError(error.ErrorCode, error.Message, null, execution); }
public override void Execute(IExecutionEntity execution) { try { bool isSkipExpressionEnabled = SkipExpressionUtil.IsSkipExpressionEnabled(execution, skipExpression); if (!isSkipExpressionEnabled || (isSkipExpressionEnabled && !SkipExpressionUtil.ShouldSkipFlowElement(execution, skipExpression))) { if (Context.ProcessEngineConfiguration.EnableProcessDefinitionInfoCache) { JToken taskElementProperties = Context.GetBpmnOverrideElementProperties(serviceTaskId, execution.ProcessDefinitionId); if (taskElementProperties != null && taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION] != null) { string overrideExpression = taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION].ToString(); if (!string.IsNullOrWhiteSpace(overrideExpression) && !overrideExpression.Equals(expression.ExpressionText)) { expression = Context.ProcessEngineConfiguration.ExpressionManager.CreateExpression(overrideExpression); } } } object @delegate = DelegateExpressionUtil.ResolveDelegateExpression(expression, execution, fieldDeclarations); if (@delegate is IActivityBehavior) { if (@delegate is AbstractBpmnActivityBehavior) { ((AbstractBpmnActivityBehavior)@delegate).MultiInstanceActivityBehavior = MultiInstanceActivityBehavior; } Context.ProcessEngineConfiguration.DelegateInterceptor.HandleInvocation(new ActivityBehaviorInvocation((IActivityBehavior)@delegate, execution)); } else if (@delegate is ICSharpDelegate) { Context.ProcessEngineConfiguration.DelegateInterceptor.HandleInvocation(new CSharpDelegateInvocation((ICSharpDelegate)@delegate, execution)); Leave(execution); } else { throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of " + typeof(IActivityBehavior) + " nor " + typeof(ICSharpDelegate)); } } else { Leave(execution); } } catch (Exception exc) { Exception cause = exc; BpmnError error = null; while (cause != null) { if (cause is BpmnError) { error = (BpmnError)cause; break; } cause = cause.InnerException; } if (error != null) { ErrorPropagation.PropagateError(error, execution); } else { throw new ActivitiException(exc.Message, exc); } } }