1818
1919package org .suren .autotest .web .framework .settings ;
2020
21- import net .sf .cglib .core .GeneratorStrategy ;
22- import net .sf .cglib .core .NamingPolicy ;
2321import net .sf .cglib .proxy .Enhancer ;
2422import net .sf .cglib .proxy .MethodInterceptor ;
2523import net .sf .cglib .proxy .MethodProxy ;
26- import org .springframework . cglib . core . SpringNamingPolicy ;
24+ import org .suren . autotest . web . framework . annotation . AutoExpect ;
2725import org .suren .autotest .web .framework .annotation .AutoModule ;
2826import org .suren .autotest .web .framework .report .RecordReportWriter ;
2927import org .suren .autotest .web .framework .report .record .ExceptionRecord ;
@@ -65,6 +63,7 @@ public Object intercept(Object obj, Method method, Object[] args,
6563 Object result = null ;
6664 Class <?> superCls = obj .getClass ().getSuperclass ();
6765 AutoModule autoModule = superCls .getAnnotation (AutoModule .class );
66+ AutoExpect autoExpect = method .getAnnotation (AutoExpect .class );
6867
6968 NormalRecord normalRecord = new NormalRecord ();
7069 normalRecord .setBeginTime (beginTime );
@@ -84,17 +83,51 @@ public Object intercept(Object obj, Method method, Object[] args,
8483 write (normalRecord );
8584 }
8685 }
87- catch (Exception e )
86+ catch (Exception | AssertionError e )
8887 {
88+ boolean acceptException = exceptionHandle (autoExpect , e );
89+
8990 normalRecord .setEndTime (System .currentTimeMillis ());
9091 write (new ExceptionRecord (e , normalRecord ));
9192
92- throw e ;
93+ if (acceptException )
94+ {
95+ e .printStackTrace ();
96+ }
97+ else
98+ {
99+ throw e ;
100+ }
93101 }
94102
95103 return result ;
96104 }
97105
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 .getClass ()))
121+ {
122+ return true ;
123+ }
124+ }
125+ }
126+ }
127+
128+ return false ;
129+ }
130+
98131 private boolean isNotExcludeMethod (Method method )
99132 {
100133 String name = method .getName ();
0 commit comments