fix(运维监控模块): 修复获取功能应用列表报空指针异常的问题

调用Sentinel接口时,有概率返回结果中不包含success属性,所以在进行请求是否成功判断时,需要先判断是否存在该属性
This commit is contained in:
OTTO 2025-07-14 17:31:02 +08:00
parent 6d47364cca
commit fde9893840
1 changed files with 13 additions and 11 deletions

View File

@ -275,18 +275,20 @@ public class K8SDashboardServiceImpl extends CommonService implements IK8sDashbo
case FLOW_CONTROL:
// 处理应用流量控制功能相关逻辑
JSONObject sentinelAppList = remoteGatewayService.getSentinelAppList(SecurityContextHolder.getUserKey());
if (sentinelAppList != null && sentinelAppList.getBoolean("success") && sentinelAppList.getJSONArray("data") != null && !sentinelAppList.getJSONArray("data").isEmpty()) {
if (sentinelAppList != null && sentinelAppList.containsKey("success") && sentinelAppList.getBoolean("success")) {
JSONArray sentinelAppListArray = sentinelAppList.getJSONArray("data");
for (int i = 0; i < sentinelAppListArray.size(); i++) {
JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i);
if (k8sLabelValue.equals(sentinelApp.getString("app"))) {
applicationFunction = new ApplicationFunction();
applicationFunction.setKeyAndName(applicationFunctionType);
functionVariables = new JSONObject();
functionVariables.put("app", k8sLabelValue);
functionVariables.put("appType", sentinelApp.getLongValue("appType"));
applicationFunction.setVariables(functionVariables);
applicationFunctionsList.add(applicationFunction);
if (sentinelAppListArray != null && !sentinelAppList.getJSONArray("data").isEmpty()) {
for (int i = 0; i < sentinelAppListArray.size(); i++) {
JSONObject sentinelApp = sentinelAppListArray.getJSONObject(i);
if (k8sLabelValue.equals(sentinelApp.getString("app"))) {
applicationFunction = new ApplicationFunction();
applicationFunction.setKeyAndName(applicationFunctionType);
functionVariables = new JSONObject();
functionVariables.put("app", k8sLabelValue);
functionVariables.put("appType", sentinelApp.getLongValue("appType"));
applicationFunction.setVariables(functionVariables);
applicationFunctionsList.add(applicationFunction);
}
}
}
}