From 2bd8e0a86ba235929f325d2753bd842bb6387ff4 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Wed, 30 Nov 2022 16:25:08 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I631ZF=20groovy=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E6=97=B6=EF=BC=8C=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8A=9B=E5=87=BA=E5=90=8E=E8=A2=AB=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=B1=E8=B4=A5=E5=BC=82=E5=B8=B8=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graaljs/GraalJavaScriptExecutor.java | 1 - .../script/groovy/GroovyScriptExecutor.java | 8 +++- .../script/javascript/JavaScriptExecutor.java | 1 - .../groovy/throwException/TestException.java | 13 +++++++ .../ThrowExceptionScriptGroovyELTest.java | 39 +++++++++++++++++++ .../groovy/throwException/cmp/ACmp.java | 20 ++++++++++ .../throwException/application.properties | 1 + .../test/resources/throwException/flow.xml | 21 ++++++++++ 8 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/flow.xml diff --git a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java index 083d48c97..23ed458cb 100644 --- a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java @@ -100,7 +100,6 @@ public class GraalJavaScriptExecutor implements ScriptExecutor { } return value; } catch (Exception e){ - log.error(e.getMessage(), e); throw e; } } diff --git a/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java b/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java index c85cb976c..2cf6e2a1e 100644 --- a/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java @@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.script.ScriptBeanManager; import com.yomahub.liteflow.script.ScriptExecuteWrap; import com.yomahub.liteflow.slot.DataBus; @@ -92,8 +93,11 @@ public class GroovyScriptExecutor implements ScriptExecutor { return compiledScript.eval(bindings); }catch (Exception e){ - log.error(e.getMessage(), e); - throw e; + if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof LiteFlowException){ + throw (LiteFlowException)e.getCause(); + }else{ + throw e; + } } } diff --git a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java index fff27366c..73f048f86 100644 --- a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java @@ -91,7 +91,6 @@ public class JavaScriptExecutor implements ScriptExecutor { return compiledScript.eval(bindings); }catch (Exception e){ - log.error(e.getMessage(), e); throw e; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java new file mode 100644 index 000000000..5375d09b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.script.groovy.throwException; + +import com.yomahub.liteflow.exception.LiteFlowException; + +public class TestException extends LiteFlowException { + public TestException(String message) { + super(message); + } + + public TestException(String code, String message) { + super(code, message); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java new file mode 100644 index 000000000..60ee83139 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.script.groovy.throwException; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import javax.annotation.Resource; + + +/** + * 测试springboot下的groovy脚本抛错 + * @author Bryan.Zhang + * @since 2.9.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/throwException/application.properties") +@SpringBootTest(classes = ThrowExceptionScriptGroovyELTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.script.groovy.throwException.cmp"}) +public class ThrowExceptionScriptGroovyELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1(){ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("T01", response.getCode()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java new file mode 100644 index 000000000..69465f37d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.groovy.throwException.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/application.properties new file mode 100644 index 000000000..c30228a45 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=throwException/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/flow.xml new file mode 100644 index 000000000..dd62494bf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/throwException/flow.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + THEN(a, s1); + + \ No newline at end of file