diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/conf/FlowableConfiguration.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/conf/FlowableConfiguration.java index 213f37b4f..f7e6b1b8a 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/conf/FlowableConfiguration.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/conf/FlowableConfiguration.java @@ -1,6 +1,7 @@ package cn.axzo.workflow.core.conf; import cn.axzo.workflow.core.engine.behavior.CustomActivityBehaviorFactory; +import cn.axzo.workflow.core.engine.cmd.CustomCommandContextFactory; import cn.axzo.workflow.core.engine.id.DistributedTimeBasedIdGenerator; import cn.axzo.workflow.core.engine.job.AsyncAbortProcessInstanceHandler; import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler; @@ -68,6 +69,7 @@ public class FlowableConfiguration { configuration.setDefaultFailedJobWaitTime(30); configuration.setAsyncFailedJobWaitTime(30); configuration.setCustomAsyncRunnableExecutionExceptionHandlers(Lists.newArrayList(new CustomAsyncRunnableExecutionExceptionHandler())); + configuration.setCommandContextFactory(new CustomCommandContextFactory()); }; } diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java new file mode 100644 index 000000000..510d6d221 --- /dev/null +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java @@ -0,0 +1,44 @@ +package cn.axzo.workflow.core.engine.cmd; + +import cn.axzo.workflow.core.common.exception.WorkflowEngineException; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.common.engine.api.FlowableOptimisticLockingException; +import org.flowable.common.engine.impl.interceptor.Command; +import org.flowable.common.engine.impl.interceptor.CommandContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TODO + * + * @author wangli + * @since 2024/5/21 09:46 + */ +public class CustomCommandContext extends CommandContext { + private static final Logger LOGGER = LoggerFactory.getLogger(CommandContext.class); + + public CustomCommandContext(Command command) { + super(command); + } + + @Override + protected void logException() { + if (exception instanceof FlowableException && !((FlowableException) exception).isLogged()) { + return; + } + + if (exception instanceof FlowableOptimisticLockingException) { + // reduce log level, as normally we're not interested in logging this exception + LOGGER.debug("Optimistic locking exception : {}", exception.getMessage(), exception); + + } else if (exception instanceof FlowableException && ((FlowableException) exception).isReduceLogLevel()) { + // reduce log level, because this may have been caused because of job deletion due to cancelActiviti="true" + LOGGER.info("Error while closing command context", exception); + } else if (exception instanceof WorkflowEngineException) { + LOGGER.warn("Workflow error while closing command context", exception); + } else { + LOGGER.error("Error while closing command context", exception); + + } + } +} diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContextFactory.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContextFactory.java new file mode 100644 index 000000000..df53139bf --- /dev/null +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContextFactory.java @@ -0,0 +1,21 @@ +package cn.axzo.workflow.core.engine.cmd; + +import org.flowable.common.engine.impl.interceptor.Command; +import org.flowable.common.engine.impl.interceptor.CommandContext; +import org.flowable.common.engine.impl.interceptor.CommandContextFactory; + +/** + * TODO + * + * @author wangli + * @since 2024/5/21 09:45 + */ +public class CustomCommandContextFactory extends CommandContextFactory { + + @Override + public CommandContext createCommandContext(Command cmd) { + CommandContext commandContext = new CustomCommandContext(cmd); + commandContext.setSessionFactories(sessionFactories); + return commandContext; + } +}