Quellcode durchsuchen

requestbodywrapper在抛出异常时,会显示是哪个请求出错了

lixing vor 3 Jahren
Ursprung
Commit
d595031fa6

+ 4 - 3
apm-common/src/main/java/com/persagy/apm/common/handler/PoemsRequestBodyWrapper.java

@@ -61,13 +61,14 @@ public class PoemsRequestBodyWrapper extends HttpServletRequestWrapper {
         String projectId = (String) paramMap.get("projectId");
 
         if (StringUtils.isBlank(groupCode)) {
-            throw new IllegalArgumentException("请求体中缺少groupCode");
+
+            throw new IllegalArgumentException(super.getRequestURI() + ": 请求体中缺少groupCode");
         }
         if (StringUtils.isBlank(userId)) {
-            throw new IllegalArgumentException("请求体中缺少userId");
+            throw new IllegalArgumentException(super.getRequestURI() + ": 请求体中缺少userId");
         }
         if (StringUtils.isBlank(pd)) {
-            throw new IllegalArgumentException("请求体中缺少pd");
+            throw new IllegalArgumentException(super.getRequestURI() + ": 请求体中缺少pd");
         }
         PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
     }

+ 11 - 7
apm-mybatis/src/main/java/com/persagy/apm/mybatis/handler/DynamicDataSourceHandler.java

@@ -5,7 +5,6 @@ import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator;
 import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
 import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
-import com.persagy.apm.common.context.AppContext;
 import com.persagy.apm.common.context.poems.PoemsContext;
 import com.persagy.apm.common.helper.SpringHelper;
 import com.persagy.apm.mybatis.service.IDbService;
@@ -21,13 +20,16 @@ import javax.sql.DataSource;
 
 /**
  * 动态数据源拦截器
+ *
  * @author Charlie Yu
  * @date 2021-03-29
  */
 @Component
 public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
 
-    /** 忽略的url - swagger的文档不校验 */
+    /**
+     * 忽略的url - swagger的文档不校验
+     */
     private static final String[] IGNORE_URL = {".html", ".js", ".css", "/swagger-resources"};
 
     @Autowired
@@ -55,20 +57,21 @@ public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
     public void resetDataSource() {
         // 是否启用多数据源
         boolean isDynamic = SpringHelper.getBoolean("spring.datasource.dynamic.enabled", false);
-        if(!isDynamic) {
+        if (!isDynamic) {
             return;
         }
         // 默认为应用名
         String dbNameDefault = SpringHelper.getString("spring.application.name");
         // 将应用名中的中划线替换为下划线,按照公司要求应用名统一用中划线,数据库名统一用下划线
-        String newDsName = dbNameDefault.replace("-", "_");
+        dbNameDefault = dbNameDefault.replace("-", "_");
+        String newDsName = dbNameDefault;
         if (StringUtils.isNotBlank(PoemsContext.getContext().getGroupCode())) {
             // 创建的数据源名称: 集团编码_应用名
-            newDsName = PoemsContext.getContext().getGroupCode() + "_" + dbNameDefault;
+            newDsName = PoemsContext.getContext().getGroupCode() + "_" + newDsName;
         }
 
         // 数据源中是否已存在
-        if(!dataSource.getCurrentDataSources().containsKey(newDsName)) {
+        if (!dataSource.getCurrentDataSources().containsKey(newDsName)) {
             // 设置新数据源
             DataSourceProperty property = copyProperty(dbNameDefault, newDsName);
             // 创建数据库实例
@@ -83,8 +86,9 @@ public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
 
     /**
      * 复制新的数据源
+     *
      * @param dbNameDefault 默认连接的实例名
-     * @param newDsName 新创建的实例名
+     * @param newDsName     新创建的实例名
      * @return
      */
     private DataSourceProperty copyProperty(String dbNameDefault, String newDsName) {