mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
bug #I7TYS3 当组件出现Exception的时候,afterProcess获取不到
This commit is contained in:
@@ -22,4 +22,8 @@ public interface ICmpAroundAspect {
|
||||
|
||||
void afterProcess(NodeComponent cmp);
|
||||
|
||||
void onSuccess(NodeComponent cmp);
|
||||
|
||||
void onError(NodeComponent cmp, Exception e);
|
||||
|
||||
}
|
||||
|
||||
@@ -110,17 +110,6 @@ public abstract class NodeComponent {
|
||||
cmpStep.setSuccess(false);
|
||||
cmpStep.setException(e);
|
||||
|
||||
if (!(e instanceof ChainEndException)){
|
||||
String chainId = this.getCurrChainId();
|
||||
// 这里事先取到exception set到slot里,为了方便finally取到exception
|
||||
if (slot.isSubChain(chainId)) {
|
||||
slot.setSubException(chainId, e);
|
||||
}
|
||||
else {
|
||||
slot.setException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 执行失败后回调方法
|
||||
// 这里要注意,失败方法本身抛出错误,只打出堆栈,往外抛出的还是主要的异常
|
||||
try {
|
||||
@@ -161,10 +150,16 @@ public abstract class NodeComponent {
|
||||
|
||||
public void onSuccess() throws Exception {
|
||||
// 如果需要在成功后回调某一个方法,请覆盖这个方法
|
||||
// 全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类
|
||||
// 非spring环境下,全局切面为空实现
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().onSuccess(this.self);
|
||||
}
|
||||
|
||||
public void onError(Exception e) throws Exception {
|
||||
// 如果需要在抛错后回调某一段逻辑,请覆盖这个方法
|
||||
// 全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类
|
||||
// 非spring环境下,全局切面为空实现
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().onError(this.self, e);
|
||||
}
|
||||
|
||||
public void afterProcess() {
|
||||
|
||||
@@ -15,4 +15,8 @@ public interface CmpAroundAspect extends SpiPriority {
|
||||
|
||||
void afterProcess(NodeComponent cmp);
|
||||
|
||||
void onSuccess(NodeComponent cmp);
|
||||
|
||||
void onError(NodeComponent cmp, Exception e);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,16 @@ public class LocalCmpAroundAspect implements CmpAroundAspect {
|
||||
// 无spring环境下为空实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
// 无spring环境下为空实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
// 无spring环境下为空实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 2;
|
||||
|
||||
@@ -37,6 +37,20 @@ public class SolonCmpAroundAspect implements CmpAroundAspect {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(cmpAroundAspect)) {
|
||||
cmpAroundAspect.onSuccess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
if (ObjectUtil.isNotNull(cmpAroundAspect)) {
|
||||
cmpAroundAspect.onError(cmp, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
|
||||
@@ -28,6 +28,20 @@ public class SpringCmpAroundAspect implements CmpAroundAspect {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) {
|
||||
ComponentScanner.cmpAroundAspect.onSuccess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) {
|
||||
ComponentScanner.cmpAroundAspect.onError(cmp, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
|
||||
@@ -72,6 +72,7 @@ public class GlobalAOPELDeclMultiSpringbootTest extends BaseTest {
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("f"));
|
||||
Assertions.assertEquals("test error", context.getData("f_error"));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
||||
@@ -20,4 +20,15 @@ public class CmpAspect implements ICmpAroundAspect {
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId()+"_error", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ public class GlobalAOPELDeclSpringbootTest extends BaseTest {
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("f"));
|
||||
Assertions.assertEquals("test error", context.getData("f_error"));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
||||
@@ -20,4 +20,15 @@ public class CmpAspect implements ICmpAroundAspect {
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId()+"_error", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,9 @@ public class GlobalAOPELSpringbootTest extends BaseTest {
|
||||
Assertions.assertEquals("before_after", context.getData("a"));
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("test error", context.getData("f"));
|
||||
Assertions.assertEquals("before_after", context.getData("f"));
|
||||
Assertions.assertEquals("test error", context.getData("f_error"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,18 @@ public class CmpAspect implements ICmpAroundAspect {
|
||||
@Override
|
||||
public void afterProcess(NodeComponent cmp) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
if (ObjectUtil.isNotNull(cmp.getSlot().getException())){
|
||||
context.setData(cmp.getNodeId(), cmp.getSlot().getException().getMessage());
|
||||
}else{
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId()+"_error", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public class GlobalAOPELSpringTest extends BaseTest {
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("f"));
|
||||
Assertions.assertEquals("test error", context.getData("f_error"));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
||||
@@ -20,4 +20,15 @@ public class CmpAspect implements ICmpAroundAspect {
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(NodeComponent cmp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(NodeComponent cmp, Exception e) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId()+"_error", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user