mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancement #ID8XF9 对QLExpress4的支持
This commit is contained in:
@@ -182,13 +182,10 @@ public class LiteFlowChainELBuilder {
|
|||||||
return this;
|
return this;
|
||||||
} catch (QLException e) {
|
} catch (QLException e) {
|
||||||
// EL 底层会包装异常,这里是曲线处理
|
// EL 底层会包装异常,这里是曲线处理
|
||||||
if (ObjectUtil.isNotNull(e.getCause()) && Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) {
|
if (ObjectUtil.isNotNull(e.getCause())) {
|
||||||
// 构建错误信息
|
// 构建错误信息
|
||||||
String msg = buildDataNotFoundExceptionMsg(elStr);
|
String msg = buildDataNotFoundExceptionMsg(elStr);
|
||||||
throw new ELParseException(msg);
|
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{
|
}else{
|
||||||
throw new ELParseException(StrUtil.isNotBlank(e.getMessage()) ? e.getMessage() : "Unknown EL parse error");
|
throw new ELParseException(StrUtil.isNotBlank(e.getMessage()) ? e.getMessage() : "Unknown EL parse error");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class LiteflowContextRegexMatcher {
|
|||||||
try{
|
try{
|
||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
context.put(entry.getKey(), entry.getValue());
|
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();
|
result = expressResult.getResult();
|
||||||
if (result != null){
|
if (result != null){
|
||||||
break;
|
break;
|
||||||
@@ -55,7 +55,7 @@ public class LiteflowContextRegexMatcher {
|
|||||||
// 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取
|
// 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取
|
||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
context.put("contextMap", contextMap);
|
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();
|
result = expressResult.getResult();
|
||||||
}catch (Exception ignore){}
|
}catch (Exception ignore){}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ public class LiteflowContextRegexMatcher {
|
|||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
context.put(entry.getKey(), entry.getValue());
|
context.put(entry.getKey(), entry.getValue());
|
||||||
tupleList.forEach(tuple -> context.put(tuple.getA(), args[tuple.getB()]));
|
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;
|
flag = true;
|
||||||
break;
|
break;
|
||||||
}catch (Exception ignore){}
|
}catch (Exception ignore){}
|
||||||
@@ -97,7 +97,7 @@ public class LiteflowContextRegexMatcher {
|
|||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
context.put("contextMap", contextMap);
|
context.put("contextMap", contextMap);
|
||||||
tupleList.forEach(tuple -> context.put(tuple.getA(), args[tuple.getB()]));
|
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){}
|
}catch (Exception ignore){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.yomahub.liteflow.script.qlexpress;
|
package com.yomahub.liteflow.script.qlexpress;
|
||||||
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.qlexpress4.Express4Runner;
|
import com.alibaba.qlexpress4.Express4Runner;
|
||||||
import com.alibaba.qlexpress4.QLResult;
|
import com.alibaba.qlexpress4.QLResult;
|
||||||
import com.alibaba.qlexpress4.InitOptions;
|
import com.alibaba.qlexpress4.InitOptions;
|
||||||
import com.alibaba.qlexpress4.QLOptions;
|
import com.alibaba.qlexpress4.QLOptions;
|
||||||
|
import com.alibaba.qlexpress4.security.QLSecurityStrategy;
|
||||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||||
@@ -13,10 +13,7 @@ import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
|||||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -37,7 +34,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptExecutor init() {
|
public ScriptExecutor init() {
|
||||||
expressRunner = new Express4Runner(InitOptions.DEFAULT_OPTIONS);
|
expressRunner = new Express4Runner(InitOptions.builder().securityStrategy(QLSecurityStrategy.open()).build());
|
||||||
//如果有生命周期则执行相应生命周期实现
|
//如果有生命周期则执行相应生命周期实现
|
||||||
super.lifeCycle(expressRunner);
|
super.lifeCycle(expressRunner);
|
||||||
return this;
|
return this;
|
||||||
@@ -46,7 +43,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void load(String nodeId, String script) {
|
public void load(String nodeId, String script) {
|
||||||
try {
|
try {
|
||||||
// QLExpress4 不需要预编译,直接存储脚本内容
|
expressRunner.parseToDefinitionWithCache(script);
|
||||||
compiledScriptMap.put(nodeId, script);
|
compiledScriptMap.put(nodeId, script);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@@ -78,7 +75,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
|||||||
|
|
||||||
bindParam(wrap, context::put, context::putIfAbsent);
|
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();
|
return expressResult.getResult();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@@ -89,8 +86,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public void cleanCache() {
|
public void cleanCache() {
|
||||||
compiledScriptMap.clear();
|
compiledScriptMap.clear();
|
||||||
// QLExpress4 没有 clearExpressCache 方法,重新初始化 runner
|
expressRunner.clearCompileCache();
|
||||||
expressRunner = new Express4Runner(InitOptions.DEFAULT_OPTIONS);
|
|
||||||
//如果有生命周期则执行相应生命周期实现
|
//如果有生命周期则执行相应生命周期实现
|
||||||
super.lifeCycle(expressRunner);
|
super.lifeCycle(expressRunner);
|
||||||
}
|
}
|
||||||
@@ -102,8 +98,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object compile(String script) throws Exception {
|
public Object compile(String script) throws Exception {
|
||||||
// QLExpress4 不支持预编译,返回 null
|
return expressRunner.parseToDefinitionWithCache(script);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user