2424import net .sf .cglib .proxy .Enhancer ;
2525import net .sf .cglib .proxy .MethodInterceptor ;
2626import net .sf .cglib .proxy .MethodProxy ;
27+ import org .suren .autotest .web .framework .annotation .AutoExpect ;
2728import org .suren .autotest .web .framework .annotation .AutoModule ;
2829
2930import 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