don't trust the response from nacos server. (#8230)

This commit is contained in:
赵延 2021-07-09 12:08:50 +08:00 committed by GitHub
parent 7af0d771de
commit 01874fc4e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -284,7 +284,9 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
HttpRestResult<String> result = httpAgent.httpGet(GET_CONFIG_KEYS_PATH, emptyMap(), paramsValues, encoding, 5 * 1000);
Stream<String> keysStream = toKeysStream(result.getData());
keysStream.forEach(keys::add);
if (keysStream != null) {
keysStream.forEach(keys::add);
}
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
@ -309,7 +311,13 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
private Stream<String> toKeysStream(String content) {
JSONObject jsonObject = JSON.parseObject(content);
if (jsonObject == null) {
return null;
}
JSONArray pageItems = jsonObject.getJSONArray("pageItems");
if (pageItems == null) {
return null;
}
return pageItems.stream()
.map(object -> (JSONObject) object)
.map(json -> json.getString("dataId"));