From 36191969d4b986d2b0aa3567b1672eaf269c1575 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Sat, 29 Nov 2025 01:27:50 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#ID8XF9=20=E5=AF=B9QLExpress4?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 5 +---- .../util/LiteflowContextRegexMatcher.java | 8 ++++---- .../qlexpress/QLExpressScriptExecutor.java | 17 ++++++----------- 3 files changed, 11 insertions(+), 19 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 aa60c3b49..2479619b1 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 @@ -182,13 +182,10 @@ public class LiteFlowChainELBuilder { return this; } catch (QLException e) { // EL 底层会包装异常,这里是曲线处理 - if (ObjectUtil.isNotNull(e.getCause()) && Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) { + if (ObjectUtil.isNotNull(e.getCause())) { // 构建错误信息 String msg = buildDataNotFoundExceptionMsg(elStr); throw new ELParseException(msg); - }else if (ObjectUtil.isNotNull(e.getCause())){ - String causeMsg = e.getCause().getMessage(); - throw new ELParseException(StrUtil.isNotBlank(causeMsg) ? causeMsg : e.getMessage()); }else{ throw new ELParseException(StrUtil.isNotBlank(e.getMessage()) ? e.getMessage() : "Unknown EL parse error"); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java index c8923e3cb..1ba6e11b9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteflowContextRegexMatcher.java @@ -42,7 +42,7 @@ public class LiteflowContextRegexMatcher { try{ Map context = new HashMap<>(); context.put(entry.getKey(), entry.getValue()); - QLResult expressResult = expressRunner.execute(entry.getKey() + "." + regPattern, context, QLOptions.DEFAULT_OPTIONS); + QLResult expressResult = expressRunner.execute(entry.getKey() + "." + regPattern, context, QLOptions.builder().cache(true).build()); result = expressResult.getResult(); if (result != null){ break; @@ -55,7 +55,7 @@ public class LiteflowContextRegexMatcher { // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取 Map context = new HashMap<>(); context.put("contextMap", contextMap); - QLResult expressResult = expressRunner.execute("contextMap." + regPattern, context, QLOptions.DEFAULT_OPTIONS); + QLResult expressResult = expressRunner.execute("contextMap." + regPattern, context, QLOptions.builder().cache(true).build()); result = expressResult.getResult(); }catch (Exception ignore){} } @@ -84,7 +84,7 @@ public class LiteflowContextRegexMatcher { Map context = new HashMap<>(); context.put(entry.getKey(), entry.getValue()); tupleList.forEach(tuple -> context.put(tuple.getA(), args[tuple.getB()])); - expressRunner.execute(StrUtil.format("{}.{}({})", entry.getKey(), methodExpress, argStr), context, QLOptions.DEFAULT_OPTIONS); + expressRunner.execute(StrUtil.format("{}.{}({})", entry.getKey(), methodExpress, argStr), context, QLOptions.builder().cache(true).build()); flag = true; break; }catch (Exception ignore){} @@ -97,7 +97,7 @@ public class LiteflowContextRegexMatcher { Map context = new HashMap<>(); context.put("contextMap", contextMap); tupleList.forEach(tuple -> context.put(tuple.getA(), args[tuple.getB()])); - expressRunner.execute(StrUtil.format("contextMap.{}({})", methodExpress, argStr), context, QLOptions.DEFAULT_OPTIONS); + expressRunner.execute(StrUtil.format("contextMap.{}({})", methodExpress, argStr), context, QLOptions.builder().cache(true).build()); }catch (Exception ignore){} } } diff --git a/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java b/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java index 1961e590f..c0150d87b 100644 --- a/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java @@ -1,11 +1,11 @@ package com.yomahub.liteflow.script.qlexpress; -import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.qlexpress4.Express4Runner; import com.alibaba.qlexpress4.QLResult; import com.alibaba.qlexpress4.InitOptions; import com.alibaba.qlexpress4.QLOptions; +import com.alibaba.qlexpress4.security.QLSecurityStrategy; import com.yomahub.liteflow.enums.ScriptTypeEnum; import com.yomahub.liteflow.script.ScriptExecuteWrap; import com.yomahub.liteflow.script.ScriptExecutor; @@ -13,10 +13,7 @@ import com.yomahub.liteflow.script.exception.ScriptLoadException; import com.yomahub.liteflow.util.CopyOnWriteHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import javax.script.ScriptException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,7 +34,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { @Override public ScriptExecutor init() { - expressRunner = new Express4Runner(InitOptions.DEFAULT_OPTIONS); + expressRunner = new Express4Runner(InitOptions.builder().securityStrategy(QLSecurityStrategy.open()).build()); //如果有生命周期则执行相应生命周期实现 super.lifeCycle(expressRunner); return this; @@ -46,7 +43,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { @Override public void load(String nodeId, String script) { try { - // QLExpress4 不需要预编译,直接存储脚本内容 + expressRunner.parseToDefinitionWithCache(script); compiledScriptMap.put(nodeId, script); } catch (Exception e) { @@ -78,7 +75,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { bindParam(wrap, context::put, context::putIfAbsent); - QLResult expressResult = expressRunner.execute(script, context, QLOptions.DEFAULT_OPTIONS); + QLResult expressResult = expressRunner.execute(script, context, QLOptions.builder().cache(true).build()); return expressResult.getResult(); } catch (Exception e) { @@ -89,8 +86,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { @Override public void cleanCache() { compiledScriptMap.clear(); - // QLExpress4 没有 clearExpressCache 方法,重新初始化 runner - expressRunner = new Express4Runner(InitOptions.DEFAULT_OPTIONS); + expressRunner.clearCompileCache(); //如果有生命周期则执行相应生命周期实现 super.lifeCycle(expressRunner); } @@ -102,8 +98,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { @Override public Object compile(String script) throws Exception { - // QLExpress4 不支持预编译,返回 null - return null; + return expressRunner.parseToDefinitionWithCache(script); } }