File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
dongtai-api-gather/dongtai-api-gather-spring-api/src/main/java/io/dongtai/iast/api/gather/spring/extractor
main/java/io/dongtai/iast/common/utils
test/java/io/dongtai/iast/common/utils Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 22
33import io .dongtai .iast .api .gather .spring .convertor .RequestMappingHandlerMappingConvertor ;
44import io .dongtai .iast .api .openapi .domain .OpenApi ;
5+ import io .dongtai .iast .common .utils .ExceptionUtil ;
56import io .dongtai .log .DongTaiLog ;
67import org .springframework .web .context .WebApplicationContext ;
78import org .springframework .web .servlet .mvc .method .annotation .RequestMappingHandlerMapping ;
@@ -72,7 +73,11 @@ private List<RequestMappingHandlerMapping> findRequestMappingHandlerMapping(WebA
7273 }
7374 }
7475 } catch (Throwable e ) {
75- DongTaiLog .debug ("try use BeanFactoryUtils find RequestMappingHandlerMapping exception" , e );
76+ // 仅在出现预期外错误的时候才打印日志
77+ String s = ExceptionUtil .getPrintStackTraceString (e );
78+ if (!s .contains ("java.lang.NoSuchMethodException: org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors()" )) {
79+ DongTaiLog .debug ("try use BeanFactoryUtils throw RequestMappingHandlerMapping exception" , e );
80+ }
7681 }
7782
7883 // 没有工具类,就只从自己里面找
Original file line number Diff line number Diff line change 1+ package io .dongtai .iast .common .utils ;
2+
3+ import java .io .PrintWriter ;
4+ import java .io .StringWriter ;
5+
6+ /**
7+ * 处理异常相关的公共逻辑提取到这里
8+ *
9+ * @author CC11001100
10+ * @since 1.13.2
11+ */
12+ public class ExceptionUtil {
13+
14+ /**
15+ * 把printStackTrace会打印的内容以字符串的形式返回
16+ *
17+ * @param e
18+ * @return
19+ */
20+ public static String getPrintStackTraceString (Throwable e ) {
21+ StringWriter stringWriter = new StringWriter ();
22+ PrintWriter printWriter = new PrintWriter (stringWriter );
23+ e .printStackTrace (printWriter );
24+ return stringWriter .toString ();
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 1+ package io .dongtai .iast .common .utils ;
2+
3+ import org .junit .Assert ;
4+ import org .junit .Test ;
5+
6+ import static org .junit .Assert .*;
7+
8+ /**
9+ * @author CC11001100
10+ */
11+ public class ExceptionUtilTest {
12+
13+ @ Test
14+ public void getPrintStackTraceString () {
15+ Exception e = new Exception ();
16+ String printStackTraceString = ExceptionUtil .getPrintStackTraceString (e );
17+ Assert .assertNotNull (printStackTraceString );
18+ }
19+
20+ }
You can’t perform that action at this time.
0 commit comments