Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 1a8f42d

Browse files
committed
增加期待异常处理
1 parent 94ab574 commit 1a8f42d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/main/java/org/suren/autotest/web/framework/settings/AutoModuleProxy.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.sf.cglib.proxy.Enhancer;
2525
import net.sf.cglib.proxy.MethodInterceptor;
2626
import net.sf.cglib.proxy.MethodProxy;
27+
import org.suren.autotest.web.framework.annotation.AutoExpect;
2728
import org.suren.autotest.web.framework.annotation.AutoModule;
2829

2930
import java.lang.reflect.Method;
@@ -62,6 +63,7 @@ public Object intercept(Object obj, Method method, Object[] args,
6263
Object result = null;
6364
Class<?> superCls = obj.getClass().getSuperclass();
6465
AutoModule autoModule = superCls.getAnnotation(AutoModule.class);
66+
AutoExpect autoExpect = method.getAnnotation(AutoExpect.class);
6567

6668
NormalRecord normalRecord = new NormalRecord();
6769
normalRecord.setBeginTime(beginTime);
@@ -83,15 +85,49 @@ public Object intercept(Object obj, Method method, Object[] args,
8385
}
8486
catch(Exception e)
8587
{
88+
boolean acceptException = exceptionHandle(autoExpect, e);
89+
8690
normalRecord.setEndTime(System.currentTimeMillis());
8791
write(new ExceptionRecord(e, normalRecord));
8892

89-
throw e;
93+
if(acceptException)
94+
{
95+
e.printStackTrace();
96+
}
97+
else
98+
{
99+
throw e;
100+
}
90101
}
91102

92103
return result;
93104
}
94105

106+
/**
107+
* 根据注解配置,是否要对异常进行处理
108+
* @param autoExpect
109+
* @return
110+
*/
111+
private boolean exceptionHandle(AutoExpect autoExpect, Throwable e)
112+
{
113+
if(autoExpect != null)
114+
{
115+
Class<?>[] acceptArray = autoExpect.accept();
116+
if(acceptArray != null && acceptArray.length > 0)
117+
{
118+
for(Class<?> clz : acceptArray)
119+
{
120+
if(clz.equals(e))
121+
{
122+
return true;
123+
}
124+
}
125+
}
126+
}
127+
128+
return false;
129+
}
130+
95131
private boolean isNotExcludeMethod(Method method)
96132
{
97133
String name = method.getName();

0 commit comments

Comments
 (0)