Osgi配置ManagedService字典键不区分大小写
我遇到了一个问题。我有一个用于osgi配置的Osgi配置ManagedService字典键不区分大小写,osgi,aem,apache-felix,Osgi,Aem,Apache Felix,我遇到了一个问题。我有一个用于osgi配置的org.osgi.service.cm.ManagedServiceimpl客户端。配置是键值对的集合。 当将这些属性中的键作为java.util.Dictionary对象传递给ManagedService的更新方法(ManagedService.updated)时,它们似乎不区分大小写,即props.get(“HellO”)即使配置中的键是“HellO”也能工作 当我通过迭代该字典的条目将其转换为Hashmap时,映射中的键会像预期的那样区分大小写。
org.osgi.service.cm.ManagedService
impl客户端。配置是键值对的集合。
当将这些属性中的键作为java.util.Dictionary
对象传递给ManagedService
的更新方法(ManagedService.updated
)时,它们似乎不区分大小写,即props.get(“HellO”)
即使配置中的键是“HellO”也能工作
当我通过迭代该字典的条目将其转换为Hashmap
时,映射中的键会像预期的那样区分大小写。这是否意味着字典中的键不区分大小写
这在AEM 6.2实例上进行了测试
这是我的ManagedService
impl类
public class ConfigService implements ManagedService {
public void updated(final Dictionary props) throws ConfigurationException {
// props.get("HellO") returns value
if (props != null) {
String pid = (String) props.get(Constants.SERVICE_PID);
// convert to map
Map map = map(props);
// map.get("HellO") returns null
// map.get("Hello") returns value
}
}
private static Map map(Dictionary dict) {
Map map = new ConcurrentHashMap();
for (Enumeration keys = dict.keys(); keys.hasMoreElements();) {
Object key = keys.nextElement();
map.put(key, dict.get(key));
}
return map;
}
ManagedService
impl使用以下代码注册为服务
final Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, "pid.of.the.osgi.configuration" );
ServiceRegistration configSvc = context.registerService(ManagedService.class.getName(),
new ConfigService(), props);
这符合配置管理服务规范
属性的名称或键必须始终是字符串对象,而不是
查找时区分大小写,但必须保留原始大小写
ApacheFelix源代码供参考。
/**
*CaseInsensitiveDictionary
是一个
*java.util.Dictionary
符合规定的要求
*由需要属性的配置管理服务规范执行
*访问属性时保留大小写但忽略大小写的名称。
*/
键不区分大小写的原因是,在当时(2000年),X.500规范看起来很重要。我想剩下的就只有X.509证书、SNMP和LDAP了。区分大小写成为标准,我们被错误的决定所困扰。一个标准的缺点之一是它不可能向后兼容。