|
|
@ -33,7 +33,7 @@ import java.util.*;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class AcmPropertySourceBuilder {
|
|
|
|
class AcmPropertySourceBuilder {
|
|
|
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(AcmPropertySourceBuilder.class);
|
|
|
|
private Logger log = LoggerFactory.getLogger(AcmPropertySourceBuilder.class);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象
|
|
|
|
* 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象
|
|
|
@ -59,20 +59,23 @@ class AcmPropertySourceBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dataId.endsWith(".properties")) {
|
|
|
|
if (dataId.endsWith(".properties")) {
|
|
|
|
Properties properties = new Properties();
|
|
|
|
Properties properties = new Properties();
|
|
|
|
logger.info(String.format("Loading acm data, dataId: '%s', group: '%s'",
|
|
|
|
log.info(String.format("Loading acm data, dataId: '%s', group: '%s'",
|
|
|
|
dataId, diamondGroup));
|
|
|
|
dataId, diamondGroup));
|
|
|
|
properties.load(new StringReader(data));
|
|
|
|
properties.load(new StringReader(data));
|
|
|
|
return properties;
|
|
|
|
return properties;
|
|
|
|
} else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) {
|
|
|
|
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
|
|
|
|
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
|
|
|
|
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
|
|
|
|
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
|
|
|
|
return yamlFactory.getObject();
|
|
|
|
return yamlFactory.getObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
if (e instanceof ConfigException) {
|
|
|
|
if (e instanceof ConfigException) {
|
|
|
|
logger.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e);
|
|
|
|
log.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
logger.error("DIAMOND-100500:" + dataId, e);
|
|
|
|
else {
|
|
|
|
|
|
|
|
log.error("DIAMOND-100500:" + dataId, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -81,13 +84,14 @@ class AcmPropertySourceBuilder {
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private Map<String, Object> toMap(Properties properties) {
|
|
|
|
private Map<String, Object> toMap(Properties properties) {
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
Enumeration<String> keys = (Enumeration<String>)properties.propertyNames();
|
|
|
|
Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
|
|
|
|
while (keys.hasMoreElements()) {
|
|
|
|
while (keys.hasMoreElements()) {
|
|
|
|
String key = keys.nextElement();
|
|
|
|
String key = keys.nextElement();
|
|
|
|
Object value = properties.getProperty(key);
|
|
|
|
Object value = properties.getProperty(key);
|
|
|
|
if (value != null) {
|
|
|
|
if (value != null) {
|
|
|
|
result.put(key, ((String)value).trim());
|
|
|
|
result.put(key, ((String) value).trim());
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
result.put(key, null);
|
|
|
|
result.put(key, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|