From bb9ca71a80002af1a1bebf56e9499ddaa40fc44d Mon Sep 17 00:00:00 2001 From: luoyi <972849752@qq.com> Date: Wed, 9 Jul 2025 18:34:48 +0800 Subject: [PATCH] =?UTF-8?q?bug=20FlowExecutor.execute2RespWithEL=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=BC=82=E5=B8=B8=E7=BB=93=E6=9E=9C=EF=BC=8C?= =?UTF-8?q?=E5=B0=BD=E9=87=8F=E9=81=BF=E5=85=8D=E5=BC=82=E5=B8=B8=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=8A=9B=E5=87=BA=EF=BC=9B=E7=A7=BB=E9=99=A4=20LiteFl?= =?UTF-8?q?owChainELBuilder.setElMd5=20=E6=96=B9=E6=B3=95=EF=BC=9B?= =?UTF-8?q?=E8=B0=83=E6=95=B4=20elMd5Map=20=E5=AD=98=E5=82=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 5 --- .../yomahub/liteflow/core/FlowExecutor.java | 18 ++++------ .../com/yomahub/liteflow/flow/FlowBus.java | 3 +- .../liteflow/flow/LiteflowResponse.java | 35 ++++++++++++------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index f19286306..cad9d1161 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -275,11 +275,6 @@ public class LiteFlowChainELBuilder { } } - public LiteFlowChainELBuilder setElMd5(String md5) { - this.chain.setElMd5(md5); - return this; - } - public void build() { this.chain.setRouteItem(this.route); this.chain.setConditionList(this.conditionList); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 1648fa379..628d7f70b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -266,9 +266,8 @@ public class FlowExecutor { * * @param elStr EL 表达式 * @return LiteflowResponse - * @throws ELParseException */ - public LiteflowResponse execute2RespWithEL(String elStr) throws Exception { + public LiteflowResponse execute2RespWithEL(String elStr) { return this.execute2RespWithEL(elStr, null, null, DefaultContext.class); } @@ -278,9 +277,8 @@ public class FlowExecutor { * @param elStr EL 表达式 * @param param 入参 * @return LiteflowResponse - * @throws ELParseException */ - public LiteflowResponse execute2RespWithEL(String elStr, Object param) throws Exception { + public LiteflowResponse execute2RespWithEL(String elStr, Object param) { return this.execute2RespWithEL(elStr, param, null, DefaultContext.class); } @@ -292,9 +290,8 @@ public class FlowExecutor { * @param requestId 请求 ID * @param contextBeanClazzArray 上下文 Class * @return LiteflowResponse - * @throws ELParseException */ - public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class... contextBeanClazzArray) throws Exception { + public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class... contextBeanClazzArray) { return this.execute2RespWithEL(elStr, param, requestId, contextBeanClazzArray, null); } @@ -306,9 +303,8 @@ public class FlowExecutor { * @param requestId 请求 ID * @param contextBeanArray 上下文对象 * @return LiteflowResponse - * @throws ELParseException */ - public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Object... contextBeanArray) throws Exception { + public LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Object... contextBeanArray) { return this.execute2RespWithEL(elStr, param, requestId, null, contextBeanArray); } @@ -321,9 +317,8 @@ public class FlowExecutor { * @param contextBeanClazzArray 上下文 Class 数组 * @param contextBeanArray 上下文对象数组 * @return LiteflowResponse - * @throws ELParseException */ - private LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray) throws Exception { + private LiteflowResponse execute2RespWithEL(String elStr, Object param, String requestId, Class[] contextBeanClazzArray, Object[] contextBeanArray) { // 规范化 el 表达式 String normalizedEl = ElRegexUtil.normalize(elStr); @@ -332,7 +327,7 @@ public class FlowExecutor { if (!validationResp.isSuccess()) { // 实际封装的是 ELParseException 类型 - throw validationResp.getCause(); + return LiteflowResponse.newMainResponse(validationResp.getCause()); } // 计算 EL MD5 值,并检查对应的 chain 是否已加载到内存中 @@ -346,7 +341,6 @@ public class FlowExecutor { LiteFlowChainELBuilder.createChain() .setChainId(chainId) .setEL(normalizedEl) - .setElMd5(elMd5) .build(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 9448ceb69..52ba5cc46 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -45,6 +45,7 @@ import com.yomahub.liteflow.spi.holder.DeclComponentParserHolder; import com.yomahub.liteflow.util.CopyOnWriteHashMap; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -81,7 +82,7 @@ public class FlowBus { chainMap = new CopyOnWriteHashMap<>(); nodeMap = new CopyOnWriteHashMap<>(); fallbackNodeMap = new CopyOnWriteHashMap<>(); - elMd5Map = new CopyOnWriteHashMap<>(); + elMd5Map = new ConcurrentHashMap<>(); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java index 4c24df652..d5eec0e8e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java @@ -5,9 +5,10 @@ import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.flow.entity.CmpStep; import com.yomahub.liteflow.slot.Slot; -import java.io.Serializable; -import java.util.*; -import java.util.function.Consumer; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; /** * 执行结果封装类 @@ -35,6 +36,12 @@ public class LiteflowResponse { return newResponse(slot, slot.getException()); } + public static LiteflowResponse newMainResponse(Exception exception) { + LiteflowResponse response = new LiteflowResponse(); + response.setExceptionParams(exception); + return response; + } + public static LiteflowResponse newInnerResponse(String chainId, Slot slot) { return newResponse(slot, slot.getSubException(chainId)); } @@ -42,20 +49,22 @@ public class LiteflowResponse { private static LiteflowResponse newResponse(Slot slot, Exception e) { LiteflowResponse response = new LiteflowResponse(); response.setChainId(slot.getChainId()); - if (e != null) { - response.setSuccess(false); - response.setCause(e); - response.setMessage(response.getCause().getMessage()); - response.setCode(response.getCause() instanceof LiteFlowException - ? ((LiteFlowException) response.getCause()).getCode() : null); - } - else { - response.setSuccess(true); - } + response.setExceptionParams(e); response.setSlot(slot); return response; } + private void setExceptionParams(Exception exception) { + if (exception != null) { + this.setSuccess(false); + this.setCause(exception); + this.setMessage(exception.getMessage()); + this.setCode(exception instanceof LiteFlowException ? ((LiteFlowException) exception).getCode() : null); + } else { + this.setSuccess(true); + } + } + public boolean isSuccess() { return success; }